Ejemplo n.º 1
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     camera = new Camera(GraphicsDevice);
     Vector3 mid = Vector3.Zero;
     if (RenderModel != null)
         mid = new Vector3((RenderModel.CompressionBounds.X.Min + RenderModel.CompressionBounds.X.Max) / 2, (RenderModel.CompressionBounds.Y.Min + RenderModel.CompressionBounds.Y.Max) / 2, (RenderModel.CompressionBounds.Z.Min + RenderModel.CompressionBounds.Z.Max) / 2);
     camera.LookAt(new Vector3(mid.X, mid.Y, mid.Z));
     camera.Zoom = 20f;
     camera.Transformations *= Matrix.CreateFromAxisAngle(Vector3.UnitZ, (float)-(Math.PI + (Math.PI / 4)));
     camera.CalculateFrame();
     camera.Transformations *= Matrix.CreateFromAxisAngle(camera.Right, (float)-(Math.PI / 5));
     camera.CalculateFrame();
     font = Content.Load<SpriteFont>("debug");
     myVertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
     IntializeEffect();
     spriteBatch = new SpriteBatch(GraphicsDevice);
 }
Ejemplo n.º 2
0
        public static Ray GetMouseRay(Vector2 mousePosition, Viewport viewport, Camera camera)
        {
            Vector3 nearPoint = new Vector3(mousePosition, 0);
            Vector3 farPoint = new Vector3(mousePosition, 1);
            nearPoint = viewport.Unproject(nearPoint, camera.Projection, camera.View, Matrix.Identity);
            farPoint = viewport.Unproject(farPoint, camera.Projection, camera.View, Matrix.Identity);
            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();

            return new Ray(nearPoint, direction);
        }