public void Draw(BasicEffect Beffect, GraphicsDevice device, Camera camera) { device.RasterizerState = RasterizerState.CullNone; transforms = new Matrix[cubeModel.Value.Bones.Count]; cubeModel.Value.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in cubeModel.Value.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.View = camera.ViewMatrix; effect.Projection = camera.ProjectionMatrix; effect.World = Matrix.Identity; } mesh.Draw(); } }
// Helper method for Draw() -> Draws all ents inside each camera view private void ViewportDraw(Camera camera) { GraphicsDevice.Viewport = camera.Viewport; foreach (Entity ent in BigOlEntityList) { ent.Draw(GraphicsDevice, Matrix.Identity, camera.ViewMatrix, camera.ProjectionMatrix); } }
// Helper method for init() -> Creates cameras and viewports, adds to list. private void SetupCameras() { defaultViewport = GraphicsDevice.Viewport; defaultViewport.Width = 800; defaultViewport.Height = 600; Viewport viewPortPerspective = new Viewport(defaultViewport.Width / 2, defaultViewport.Height / 2, defaultViewport.Width / 2, defaultViewport.Height / 2); Viewport viewPortTop = new Viewport(defaultViewport.Width / 2, 0, defaultViewport.Width / 2, defaultViewport.Height / 2); Viewport viewPortFront = new Viewport(0, 0, defaultViewport.Width / 2, defaultViewport.Height / 2); Viewport viewPortSide = new Viewport(0, defaultViewport.Height / 2, defaultViewport.Width / 2, defaultViewport.Height / 2); Camera camera = new Camera(); Camera cameraTop = new Camera(); Camera cameraSide = new Camera(); Camera cameraFront = new Camera(); camera.Viewport = viewPortPerspective; cameraTop.Viewport = viewPortTop; cameraFront.Viewport = viewPortFront; cameraSide.Viewport = viewPortSide; camera.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, viewPortPerspective.AspectRatio, 1.0f, 1000f); cameraTop.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, viewPortSide.AspectRatio, 1.0f, 1000f); cameraSide.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, viewPortTop.AspectRatio, 1.0f, 1000f); cameraFront.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, viewPortFront.AspectRatio, 1.0f, 1000f); camera.Position = new Vector3(10, 10, 10); cameraTop.Position = new Vector3(0, 15, 0); cameraSide.Position = new Vector3(15, 0, 0); cameraFront.Position = new Vector3(0, 0, 15); cameraTop.LookAt = Vector3.Zero; cameraSide.LookAt = Vector3.Zero; cameraFront.LookAt = Vector3.Zero; camera.LookAt = Vector3.Zero; cameraTop.UpVector = new Vector3(1, 0, 0); camera.UpVector = new Vector3(0, 1, 0); cameraFront.UpVector = new Vector3(0, 1, 0); cameraSide.UpVector = new Vector3(0, 1, 0); Cameras.Add(camera); Cameras.Add(cameraTop); Cameras.Add(cameraSide); Cameras.Add(cameraFront); }
private void SetupCameras() { Default = GraphicsDevice.Viewport; Default.Width = 800; Default.Height = 600; Perspective = new Viewport(Default.Width / 2, Default.Height /2, Default.Width /2, Default.Height /2); Top = new Viewport(Default.Width / 2, 0, Default.Width / 2, Default.Height / 2); Front = new Viewport(0, 0, Default.Width / 2, Default.Height / 2); Side = new Viewport(0, Default.Height / 2, Default.Width / 2, Default.Height / 2); camera = new Camera(); cameraTop = new Camera(); cameraSide = new Camera(); cameraFront = new Camera(); camera.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Perspective.AspectRatio, 1.0f, 1000f); cameraTop.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Side.AspectRatio, 1.0f, 1000f); cameraSide.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Top.AspectRatio, 1.0f, 1000f); cameraFront.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Front.AspectRatio, 1.0f, 1000f); camera.Position = new Vector3(6, 6, 6); cameraTop.Position = new Vector3(0, 10, 0); cameraSide.Position = new Vector3(10, 0, 0); cameraFront.Position = new Vector3(0, 0, 10); cameraTop.LookAt = Vector3.Zero; cameraSide.LookAt = Vector3.Zero; cameraFront.LookAt = Vector3.Zero; camera.LookAt = Vector3.Zero; cameraTop.UpVector = new Vector3(1, 0, 0); camera.UpVector = new Vector3(0, 1, 0); cameraFront.UpVector = new Vector3(0, 1, 0); cameraSide.UpVector = new Vector3(0, 1, 0); }
private Ray GetMouseRay(Camera Perspective_Camera, Camera Top_Camera, Camera Side_Camera, Camera Front_Camera, params Viewport[] Viewport) { Vector2 MouseCoords = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Camera CurrentCamera = new Camera(); for (int i = 0; i < 4; i++) { if (Viewport[i].Bounds.Intersects(new Rectangle((int)MouseCoords.X, (int)MouseCoords.Y,1,1))) { if (i == 0) {CurrentCamera = Perspective_Camera;} if (i == 1) {CurrentCamera = Top_Camera;} if (i == 2) {CurrentCamera = Side_Camera;} if (i == 3) {CurrentCamera = Front_Camera;} Vector3 vec0 = Viewport[i].Unproject( new Vector3(MouseCoords, 0), CurrentCamera.ProjectionMatrix, CurrentCamera.ViewMatrix, Matrix.Identity); Vector3 vec1 = Viewport[i].Unproject( new Vector3(MouseCoords, 1), CurrentCamera.ProjectionMatrix, CurrentCamera.ViewMatrix, Matrix.Identity); Vector3 mouseDirection = vec1 - vec0; mouseDirection.Normalize(); return new Ray(vec0, mouseDirection); } } return new Ray(); }