Example #1
0
        public void TestFollowCurve()
        {
            XNAGame game = new XNAGame();

            Curve3D curve = Curve3D.CreateTestCurve();

            game.SpectaterCamera.CameraDirection = Vector3.Normalize(new Vector3(-0.2f, -1f, -0.4f));
            BoundingSphere sphere = curve.CalculateBoundingSphere();

            sphere.Radius += 1.5f;
            game.SpectaterCamera.FitInView(sphere);

            float time = 0;

            game.DrawEvent +=
                delegate
            {
                if (game.Keyboard.IsKeyPressed(Keys.V))
                {
                    game.SpectaterCamera.CameraDirection = Vector3.Normalize(new Vector3(-0.2f, -1f, -0.4f));
                }
                Render(curve, game, Color.Red);
                game.LineManager3D.AddCenteredBox(curve.Evaluate(time), 0.2f, Color.Green);
                time += game.Elapsed;
            };


            game.Run();
        }
Example #2
0
        public void Render(Curve3D curve, IXNAGame game, Color color)
        {
            float segmentLength = 0.1f;

            float start = curve.GetStart();
            float end   = curve.GetEnd();

            Vector3 lastPoint = curve.Evaluate(start);

            for (float i = start + segmentLength; i < end; i += segmentLength)
            {
                Vector3 newPoint = curve.Evaluate(i);
                game.LineManager3D.AddLine(lastPoint, newPoint, color);
                lastPoint = newPoint;
            }

            game.LineManager3D.AddLine(lastPoint, curve.Evaluate(end), color);
        }
Example #3
0
        public void Refresh(Curve3D path, float duration)
        {
            Debug.Assert(path != null, "Given path was null.");

            // TODO: Assign timer trigger function.
            timer.Duration = duration;
            timer.Tick     = t =>
            {
                Recompute(path.Evaluate(t));
            };
        }
Example #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();
        }
Example #5
0
        public void TestPhysicsEnableDisable()
        {
            List <ClientPhysicsTestSphere> spheres = new List <ClientPhysicsTestSphere>();

            ClientPhysicsQuadTreeNode root = CreateTestClientPhysicsQuadtree();



            spheres.Add(new ClientPhysicsTestSphere(new Vector3(0, 0, 0), 2));


            Curve3D curve1 = CreateTestObject1MovementCurve();



            float time         = 0;
            bool  progressTime = true;
            QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA();

            XNAGame game = new XNAGame();

            game.UpdateEvent +=
                delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.P))
                {
                    progressTime = !progressTime;
                }

                if (progressTime)
                {
                    time += game.Elapsed;
                }


                spheres[0].Move(root, curve1.Evaluate(time * (1 / 4f)));
            };

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

                    return(node.DynamicObjectsCount == 0 && !node.PhysicsEnabled);
                });
                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Red;

                    return(node.DynamicObjectsCount == 0 && node.PhysicsEnabled);
                });

                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Yellow;
                    if (node.DynamicObjectsCount == 1)
                    {
                        col = Color.Orange;
                    }

                    return(node.DynamicObjectsCount > 0);
                });

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

                    return(node.DynamicObjectsCount < 0);
                });
            };



            game.Run();
        }
