public void Move(ClientPhysicsQuadTreeNode root, Matrix newPose)
        {
            if (actor == null)
            {
                throw new InvalidOperationException();
            }
            // NOTE: IMPORTANT: this is actually a partial implementation of the algorithm itself

            Matrix oldPose = World;
            ClientPhysicsQuadTreeNode oldNode = Node;


            // Update location in quadtree
            world = newPose;
            root.OrdenObject(this);

            // Update dynamic object count

            Node.AddDynamicObjectToIntersectingNodes(this); // Add must come before remove to prevent overhead

            if (oldNode != null)
            {
                world = oldPose; // set old state
                oldNode.RemoveDynamicObjectFromIntersectingNodes(this);

                world = newPose;  // set new state
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This updates the position of the client physics object to the controller's position,
        /// and updates the dynamicobjectscount in the Client Physics
        /// This uses the dynamic object trick
        /// </summary>
        public void Update(ClientPhysicsQuadTreeNode root)
        {
            // First adds count, then removes. This is simply to ensure that objects are not flicked on of this frame

            Vector3 oldPosition = currentPosition;
            Vector3 newPosition = controller.GlobalPosition;

            currentPosition = newPosition;

            ClientPhysicsQuadTreeNode oldNode = node;

            root.OrdenObject(this);

            node.AddDynamicObjectToIntersectingNodes(this);

            if (oldNode != null)
            {
                currentPosition = oldPosition;
                oldNode.RemoveDynamicObjectFromIntersectingNodes(this);
                currentPosition = newPosition;
            }
        }
Exemplo n.º 3
0
            public void Move(ClientPhysicsQuadTreeNode root, Vector3 newCenter)
            {
                // NOTE: IMPORTANT: this is actually a partial implementation of the algorithm itself

                Vector3 oldCenter = Center;
                ClientPhysicsQuadTreeNode oldNode = Node;


                // Update location in quadtree
                Center = newCenter;
                root.OrdenObject(this);

                // Update dynamic object count

                Node.AddDynamicObjectToIntersectingNodes(this);   // Add must come before remove to prevent overhead

                if (oldNode != null)
                {
                    Center = oldCenter; // set old state
                    oldNode.RemoveDynamicObjectFromIntersectingNodes(this);

                    Center = newCenter; // set new state
                }
            }
Exemplo n.º 4
0
        public void TestPhysicsQuadTreeOrdenObjects()
        {
            ClientPhysicsQuadTreeNode root = CreateTestClientPhysicsQuadtree();

            List <ClientPhysicsTestSphere> spheres = new List <ClientPhysicsTestSphere>();

            spheres.Add(new ClientPhysicsTestSphere(new Vector3(3, 0, 3), 1));
            spheres.Add(new ClientPhysicsTestSphere(new Vector3(33, 0, -83), 1));
            spheres.Add(new ClientPhysicsTestSphere(new Vector3(-25, 0, 40), 1));
            spheres.Add(new ClientPhysicsTestSphere(new Vector3(-25, 0, -35), 1));
            for (int i = 0; i < spheres.Count; i++)
            {
                root.OrdenObject(spheres[i]);
            }


            ClientPhysicsTestSphere movingSphere = new ClientPhysicsTestSphere(Vector3.Zero, 2);
            Curve3D curve = CreateTestObject1MovementCurve();

            float time = 0;

            QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA();

            XNAGame game = new XNAGame();

            game.UpdateEvent +=
                delegate
            {
                time += game.Elapsed;
                movingSphere.Center = curve.Evaluate(time * (1 / 4f));
                root.OrdenObject(movingSphere);
            };

            game.DrawEvent +=
                delegate
            {
                for (int i = 0; i < spheres.Count; i++)
                {
                    game.LineManager3D.AddCenteredBox(spheres[i].Center, spheres[i].Radius, Color.Red);
                }
                game.LineManager3D.AddCenteredBox(movingSphere.Center, movingSphere.Radius, Color.Red);
                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Green;

                    return(node.PhysicsObjects.Count == 0);
                });

                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Orange;

                    return(node.PhysicsObjects.Count > 0);
                });
            };



            game.Run();
        }