private Vector3D ComputeForward() { Matrix RX = Matrix.CreateRotationMatrix(Axis.X, alpha); Matrix RY = Matrix.CreateRotationMatrix(Axis.Y, beta); Matrix R = RX * RY; Vector4D dir = new Vector4D(new Vector3D(0, 0, 1)); return (R * dir).Vect3D; }
public Ray ShootRay(Viewport viewport, int x, int y) { Vector3D origin = new Vector3D( viewport.Scaling * ((float)x + 0.5f - (float)viewport.Width / 2f), viewport.Scaling * ((float)y + 0.5f - (float)viewport.Height / 2f), 0f); Vector4D P = new Vector4D(origin); Matrix RX = Matrix.CreateRotationMatrix(Axis.X, alpha); Matrix RY = Matrix.CreateRotationMatrix(Axis.Y, beta); Matrix R = RX * RY; Matrix T = Matrix.CreateTranslationMatrix(position); Vector4D realOrigin = (T * R) * P; return new Ray(realOrigin.Vect3D, forward); }