Example #6
0
        public void TestEntityClientPhysis()
        {
            XNAGame game = new XNAGame();

            Database.Database database = loadDatabaseServices();

            EntityManagerService ems = new EntityManagerService(database);

            BoundingBox bb = new BoundingBox();



            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;

            TheWizards.Client.ClientPhysicsQuadTreeNode root;
            root = new ClientPhysicsQuadTreeNode(
                new BoundingBox(
                    new Vector3(-16 * 16 / 2f, -100, -16 * 16 / 2f),
                    new Vector3(16 * 16 / 2f, 100, 16 * 16 / 2f)));

            QuadTree.Split(root, 4);


            ClientPhysicsTestSphere sphere = new ClientPhysicsTestSphere(Vector3.Zero, 2);

            Curve3D curve1 = ClientTest.CreateTestObject1MovementCurve();


            QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA();
            float time = 0;

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


            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);

                EntityFullData      entityData;
                EntityClientPhysics entPhysics;



                entityData           = CreatePyramidEntity(ems, 5);
                entityData.Transform = new Transformation(
                    Vector3.One, Quaternion.Identity,
                    new Vector3(10, 2, 20));

                entPhysics = new EntityClientPhysics(entityData);
                entPhysics.LoadInClientPhysics(engine.Scene, root);
                entities.Add(entPhysics);

                entityData           = CreatePyramidEntity(ems, 20);
                entityData.Transform = new Transformation(
                    Vector3.One, Quaternion.Identity,
                    new Vector3(-32, 0, -40));

                entPhysics = new EntityClientPhysics(entityData);
                entPhysics.LoadInClientPhysics(engine.Scene, root);
                entities.Add(entPhysics);


                entityData = CreateTwoPyramidEntity(ems, 5, 3);
                entityData.ObjectFullData.Models[0].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(-3, 0, 3));
                entityData.ObjectFullData.Models[1].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(3, 1, 2));
                entityData.Transform = new Transformation(
                    Vector3.One * 2, Quaternion.Identity,
                    new Vector3(80, 0, -45));

                entPhysics = new EntityClientPhysics(entityData);
                entPhysics.LoadInClientPhysics(engine.Scene, root);
                entities.Add(entPhysics);
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);


                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.LineManager3D.AddCenteredBox(sphere.Center, sphere.Radius, Color.Red);

                for (int i = 0; i < entities.Count; i++)
                {
                    game.LineManager3D.AddCenteredBox(entities[i].BoundingSphere.Center,
                                                      entities[i].BoundingSphere.Radius * 2, Color.Black);
                }
            };
            game.UpdateEvent += delegate
            {
                time += game.Elapsed;


                sphere.Move(root, curve1.Evaluate(time * (1 / 4f)));


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    ClientPhysicsTestSphere iSphere = new ClientPhysicsTestSphere(engine.Scene,
                                                                                  game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection
                                                                                  , 1);

                    iSphere.InitDynamic();
                    iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;

                    spheres.Add(iSphere);
                }



                for (int i = 0; i < spheres.Count; i++)
                {
                    spheres[i].Update(root, game);
                }



                engine.Update(game.Elapsed);
            };


            game.Run();
        }
