From 4c823f57959a5d821a9f00d8e8c7f57c08ac2ded Mon Sep 17 00:00:00 2001 From: Martin Lehoux Date: Sun, 5 Apr 2020 23:34:05 -0700 Subject: feat - Camera VFOV --- camera.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'camera.go') 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{ -- cgit v1.3