public Game() { Scene = new Scene(); Viewport = new Viewport { Scene = Scene, Width = 800, Height = 600 }; Camera = new Camera() { Target = Vector.Forward, Position = Vector.Zero }; Constructed(); }
public void Setup() { var viewport = new Viewport { Width = 640, Height = 480 }; _camera = new Camera() { Target = Vector.Forward, Position = Vector.Zero }; viewport.View = _camera; _camera.Update(viewport); _frustum = new Frustum(); _frustum.SetCameraDefinition(viewport, _camera); }
public void SetCameraDefinition(Viewport viewport, Camera camera) { Vector dir, nc, fc, X, Y, Z; SetCameraInternals(camera.FieldOfView, viewport.AspectRatio, camera.Near, camera.Far); Z = camera.Target-camera.Position; Z.Normalize(); X = camera.Up * Z; X.Normalize(); Y = Z * X; nc = camera.Position - Z * _near; fc = camera.Position - Z * _far; ntl = nc + Y * _nh - X * _nw; ntr = nc + Y * _nh + X * _nw; nbl = nc - Y * _nh - X * _nw; nbr = nc - Y * _nh + X * _nw; ftl = fc + Y * _fh - X * _fw; ftr = fc + Y * _fh + X * _fw; fbl = fc - Y * _fh - X * _fw; fbr = fc - Y * _fh + X * _fw; _planes[(int)FrustumLocation.Top].SetVectors(ntr, ntl, ftl); _planes[(int)FrustumLocation.Bottom].SetVectors(nbl, nbr, fbr); _planes[(int)FrustumLocation.Left].SetVectors(ntl, nbl, fbl); _planes[(int)FrustumLocation.Right].SetVectors(nbr, ntr, fbr); _planes[(int)FrustumLocation.Near].SetVectors(ntl, ntr, fbr); _planes[(int)FrustumLocation.Far].SetVectors(ftr, ftl, fbl); }