Example #7
0
        public void TestMeshPhysicsElementFactoryStatic()
        {
            XNAGame game = new XNAGame();

            var mesh = new RAMMesh();
            var data = mesh.GetCollisionData();

            var box = new MeshCollisionData.Box();

            box.Dimensions  = Vector3.One * 2;
            box.Orientation = Matrix.Identity;

            data.Boxes.Add(box);


            box             = new MeshCollisionData.Box();
            box.Dimensions  = Vector3.One * 4;
            box.Orientation = Matrix.CreateTranslation(new Vector3(2, 2, 2));

            data.Boxes.Add(box);


            BoundingBox bb = new BoundingBox();



            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;

            TheWizards.Client.ClientPhysicsQuadTreeNode root;
            root = new ClientPhysicsQuadTreeNode(
                new BoundingBox(
                    new Vector3(-16 * 16 / 2f, -100, -16 * 16 / 2f),
                    new Vector3(16 * 16 / 2f, 100, 16 * 16 / 2f)));

            QuadTree.Split(root, 4);


            ClientPhysicsTestSphere sphere = new ClientPhysicsTestSphere(Vector3.Zero, 2);

            Curve3D curve1 = ClientTest.CreateTestObject1MovementCurve();


            var   visualizer = new QuadTreeVisualizerXNA();
            float time       = 0;

            var spheres = new List <ClientPhysicsTestSphere>();
            var meshes  = new List <MeshStaticPhysicsElement>();

            var physicsElementFactoryXNA = new MeshPhysicsFactoryXNA(engine, root);
            var factory = physicsElementFactoryXNA.Factory;

            game.AddXNAObject(physicsElementFactoryXNA);

            var el = factory.CreateStaticElement(mesh, Matrix.CreateTranslation(new Vector3(20, 0, 20)));

            meshes.Add(el);


            el = factory.CreateStaticElement(mesh, Matrix.CreateTranslation(new Vector3(-40, 0, 8)));
            meshes.Add(el);


            el = factory.CreateStaticElement(mesh, Matrix.CreateTranslation(new Vector3(80, 0, 70)));
            meshes.Add(el);

            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);


                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.LineManager3D.AddCenteredBox(sphere.Center, sphere.Radius, Color.Red);

                for (int i = 0; i < meshes.Count; i++)
                {
                    game.LineManager3D.AddCenteredBox(meshes[i].BoundingSphere.Center,
                                                      meshes[i].BoundingSphere.Radius * 2, Color.Black);
                }
            };
            game.UpdateEvent += delegate
            {
                time += game.Elapsed;


                sphere.Move(root, curve1.Evaluate(time * (1 / 4f)));


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    ClientPhysicsTestSphere iSphere = new ClientPhysicsTestSphere(engine.Scene,
                                                                                  game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection
                                                                                  , 1);

                    iSphere.InitDynamic();
                    iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;

                    spheres.Add(iSphere);
                }



                for (int i = 0; i < spheres.Count; i++)
                {
                    spheres[i].Update(root, game);
                }



                engine.Update(game.Elapsed);
            };


            game.Run();
        }
        //[Test]
        //public void SparkleTest()
        //{
        //    Emitter emit;
        //    XNAGame game = new XNAGame();
        //    SparkelParticleCreater creater;
        //    game.DrawFps = true;

        //    var pool = new VertexDeclarationPool();
        //    pool.SetVertexElements<Emitter.ParticleVertex>(Emitter.ParticleVertex.VertexElements);
        //    var texPool = new TexturePoolTest();
        //    var testTexture = GetTestTexture();
        //    creater = new SparkelParticleCreater();
        //    EmitterParameters param = new EmitterParameters();
        //    param.EffectName = "CalculateSpark";
        //    param.texture = testTexture;
        //    param.particleCreater = creater;
        //    emit = new Emitter(texPool, pool, game, param);

        //    param.Directional = true;
        //    Seeder seed = new Seeder(54);
        //    param.UvStart = new Vector2(0, 0.5f);
        //    param.UvSize = new Vector2(0.5f, 0.1f);
        //    param.startColor = Color.LightYellow;
        //    param.endColor = Color.OrangeRed;
        //    game.Wpf.CreateClassForm(param);

        //    game.InitializeEvent += delegate
        //    {
        //        texPool.Initialize(game);
        //        pool.Initialize(game);

        //        emit.Initialize();
        //        emit.InitializeRender();


        //        emit.CreateRenderData();
        //        emit.SetRenderData();

        //    };
        //    float dist = 0;
        //    game.UpdateEvent += delegate
        //    {

        //        emit.Update();

        //    };
        //    game.DrawEvent += delegate
        //    {
        //        //game.GraphicsDevice.Clear(Color.Black);
        //        game.GraphicsDevice.RenderState.CullMode = CullMode.None;
        //        emit.Render(game.SpectaterCamera.ViewProjection, game.SpectaterCamera.ViewInverse);

        //    };

        //    game.Run();
        //}
        ////private void setColors(Emitter emit)
        ////{
        ////    //emit.StartColor = new Color(20,20,200);
        ////    emit.EndColor = new Color(0,0,0);
        ////}


        //[Test]
        //public void BasicEffectTest()
        //{

        //    XNAGame game = new XNAGame();
        //    SparkelParticleCreater creater;
        //    game.DrawFps = true;

        //    var pool = new VertexDeclarationPool();
        //    pool.SetVertexElements<Emitter.ParticleVertex>(Emitter.ParticleVertex.VertexElements);
        //    var texPool = new TexturePoolTest();
        //    var testTexture = GetTestTexture();
        //    creater = new SparkelParticleCreater();
        //    EmitterParameters param = new EmitterParameters();
        //    param.EffectName = "CalculateSpark";
        //    param.texture = testTexture;
        //    param.particleCreater = creater;
        //    param.Directional = true;
        //    Seeder seed = new Seeder(54);
        //    param.UvStart = new Vector2(0, 0.5f);
        //    param.UvSize = new Vector2(0.5f, 0.1f);
        //    param.startColor = Color.LightYellow;
        //    param.endColor = Color.OrangeRed;
        //    param.Continueous = false;


        //    ParticleEffect effect = new ParticleEffect(game, pool, texPool);game.Wpf.CreateClassForm(effect);
        //    effect.AddEmitter(param);
        //    game.InitializeEvent += delegate
        //    {
        //        texPool.Initialize(game);
        //        pool.Initialize(game);
        //        effect.Initialize();

        //    };
        //    float dist = 0;
        //    game.UpdateEvent += delegate
        //                            {
        //                                if(game.Keyboard.IsKeyPressed(Keys.T))
        //                                {
        //                                    effect.Trigger();
        //                                }
        //                                effect.Update();

        //                            };
        //    game.DrawEvent += delegate
        //    {
        //       game.GraphicsDevice.Clear(Color.Black);
        //       game.GraphicsDevice.RenderState.CullMode = CullMode.None;
        //       effect.Render(game.SpectaterCamera.ViewProjection, game.SpectaterCamera.ViewInverse);

        //    };

        //    game.Run();
        //}
        private void Temp(float dist, Emitter emit, Curve3D curve)
        {
            emit.SetPosition(curve.Evaluate(dist * 3).dx() * 2);
        }