예제 #1
0
        private void InitializeCamera()
        {
            float aspectRatio = (float)GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height;
            float fov         = MathHelper.PiOver4 * aspectRatio * 3 / 4;

            projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, .1f, 2000f);
            world      = Matrix.Identity;

            camera          = new ArcBallCamera(ArcBallCameraMode.RollConstrained);
            camera.Distance = 450;
            //orbit the camera so we're looking down the z=-1 axis
            //the acr-ball camera is traditionally oriented to look
            //at the "front" of an object
            camera.OrbitRight(MathHelper.Pi);
            camera.OrbitUp(1.0f);
            camera.InputDistanceRate = 100;
        }
예제 #2
0
파일: Sky.cs 프로젝트: spech66/marvinsarena
        public void Draw(GraphicsDevice graphics, ArcBallCamera camera, Matrix projection)
        {
            // Set the parameters of the effect
            skySphereEffect.Parameters["ViewMatrix"].SetValue(camera.ViewMatrix);
            skySphereEffect.Parameters["ProjectionMatrix"].SetValue(projection);

            foreach (ModelMesh mesh in skySphere.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = skySphereEffect;
                }
            }

            // Draw model
            foreach (ModelMesh mesh in skySphere.Meshes)
            {
                mesh.Draw();
            }

            // Undo the renderstate settings from the shader
            graphics.RasterizerState   = RasterizerState.CullCounterClockwise;
            graphics.DepthStencilState = DepthStencilState.Default;
        }
예제 #3
0
        public void DrawrobotNames(SpriteBatch spriteBatch, WorldObjectRobot robot, GraphicsDevice graphicsDevice, ArcBallCamera camera, Matrix projection)
        {
            GameObjectRobot gameObjectRobot = (GameObjectRobot)robot.GameObject;
            Vector3         screenSpace     = graphicsDevice.Viewport.Project(Vector3.Zero,
                                                                              projection,
                                                                              camera.ViewMatrix,
                                                                              Matrix.CreateTranslation(robot.PositionX, robot.PositionY, robot.PositionZ));

            // Get 2D coordinates from screenspace vector
            Vector2 textPosition;

            textPosition.X = screenSpace.X;
            textPosition.Y = screenSpace.Y;

            // Center the text
            Vector2 stringCenter = FontSmall.MeasureString(gameObjectRobot.FullName) * 0.5f;

            // Calculate position
            textPosition.X = (int)(textPosition.X - stringCenter.X);
            //textPosition.Y = (int)(textPosition.Y - stringCenter.Y);
            textPosition.Y = (int)(textPosition.Y + stringCenter.Y);

            // Skip if out of screen
            if (textPosition.X < 0 || textPosition.X > graphicsDevice.Viewport.Width)
            {
                return;
            }
            if (textPosition.Y < 0 || textPosition.Y > graphicsDevice.Viewport.Height)
            {
                return;
            }

            // Draw the text
            spriteBatch.DrawString(FontSmall, gameObjectRobot.FullName, textPosition, Color.White);
        }