Exemplo n.º 1
0
        public void Add(CameraLayout cameraLayout, Camera3D camera)
        {
            if (this.cameraDictionary.ContainsKey(cameraLayout))
            {
                List<Camera3D> list = this.cameraDictionary[cameraLayout];

                if(!list.Contains(camera))
                    list.Add(camera);
            }
            else
            {
                List<Camera3D> list = new List<Camera3D>();
                list.Add(camera);
                this.cameraDictionary.Add(cameraLayout, list);
            }
        }
 public CharacterModelObject(string id, ObjectType objectType, Transform3D transform, Effect effect,
     Texture2D texture, Model model, Camera3D camera, Color color, float alpha)
     : base(id, objectType, transform, effect, texture, model, color, alpha)
 {
     this.camera = camera;
 }
 public CharacterModelObject(string id, ObjectType objectType, Transform3D transform, Effect effect, 
     Model model, Color color, float alpha)
     : base(id, objectType, transform, effect, null, model, color, alpha)
 {
     this.camera = null;
 }
        private void testCloning()
        {
            Transform3D t1
                = new Transform3D(Vector3.One,
                    Vector3.Zero,
                    Vector3.One, Vector3.UnitZ,
                    Vector3.UnitY);

            Transform3D clone
                    = (Transform3D)t1.Clone();

            clone.Translation = new Vector3(1, 2, 3);

            if (clone.Translation.Equals(t1.Translation))
                Console.WriteLine("same!");
            else
                Console.WriteLine("different!");

            Camera3D c1 = new Camera3D("1",
                ObjectType.FirstPersonCamera,
                t1,
                ProjectionParameters.StandardMediumFourThree,
                new Viewport(0,0,800,600));

            Camera3D cloneC1 = (Camera3D)c1.Clone();
            cloneC1.Viewport = new Viewport(0, 0, 10, 10);
        }
        //used when in 1st person collidable camera mode
        //start distance allows us to start the ray outside the collidable skin of the 1st person colliable camera object
        //otherwise the only thing we would ever collide with would be ourselves!
        public Actor GetPickedObject(Camera3D camera, float startDistance, float distance,
                   out Vector3 pos, out Vector3 normal)
        {
            Vector3 ray = GetMouseRayDirection(camera);
            ImmovableSkinPredicate pred = new ImmovableSkinPredicate();

            this.game.PhysicsManager.PhysicsSystem.CollisionSystem.SegmentIntersect(
                out frac, out skin, out pos, out normal,
                new Segment(camera.Transform3D.Translation + startDistance * Vector3.Normalize(ray), ray * distance), pred);

            if (skin != null && skin.Owner != null)
            {
                return skin.Owner.ExternalData as Actor;
            }

            return null;
        }
        //get a ray from a user-defined near position in world space and the mouse pointer
        public Microsoft.Xna.Framework.Ray GetMouseRayFromNearPosition(Camera3D camera, Vector3 near)
        {
            //get the positions of the mouse in screen space
            Vector3 far = new Vector3(this.newState.X, this.Position.Y, 1);

            //convert from screen space to world space
            far = camera.Viewport.Unproject(far, camera.ProjectionParameters.Projection, camera.View, Matrix.Identity);

            //generate a ray to use for intersection tests
            return new Microsoft.Xna.Framework.Ray(near, Vector3.Normalize(far - near));
        }
        public Vector3 GetMouseRayDirection(Camera3D camera)
        {
            //get the positions of the mouse in screen space
            Vector3 near = new Vector3(this.newState.X, this.Position.Y, 0);
            Vector3 far = new Vector3(this.newState.X, this.Position.Y, 1);

            //convert from screen space to world space
            near = camera.Viewport.Unproject(near, camera.ProjectionParameters.Projection, camera.View, Matrix.Identity);
            far = camera.Viewport.Unproject(far, camera.ProjectionParameters.Projection, camera.View, Matrix.Identity);

            //generate a ray to use for intersection tests
            return far - near;
        }
        //get a ray positioned at the mouse's location on the screen - used for picking
        public Microsoft.Xna.Framework.Ray GetMouseRay(Camera3D camera)
        {
            //get the positions of the mouse in screen space
            Vector3 near = new Vector3(this.newState.X, this.Position.Y, 0);

            //convert from screen space to world space
            near = camera.Viewport.Unproject(near, camera.ProjectionParameters.Projection, camera.View, Matrix.Identity);

            return GetMouseRayFromNearPosition(camera, near);
        }
Exemplo n.º 9
0
        public static void DrawBoundingBox(BoundingBoxBuffers buffers, BasicEffect effect,
            GraphicsDevice graphicsDevice, Camera3D camera)
        {
            graphicsDevice.SetVertexBuffer(buffers.Vertices);
            graphicsDevice.Indices = buffers.Indices;

            effect.World = Matrix.Identity;
            effect.View = camera.View;
            effect.Projection = camera.ProjectionParameters.Projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0,
                    buffers.VertexCount, 0, buffers.PrimitiveCount);
            }
        }
        public void FindCameraBy(string cameraLayout, string cameraID, out Camera3D camera, out int index)
        {
            camera = null;
            index = -1;

            List<Camera3D> list = this.cameraDictionary[cameraLayout];

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].ID.Equals(cameraID))
                    {
                        camera = list[i];
                        index = i;
                        break;
                    }
                }
            }
        }
 public CharacterMoveController(Main game, string name, Actor parentActor, bool bEnabled, Camera3D camera)
     : base(name, parentActor, bEnabled)
 {
     this.game = game;
     this.camera = camera;
 }