private void UpdateCameraMatrix() { // right-handed coordinates #if false // front view var eye = new Vector3D(0.0, 0.0, -CameraDistance); var at = new Vector3D(0.0, 0.0, 0.0); var up = new Vector3D(0.0, 1.0, 0.0); var lookAt = WWMatrixUtil.CalculateLookAt(eye, at, up); #else // virtual trackball var cameraRot = mVirtualTrackball.RotationMatrix(); var cameraTranslate = new Matrix3D(); cameraTranslate.Translate(new Vector3D(0.0, 0.0, -mCameraDistanceCurrent)); var cameraMat = cameraTranslate * cameraRot; var lookAt = cameraMat; lookAt.Invert(); #endif var viewProjectionMatrix = WWMatrixUtil.CreatePerspectiveProjectionMatrix(mCameraNear, mCameraDistanceCurrent * 2.0, CameraFovHDegree, 1.0); mWorldProjectionMatrix = lookAt * viewProjectionMatrix; }
private void RedrawRoom() { DrawModel(mRoom.RoomModel, Matrix3D.Identity, new SolidColorBrush(Colors.White)); Matrix3D listenerMatrix = new Matrix3D(); listenerMatrix.Translate((Vector3D)mRoom.ListenerPos); DrawModel(mRoom.ListenerModel, listenerMatrix, new SolidColorBrush(Colors.Gray)); for (int i = 0; i < WWRoom.NUM_OF_SPEAKERS; ++i) { var pos = mRoom.SpeakerPos(i); var dir = mRoom.SpeakerDir(i); Vector3D posV = new Vector3D(pos.X, pos.Y, pos.Z); Vector3D at = new Vector3D(pos.X + dir.X, pos.Y + dir.Y, pos.Z + dir.Z); Vector3D up = new Vector3D(0.0, 1.0, 0.0); Matrix3D speakerMatrixInv = WWMatrixUtil.CalculateLookAt(posV, at, up); var speakerMatrix = speakerMatrixInv; speakerMatrix.Invert(); DrawModel(mRoom.SpeakerModel, speakerMatrix, new SolidColorBrush(Colors.Gray)); } }