public void MultMatrix(ref Matrix4 modelMatrix) { for (Int32 i = 0; i < Vertices.Length / 3; i++) { Vector4 vertex = new Vector4(Vertices[i, 0], Vertices[i, 1], Vertices[i, 2], 1.0f); vertex = VectorMathOperations.multMatrix(modelMatrix, vertex); this.Vertices[i, 0] = vertex.X; this.Vertices[i, 1] = vertex.Y; this.Vertices[i, 2] = vertex.Z; if (_normals != null) { Vector4 normal = new Vector4(Normals[i, 0], Normals[i, 1], Normals[i, 2], 0.0f); normal = VectorMathOperations.multMatrix(modelMatrix, normal); this.Normals[i, 0] = normal.X; this.Normals[i, 1] = normal.Y; this.Normals[i, 2] = normal.Z; } } }
private void UpdateRotationMatrix(Int32 deltaX, Int32 deltaY) { m_eyeSpaceForwardVector = VectorMathOperations.multMatrix(m_rotationMatrix, m_localSpaceForwardVector).Normalized(); m_eyeSpaceRightVector = Vector3.Cross(m_eyeSpaceForwardVector, m_localSpaceUpVector).Normalized(); float anglePitch = deltaY * rotateSensetivity; float angleYaw = deltaX * rotateSensetivity; Matrix3 rotatePitch = Matrix3.CreateFromAxisAngle(m_eyeSpaceRightVector, MathHelper.DegreesToRadians(anglePitch)); Matrix3 rotateYaw = Matrix3.CreateRotationY(MathHelper.DegreesToRadians(angleYaw)); Matrix3 tempRotationMatrix = Matrix3.Identity; tempRotationMatrix *= rotateYaw; tempRotationMatrix *= rotatePitch; m_rotationMatrix = tempRotationMatrix * m_rotationMatrix; bTransformationDirty = true; //Console.Clear(); //pitch = (float)Math.Atan2(-rotationMatrix[2, 0], Math.Sqrt(rotationMatrix[2, 1] * rotationMatrix[2, 1] + rotationMatrix[2, 2] * rotationMatrix[2, 2])); //Console.WriteLine(pitch); }