/// <summary> /// Helper function to create a texture. It checks the root path first, /// then tries the DXSDK media path (as specified in the system registry). /// </summary> public static Texture CreateTexture(Device device, string textureFilename) { return(GraphicsUtility.CreateTexture(device, textureFilename, Format.Unknown)); }
/// <summary> /// Fired when the containers mouse is moving /// </summary> private void OnContainerMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (GetAsyncKeyState(CameraControlKey)) { if (e.Button == System.Windows.Forms.MouseButtons.Left && parent.Camera.Rotatable) { if (internaldragging) { // adjustedY is normally just (e.Y) int adjustedY = saveMouseY - (e.Y - saveMouseY); // recompute nowQuat Vector3 vCur = ScreenToVector(e.X, adjustedY); #region new rotate - ignore this // // Normalize based on size of window and bounding sphere radius // float fDeltaX = (saveMouseX-e.X) * 0.005f; // * internalradiusTranslation / internalWidth; // float fDeltaY = (saveMouseY-e.Y) * 0.005f; // * internalradiusTranslation / internalHeight; // // // // calculate the directional view vector, and use it for our panning plane vectors // Vector3 direction = parent.Camera.TargetPoint - parent.Camera.EyePosition; // Vector3 panX = Vector3.Cross(direction, parent.Camera.UpVector); // Vector3 panY = parent.Camera.UpVector; // // // calculate the view (camera movement) vector // Vector3 vCur = parent.Camera.TargetPoint + // (panX * e.X) + (panY * e.Y); #endregion Quaternion qAxisToAxis = GraphicsUtility.D3DXQuaternionAxisToAxis(internalvectorDown, vCur); internalnowQuat = internaldownQuat; internalnowQuat = Quaternion.Multiply(internalnowQuat, qAxisToAxis); internalrotationDelta = Matrix.RotationQuaternion(qAxisToAxis); } else { internalrotationDelta = Matrix.Identity; } internalrotationMatrix = Matrix.RotationQuaternion(internalnowQuat); internaldragging = true; // set cursor if (cursorInvalid) { parent.Cursor = new Cursor(GetType(), "rotate.cur"); cursorInvalid = false; } } if ((e.Button == System.Windows.Forms.MouseButtons.Right) || (e.Button == System.Windows.Forms.MouseButtons.Middle)) { // Normalize based on size of window and bounding sphere radius float fDeltaX = (saveMouseX - e.X) * internalradiusTranslation / internalWidth; float fDeltaY = (saveMouseY - e.Y) * internalradiusTranslation / internalHeight; if (e.Button == System.Windows.Forms.MouseButtons.Middle && parent.Camera.Pannable) { // camera: panning // // calculate the directional view vector, and use it for our panning plane vectors Vector3 direction = parent.Camera.TargetPoint - parent.Camera.EyePosition; Vector3 panX = Vector3.Cross(direction, parent.Camera.UpVector); Vector3 panY = parent.Camera.UpVector; // calculate the view (camera movement) vector Vector3 view = parent.Camera.TargetPoint + (panX * fDeltaX) + (panY * fDeltaY * 5.0f); // determine the translation matrix internaltranslationDelta = Matrix.Translation(view.X, view.Y, view.Z); internaltranslationMatrix = Matrix.Multiply(internaltranslationMatrix, internaltranslationDelta); // set cursor if (cursorInvalid) { parent.Cursor = new Cursor(GetType(), "move.cur"); cursorInvalid = false; } } if (e.Button == System.Windows.Forms.MouseButtons.Right && parent.Camera.Zoomable) { // camera: zooming // // calculate the camera's directional vector Vector3 direction = parent.Camera.TargetPoint - parent.Camera.EyePosition; internaltranslationDelta = Matrix.Translation(direction.X * -fDeltaY, direction.Y * -fDeltaY, direction.Z * -fDeltaY); internaltranslationMatrix = Matrix.Multiply(internaltranslationMatrix, internaltranslationDelta); // zoom orthogonal camera parent.Camera.OrthoZoom -= fDeltaY * 4.0f; if (parent.Camera.OrthoZoom < 4.0f) { parent.Camera.OrthoZoom = 4.0f; } parent.Camera.SetProjectionParameters(parent.Camera.FOV, parent.Camera.AspectRatio, parent.Camera.NearClipPlane, parent.Camera.FarClipPlane); // set cursor if (cursorInvalid) { parent.Cursor = new Cursor(GetType(), "zoom.cur"); cursorInvalid = false; } } // Store mouse coordinate saveMouseX = e.X; saveMouseY = e.Y; } // end of zoom/pan // copy the world matrix transformations Matrix worldTemp = Matrix.Translation(parent.Camera.TargetPoint); worldTemp.Multiply(internalrotationMatrix); worldTemp.Multiply(internaltranslationMatrix); parent.Camera.WorldMatrix = worldTemp; // render this camera's viewport parent.Render(); } else { internaldragging = false; cursorInvalid = true; } }