/// <summary> /// This method calculates modification matrix, that allows to convert world /// coordinates to camera. /// </summary> public Matrix GetCameraMatrix() { //Stage 1: Creating inverted matrix of translation Matrix matrixInverted = ModificationMatrix.NewMoveMatrix(-Position.X, -Position.Y, -Position.Z); //Stage 2: Calculating vectors u, v, n Vector3D N = new Vector3D(Target.X - Position.X, Target.Y - Position.Y, Target.Z - Position.Z); Vector3D V = new Vector3D(0, 1, 0); Vector3D U = V ^ N; V = U ^ N; //Normalizing all vectors U.Normalize(); V.Normalize(); N.Normalize(); cameraMatrix = ModificationMatrix.NewUVNProjectionMatrix( U.X, U.Y, U.Z, V.X, V.Y, V.Z, N.X, N.Y, N.Z); cameraMatrix = cameraMatrix.Multiply(matrixInverted); return(cameraMatrix); }
public Matrix GetModificationMatrix() { Matrix matrix = ModificationMatrix.NewIdentityMatrix(4); matrix = matrix.Multiply(ModificationMatrix.NewScaleMatrix(ScaleX, ScaleY, ScaleZ)); matrix = matrix.Multiply(ModificationMatrix.NewRotateXMatrix(MathHelpers.FromDegreesToRadians(AngleX))); matrix = matrix.Multiply(ModificationMatrix.NewRotateYMatrix(MathHelpers.FromDegreesToRadians(AngleY))); matrix = matrix.Multiply(ModificationMatrix.NewRotateZMatrix(MathHelpers.FromDegreesToRadians(AngleZ))); return(matrix); }
/// <summary> /// Rotates camera up & down with @angle /// </summary> public void FlyCameraUpDown(double angle) { Matrix rotateMatrix = ModificationMatrix.NewMoveMatrix(-Target.X, -Target.Y, -Target.Z); rotateMatrix = rotateMatrix.Multiply(Position.GetProjectiveCoordinates()); Position.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]); angle += MathHelpers.FromRadiansToDegrees(Position.Theta); angle = Math.Min(Math.Max(angle, MIN_THETA), MAX_THETA); Position.SetTheta(MathHelpers.FromDegreesToRadians(angle)); AngleTheta = 180 - (int)angle; rotateMatrix = ModificationMatrix.NewMoveMatrix(Target.X, Target.Y, Target.Z); rotateMatrix = rotateMatrix.Multiply(Position.GetProjectiveCoordinates()); Position.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]); }
// do you really need any comments here? public void HeadCameraLeftRight(double angle) { Matrix rotateMatrix = ModificationMatrix.NewMoveMatrix(-Position.X, -Position.Y, -Position.Z); rotateMatrix = rotateMatrix.Multiply(Target.GetProjectiveCoordinates()); Target.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]); angle += MathHelpers.FromRadiansToDegrees(Target.Phi); angle %= 360; angle = angle < 0 ? 360 + angle : angle; Target.SetPhi(MathHelpers.FromDegreesToRadians(angle)); AnglePhi = (int)angle; rotateMatrix = ModificationMatrix.NewMoveMatrix(Position.X, Position.Y, Position.Z); rotateMatrix = rotateMatrix.Multiply(Target.GetProjectiveCoordinates()); Target.Set(rotateMatrix[0, 0], rotateMatrix[1, 0], rotateMatrix[2, 0]); }
public void DrawObjects() { FastBitmap bitmap = new FastBitmap(new Bitmap(Camera.Width, Camera.Height)); Matrix cameraMatrix = Camera.GetCameraMatrix(); // z-buffer (z-matrix). For each camera viewport pixel. // first, fill it with double.MaxValue with future z-buffer algoritm in mind. double[,] buffer = new double[Camera.Width, Camera.Height]; for (int i = 0; i < Camera.Width; ++i) { for (int j = 0; j < Camera.Height; ++j) { buffer[i, j] = double.MaxValue; } } if (IsPanning) { // defining light Matrix lightMatrix = ModificationMatrix.NewIdentityMatrix(4); var light = Light; { Point3D lightPosition = new Point3D(light); } } if (SelectedForPanObject != null) { DrawObject(SelectedForPanObject, bitmap, buffer, cameraMatrix); } else { for (int i = 0; i < Objects.Count; ++i) { SceneObject radioObject = Objects[i]; if (IsVisibleForCamera(radioObject.BasePoint, radioObject.MaxLength, cameraMatrix)) { DrawObject(radioObject, bitmap, buffer, cameraMatrix); } } } canvas.Image = bitmap.GetBitmap(); }