aboutsummaryrefslogtreecommitdiff
path: root/camera.go
diff options
context:
space:
mode:
authorMartin Lehoux <martin@lehoux.net>2020-04-05 23:34:05 -0700
committerMartin Lehoux <martin@lehoux.net>2020-04-05 23:34:05 -0700
commit4c823f57959a5d821a9f00d8e8c7f57c08ac2ded (patch)
tree483ba7af5cbcd051cf9835e7cb4821e6d8cbd2f4 /camera.go
parent09126c915e0f410fddfee14239589fad250ea712 (diff)
feat - Camera VFOV
Diffstat (limited to 'camera.go')
-rw-r--r--camera.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/camera.go b/camera.go
index 6cc3391..2992b02 100644
--- a/camera.go
+++ b/camera.go
@@ -1,11 +1,25 @@
package main
+import "math"
+
// Camera handle view position and screen
type Camera struct {
lowerLeftCorner Vec3D
origin, horizontal, vertical Vec3D
}
+// NewCamera creates a new camera
+func NewCamera(vfov float64, aspect float64) Camera {
+ origin := Vec3D{0.0, 0.0, 0.0}
+ theta := DegreesToRadians(vfov)
+ halfHeight := math.Tan(theta / 2.0)
+ halfWidth := aspect * halfHeight
+ lowerLeftCorner := Vec3D{-halfWidth, -halfHeight, -1.0}
+ horizontal := Vec3D{2.0 * halfWidth, 0.0, 0.0}
+ vertical := Vec3D{0.0, 2.0 * halfHeight, 0.0}
+ return Camera{lowerLeftCorner, origin, horizontal, vertical}
+}
+
// GetRay computes Ray given screen params
func (camera Camera) GetRay(u float64, v float64) Ray {
return Ray{