// Rotate based on mouse input. public void Update(ref DXInput di) { float t = sw.ElapsedMilliseconds / 1000.0f; viewProj = Matrix.Multiply(view, proj); // Left mouse button if ((di.currMouseState.Buttons[0] == true) && (di.prevMouseState.Buttons[0] == true)) { xRot += 0.00025f; } // Middle mouse button else if ((di.currMouseState.Buttons[2] == true) && (di.prevMouseState.Buttons[2] == true)) { zRot += 0.00025f; } // Right mouse button else if ((di.currMouseState.Buttons[1] == true) && (di.prevMouseState.Buttons[1] == true)) { yRot += 0.00025f; } var rot = Matrix.RotationX(xRot) * Matrix.RotationY(yRot) * Matrix.RotationZ(zRot); var wvp = rot * viewProj; wvp.Transpose(); devCon.UpdateSubresource(ref wvp, cBuffer); }
// Initialise components public void InitialiseComponents() { // --------------------- // // Uncomment for testing // // --------------------- // // Triangle test //tri = new Triangle(ref dev, ref devCon); //tri.Initialise(); // Cube test //cube = new Cube(ref dev, ref devCon); //cube.setDimensions(form.ClientSize.Width, form.ClientSize.Height); //cube.Initialise(); // Cube import ci = new CubeImport(ref dev, ref devCon); ci.setDimensions(form.ClientSize.Width, form.ClientSize.Height); ci.Initialise(); // ---- // // Live // // ---- // di = new DXInput(); di.setDimensions(form.ClientSize.Width, form.ClientSize.Height); arc = new ArcCamera(); arc.setDXInput(ref di); cam = new FPSCamera(); cam.setDXInput(ref di); cam.setProjectionMatrix(form.ClientSize.Width, form.ClientSize.Height); sky = new Skydome(ref dev, ref devCon); sky.setDimensions(form.ClientSize.Width, form.ClientSize.Height); sky.Initialise(); terrain = new Terrain(ref dev, ref devCon); terrain.setDimensions(form.ClientSize.Width, form.ClientSize.Height); terrain.Initialise(); }
// Rotate based on FPSCamera. public void Update(ref DXInput di, ref FPSCamera cam) { viewProj = Matrix.Multiply(cam.GetViewMatrix(), proj); // Move up or down using Q and Z. if ((di.currKeyboardState.IsPressed(SDI.Key.Q)) && (di.prevKeyboardState.IsPressed(SDI.Key.Q))) { //cam.ApplyZoom(0.005f); cam.MoveVertically(0.01f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.Z)) && (di.prevKeyboardState.IsPressed(SDI.Key.Z))) { //cam.ApplyZoom(-0.005f); cam.MoveVertically(-0.01f); } // Strafe left or right using A and D. if ((di.currKeyboardState.IsPressed(SDI.Key.A)) && (di.prevKeyboardState.IsPressed(SDI.Key.A))) { cam.Strafe(-0.01f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.D)) && (di.prevKeyboardState.IsPressed(SDI.Key.D))) { cam.Strafe(0.01f); } // Move forward or backward using W and S. if ((di.currKeyboardState.IsPressed(SDI.Key.W)) && (di.prevKeyboardState.IsPressed(SDI.Key.W))) { cam.MoveForward(0.01f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.S)) && (di.prevKeyboardState.IsPressed(SDI.Key.S))) { cam.MoveForward(-0.01f); } // Pitch the camera using I and K. if ((di.currKeyboardState.IsPressed(SDI.Key.I)) && (di.prevKeyboardState.IsPressed(SDI.Key.I))) { cam.Pitch(-0.0001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.K)) && (di.prevKeyboardState.IsPressed(SDI.Key.K))) { cam.Pitch(0.0001f); } // Yaw the camera using J and L. if ((di.currKeyboardState.IsPressed(SDI.Key.J)) && (di.prevKeyboardState.IsPressed(SDI.Key.J))) { cam.Yaw(-0.0001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.L)) && (di.prevKeyboardState.IsPressed(SDI.Key.L))) { cam.Yaw(0.0001f); } //cam.ApplyRotation(yawDelta, pitchDelta); //var rot = Matrix.RotationX(xRot) * Matrix.RotationY(yRot) * Matrix.RotationZ(zRot); var wvp = viewProj; // * rot; // var wvp = view; wvp.Transpose(); devCon.UpdateSubresource(ref wvp, cBuffer); }
public void setDXInput(ref DXInput di) { dInput = di; }
// Rotate based on FPSCamera. public void Update(ref DXInput di, ref FPSCamera cam) { float t = sw.ElapsedMilliseconds / 1000.0f; viewProj = Matrix.Multiply(cam.GetViewMatrix(), proj); // Left mouse button if ((di.currMouseState.Buttons[0] == true) && (di.prevMouseState.Buttons[0] == true)) { xRot += 0.0025f; } // Middle mouse button else if ((di.currMouseState.Buttons[2] == true) && (di.prevMouseState.Buttons[2] == true)) { zRot += 0.0025f; } // Right mouse button else if ((di.currMouseState.Buttons[1] == true) && (di.prevMouseState.Buttons[1] == true)) { yRot += 0.0025f; } float yawDelta = 0.0f; float pitchDelta = 0.0f; // Move up or down using Q and Z. if ((di.currKeyboardState.IsPressed(SDI.Key.Q)) && (di.prevKeyboardState.IsPressed(SDI.Key.Q))) { //cam.ApplyZoom(0.005f); cam.MoveVertically(0.001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.Z)) && (di.prevKeyboardState.IsPressed(SDI.Key.Z))) { //cam.ApplyZoom(-0.005f); cam.MoveVertically(-0.001f); } // Strafe left or right using A and D. if ((di.currKeyboardState.IsPressed(SDI.Key.A)) && (di.prevKeyboardState.IsPressed(SDI.Key.A))) { yawDelta = -0.001f; cam.Strafe(-0.001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.D)) && (di.prevKeyboardState.IsPressed(SDI.Key.D))) { yawDelta = 0.001f; cam.Strafe(0.001f); } // Move forward or backward using W and S. if ((di.currKeyboardState.IsPressed(SDI.Key.W)) && (di.prevKeyboardState.IsPressed(SDI.Key.W))) { pitchDelta = -0.001f; cam.MoveForward(0.001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.S)) && (di.prevKeyboardState.IsPressed(SDI.Key.S))) { pitchDelta = 0.001f; cam.MoveForward(-0.001f); } // Pitch the camera using I and K. if ((di.currKeyboardState.IsPressed(SDI.Key.I)) && (di.prevKeyboardState.IsPressed(SDI.Key.I))) { cam.Pitch(-0.001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.K)) && (di.prevKeyboardState.IsPressed(SDI.Key.K))) { cam.Pitch(0.001f); } // Yaw the camera using J and L. if ((di.currKeyboardState.IsPressed(SDI.Key.J)) && (di.prevKeyboardState.IsPressed(SDI.Key.J))) { cam.Yaw(-0.001f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.L)) && (di.prevKeyboardState.IsPressed(SDI.Key.L))) { cam.Yaw(0.001f); } //cam.ApplyRotation(yawDelta, pitchDelta); var trn = Matrix.Translation(cBufferData.lightDir.X, cBufferData.lightDir.Y, cBufferData.lightDir.Z); var rot = Matrix.RotationX(xRot) * Matrix.RotationY(yRot) * Matrix.RotationZ(zRot); cBufferData.world = rot * trn; var wvp = rot * trn * viewProj; wvp.Transpose(); cBufferData.wvp = wvp; devCon.UpdateSubresource(ref cBufferData, cBuffer); }
// Rotate based on ArcCamera. public void Update(ref DXInput di, ref ArcCamera arc) { float t = sw.ElapsedMilliseconds / 1000.0f; viewProj = Matrix.Multiply(arc.GetViewMatrix(), proj); // Left mouse button if ((di.currMouseState.Buttons[0] == true) && (di.prevMouseState.Buttons[0] == true)) { xRot += 0.0025f; } // Middle mouse button else if ((di.currMouseState.Buttons[2] == true) && (di.prevMouseState.Buttons[2] == true)) { zRot += 0.0025f; } // Right mouse button else if ((di.currMouseState.Buttons[1] == true) && (di.prevMouseState.Buttons[1] == true)) { yRot += 0.0025f; } float yawDelta = 0.0f; float pitchDelta = 0.0f; // Apply zoom distance using Q and Z. if ((di.currKeyboardState.IsPressed(SDI.Key.Q)) && (di.prevKeyboardState.IsPressed(SDI.Key.Q))) { arc.ApplyZoom(0.005f); } else if ((di.currKeyboardState.IsPressed(SDI.Key.Z)) && (di.prevKeyboardState.IsPressed(SDI.Key.Z))) { arc.ApplyZoom(-0.005f); } // Apply yaw using A and D. if ((di.currKeyboardState.IsPressed(SDI.Key.A)) && (di.prevKeyboardState.IsPressed(SDI.Key.A))) { yawDelta = -0.001f; } else if ((di.currKeyboardState.IsPressed(SDI.Key.D)) && (di.prevKeyboardState.IsPressed(SDI.Key.D))) { yawDelta = 0.001f; } // Apply pitch using W and S. if ((di.currKeyboardState.IsPressed(SDI.Key.W)) && (di.prevKeyboardState.IsPressed(SDI.Key.W))) { pitchDelta = -0.001f; } else if ((di.currKeyboardState.IsPressed(SDI.Key.S)) && (di.prevKeyboardState.IsPressed(SDI.Key.S))) { pitchDelta = 0.001f; } arc.ApplyRotation(yawDelta, pitchDelta); var rot = Matrix.RotationX(xRot) * Matrix.RotationY(yRot) * Matrix.RotationZ(zRot); var wvp = rot * viewProj; wvp.Transpose(); devCon.UpdateSubresource(ref wvp, cBuffer); }
// Rotate based on FPSCamera. public void Update(ref DXInput di, ref FPSCamera cam, ref RenderForm form) { float t = sw.ElapsedMilliseconds / 1000.0f; viewProj = Matrix.Multiply(cam.GetViewMatrix(), proj); // Left mouse button if ((di.currMouseState.Buttons[0] == true) && (di.prevMouseState.Buttons[0] == true)) { xRot += 0.0025f; } // Middle mouse button else if ((di.currMouseState.Buttons[2] == true) && (di.prevMouseState.Buttons[2] == true)) { zRot += 0.0025f; } // Right mouse button else if ((di.currMouseState.Buttons[1] == true) && (di.prevMouseState.Buttons[1] == true)) { yRot += 0.0025f; } float yawDelta = 0.0f; float pitchDelta = 0.0f; float moveFactorV = 0.001f; float moveFactorH = 0.001f; float pitchYawFactor = 0.00005f; // Move up or down using Q and Z. if ((di.currKeyboardState.IsPressed(SDI.Key.Q)) && (di.prevKeyboardState.IsPressed(SDI.Key.Q))) { //cam.ApplyZoom(0.005f); cam.MoveVertically(moveFactorV); } else if ((di.currKeyboardState.IsPressed(SDI.Key.Z)) && (di.prevKeyboardState.IsPressed(SDI.Key.Z))) { //cam.ApplyZoom(-0.005f); cam.MoveVertically(-moveFactorV); } // Strafe left or right using A and D. if ((di.currKeyboardState.IsPressed(SDI.Key.A)) && (di.prevKeyboardState.IsPressed(SDI.Key.A))) { yawDelta = -0.001f; cam.Strafe(-moveFactorH); } else if ((di.currKeyboardState.IsPressed(SDI.Key.D)) && (di.prevKeyboardState.IsPressed(SDI.Key.D))) { yawDelta = 0.001f; cam.Strafe(moveFactorH); } // Move forward or backward using W and S. if ((di.currKeyboardState.IsPressed(SDI.Key.W)) && (di.prevKeyboardState.IsPressed(SDI.Key.W))) { pitchDelta = -0.001f; cam.MoveForward(moveFactorH); } else if ((di.currKeyboardState.IsPressed(SDI.Key.S)) && (di.prevKeyboardState.IsPressed(SDI.Key.S))) { pitchDelta = 0.001f; cam.MoveForward(-moveFactorH); } // Pitch the camera using I and K. if ((di.currKeyboardState.IsPressed(SDI.Key.I)) && (di.prevKeyboardState.IsPressed(SDI.Key.I))) { cam.Pitch(-pitchYawFactor); } else if ((di.currKeyboardState.IsPressed(SDI.Key.K)) && (di.prevKeyboardState.IsPressed(SDI.Key.K))) { cam.Pitch(pitchYawFactor); } // Yaw the camera using J and L. if ((di.currKeyboardState.IsPressed(SDI.Key.J)) && (di.prevKeyboardState.IsPressed(SDI.Key.J))) { cam.Yaw(-pitchYawFactor); } else if ((di.currKeyboardState.IsPressed(SDI.Key.L)) && (di.prevKeyboardState.IsPressed(SDI.Key.L))) { cam.Yaw(pitchYawFactor); } //cam.ApplyRotation(yawDelta, pitchDelta); // Limit camera position. float camX = cam.getCamX(); float camY = cam.getCamY(); float camZ = cam.getCamZ(); int updated = 0; int te_size = te.getTerrainSize(); for (int i = 0; i < te_size; i++) { for (int j = 0; j < te_size; j++) { if (((int)vt[te_size * i + j].Position.X == (int)camX) && ((int)vt[te_size * i + j].Position.Z == (int)camZ)) { if (camY < vt[te_size * i + j].Position.Y) { cam.setCamY(vt[te_size * i + j].Position.Y + 0.5f); } updated = 1; break; } } if (updated == 1) { break; } } viewProj = Matrix.Multiply(cam.GetViewMatrix(), proj); var rot = Matrix.RotationX(xRot) * Matrix.RotationY(yRot) * Matrix.RotationZ(zRot); cBufferData.world = rot; var wvp = viewProj;// * rot; wvp.Transpose(); cBufferData.wvp = wvp; cBufferData.view = cam.GetViewMatrix(); cBufferData.modelViewIT = Matrix.Transpose(Matrix.Invert(cBufferData.world)); devCon.UpdateSubresource(ref cBufferData, cBuffer); // Get mouse coordinates float xc = di.mouseX; float yc = di.mouseY; float zc = di.mouseZ; // Get the system cursor position. System.Drawing.Point p = new System.Drawing.Point(Cursor.Position.X, Cursor.Position.Y); //xc = p.X; //yc = p.Y; xc = form.PointToClient(p).X; yc = form.PointToClient(p).Y; //xc = (2.0f * xc / formWidth) - 1.0f; //yc = ((2.0f * yc / formHeight) - 1.0f) * -1.0f; //int minCursorX = form.DesktopLocation.X; //int minCursorY = form.DesktopLocation.Y; //int maxCursorX = form.DesktopBounds.Right; //int maxCursorY = form.DesktopBounds.Bottom; /*if(xc < minCursorX) { xc = minCursorX; } * if(yc < minCursorY) { yc = minCursorY; } * if(xc > maxCursorX) { xc = maxCursorX; } * if(yc > maxCursorY) { yc = maxCursorY; }*/ //System.Console.WriteLine("{0} {1} {2}", xc, yc, zc); //System.Console.WriteLine("{0} {1} {2} {3}", minCursorX, minCursorY, maxCursorX, maxCursorY); //System.Console.WriteLine("{0} {1}", xc, yc); bool rp = rayPick(new Vector2(xc, yc), bb); if (rp == true) { cBufferData.lightCol2 = new Vector4(1.3f, 1.4f, 1.45f, 1.0f); } else { cBufferData.lightCol2 = new Vector4(0.13f, 0.14f, 0.145f, 1.0f); } devCon.UpdateSubresource(ref cBufferData, cBuffer); }