Exemplo n.º 1
0
        private void AddEntityToCollisionGroup(string entityName, Physic3DCollisionGroup group)
        {
            var entity    = this.EntityManager.Find(entityName);
            var rigidBody = entity.FindComponent <RigidBody3D>();

            rigidBody.CollisionGroup = group;
        }
Exemplo n.º 2
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.CornflowerBlue;

            // Main Camera definition and Pick Entity Behavior
            FreeCamera camera = new FreeCamera("MainCamera", new Vector3(0, 40, 50), Vector3.Zero);
            camera.Entity.AddComponent(new PickingBehavior());
            this.EntityManager.Add(camera.Entity);

            // Sample needs Collision groups to ignore collisions between wheels and body
            // Collision group 1: Body
            // Collision group 2: Wheels (ignores collision with body)
            // collision group 3: terrain (collides with body and wheels)
            Physic3DCollisionGroup bodyCollisiongroup = new Physic3DCollisionGroup();

            Physic3DCollisionGroup wheelCollistionGroup = new Physic3DCollisionGroup();
            wheelCollistionGroup.IgnoreCollisionWith(bodyCollisiongroup);

            Physic3DCollisionGroup terrainCollisiongroup = new Physic3DCollisionGroup();
            terrainCollisiongroup.DefineCollisionWith(bodyCollisiongroup);
            terrainCollisiongroup.DefineCollisionWith(wheelCollistionGroup);

            // Creates Entities
            this.CreateGround(new Vector3(0, -5, 0), terrainCollisiongroup);
            this.CreateVehicle(bodyCollisiongroup, wheelCollistionGroup);
        }
Exemplo n.º 3
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.CornflowerBlue;

            // Main Camera definition and Pick Entity Behavior
            FreeCamera camera = new FreeCamera("MainCamera", new Vector3(0, 40, 50), Vector3.Zero);

            camera.Entity.AddComponent(new PickingBehavior());
            this.EntityManager.Add(camera.Entity);

            // Sample needs Collision groups to ignore collisions between wheels and body
            // Collision group 1: Body
            // Collision group 2: Wheels (ignores collision with body)
            // collision group 3: terrain (collides with body and wheels)
            Physic3DCollisionGroup bodyCollisiongroup = new Physic3DCollisionGroup();

            Physic3DCollisionGroup wheelCollistionGroup = new Physic3DCollisionGroup();

            wheelCollistionGroup.IgnoreCollisionWith(bodyCollisiongroup);

            Physic3DCollisionGroup terrainCollisiongroup = new Physic3DCollisionGroup();

            terrainCollisiongroup.DefineCollisionWith(bodyCollisiongroup);
            terrainCollisiongroup.DefineCollisionWith(wheelCollistionGroup);

            // Creates Entities
            this.CreateGround(new Vector3(0, -5, 0), terrainCollisiongroup);
            this.CreateVehicle(bodyCollisiongroup, wheelCollistionGroup);
        }
Exemplo n.º 4
0
 public FireBehavior(Physic3DCollisionGroup collisionGroup)
     : base("FireBehavior")
 {
     this.collisionGroup = collisionGroup;
     this.ballMaterial = new NormalMappingMaterial("Content/Textures/ball_diffuse.png", "Content/Textures/ball_normal_spec.png")
         {
             AmbientColor = Color.White * 0.4f
         };
 }
Exemplo n.º 5
0
 public FireBehavior(Physic3DCollisionGroup collisionGroup)
     : base("FireBehavior")
 {
     this.collisionGroup = collisionGroup;
     this.ballMaterial   = new NormalMappingMaterial("Content/Textures/ball_diffuse.png", "Content/Textures/ball_normal_spec.png")
     {
         AmbientColor = Color.White * 0.4f
     };
 }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a Physical Box
        /// </summary>
        /// <param name="position">Entity Position</param>
        /// <param name="collisionGroup">Collision Group</param>
        /// <param name="isKinematic">Is Kinematic</param>
        /// <returns>A Box Entity</returns>
        private Entity CreateBox(Vector3 position, Physic3DCollisionGroup collisionGroup, bool isKinematic)
        {
            Entity primitive = new Entity("box" + instance++)
                .AddComponent(new Transform3D() { Position = position, Scale = new Vector3(3, 0.5f, 2) })
                .AddComponent(new BoxCollider())
                .AddComponent(Model.CreateCube())
                .AddComponent(new RigidBody3D() { IsKinematic = isKinematic, CollisionGroup = collisionGroup })
                .AddComponent(new MaterialsMap())
                .AddComponent(new ModelRenderer());

            return primitive;
        }
Exemplo n.º 7
0
        private void DefineCollisionGroups()
        {
            this.sceneGroup  = new Physic3DCollisionGroup();
            this.ballGroup   = new Physic3DCollisionGroup();
            this.cameraGroup = new Physic3DCollisionGroup();

            this.cameraGroup.DefineCollisionWith(this.sceneGroup);
            this.cameraGroup.IgnoreCollisionWith(this.ballGroup);
            this.ballGroup.IgnoreCollisionWith(this.sceneGroup);
            this.ballGroup.IgnoreCollisionWith(this.ballGroup);

            this.sceneGroup.DefineCollisionWith(this.cameraGroup);
            this.sceneGroup.DefineCollisionWith(this.ballGroup);
        }
		public Creature(Vector2 startPosition)
		{
			var collisionGroup = new Physic3DCollisionGroup();
			//collisionGroup.DefineCollisionWith(Physic3DCollisionGroup.DefaulCollisionGroup);

			Behavior = new CreatureBehavior();

			entity = new Entity("Creature" + _creatureCount++)
				.AddComponent(new Transform3D {Position = new Vector3(startPosition.X, 0, startPosition.Y), Scale = new Vector3(2)})
				.AddComponent(new MaterialsMap(new BasicMaterial(Color.BlueViolet)))
				.AddComponent(Model.CreateSphere())
				.AddComponent(new SphereCollider())
				.AddComponent(new RigidBody3D {Mass = 3, EnableContinuousContact = true, CollisionGroup = collisionGroup})
				.AddComponent(new ModelRenderer())
				.AddComponent(Behavior);
		}
Exemplo n.º 9
0
        private void SetUpPhysicsOnGround(Physic3DCollisionGroup chasisCollisionGroup)
        {
            var chasis = this.EntityManager.Find("chasis");

            if (chasis == null)
            {
                return;
            }

            var chasisRigidBody = chasis.FindComponent <RigidBody3D>();

            if (chasisRigidBody == null)
            {
                return;
            }

            chasisRigidBody.CollisionGroup = chasisCollisionGroup;
        }
Exemplo n.º 10
0
        private void SetUpPhysicsOnChasis(Physic3DCollisionGroup groundCollisionGroup)
        {
            var ground = this.EntityManager.Find("ground");

            if (ground == null)
            {
                return;
            }

            var groundRigidBody = ground.FindComponent <RigidBody3D>();

            if (groundRigidBody == null)
            {
                return;
            }

            groundRigidBody.CollisionGroup = groundCollisionGroup;
        }
Exemplo n.º 11
0
        private void SetUpPhysicsOnChasis(Physic3DCollisionGroup groundCollisionGroup)
        {
            var ground = this.EntityManager.Find("ground");

            if (ground == null)
            {
                return;
            }

            var groundRigidBody = ground.FindComponent<RigidBody3D>();

            if (groundRigidBody == null)
            {
                return;
            }

            groundRigidBody.CollisionGroup = groundCollisionGroup;
        }
Exemplo n.º 12
0
        private void SetUpPhysicsOnGround(Physic3DCollisionGroup chasisCollisionGroup)
        {
            var chasis = this.EntityManager.Find("chasis");

            if (chasis == null)
            {
                return;
            }

            var chasisRigidBody = chasis.FindComponent<RigidBody3D>();

            if (chasisRigidBody == null)
            {
                return;
            }

            chasisRigidBody.CollisionGroup = chasisCollisionGroup;
        }
Exemplo n.º 13
0
        protected override void CreateScene()
        {
            this.Load(WaveContent.Scenes.MyScene);

            // This sample needs Collision Groups to ignore such between chasis and wheels
            var chasisCollisionGroup = new Physic3DCollisionGroup();

            var wheelCollisionGroup = new Physic3DCollisionGroup();
            wheelCollisionGroup.IgnoreCollisionWith(chasisCollisionGroup);

            var groundCollisionGroup = new Physic3DCollisionGroup();
            groundCollisionGroup.DefineCollisionWith(chasisCollisionGroup);
            groundCollisionGroup.DefineCollisionWith(wheelCollisionGroup);

            this.SetUpPhysicsOnGround(chasisCollisionGroup);
            this.SetUpPhysicsOnWheels(wheelCollisionGroup);
            this.SetUpPhysicsOnChasis(groundCollisionGroup);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a Physical Ground
        /// </summary>
        /// <param name="position">Ground position</param>
        /// <param name="collisionGroup">Ground Collision Group</param>
        private void CreateGround(Vector3 position, Physic3DCollisionGroup collisionGroup)
        {
            Entity terrain = new Entity("terrain" + instance++)
                             .AddComponent(new Transform3D()
            {
                Position = position, Scale = new Vector3(4)
            })
                             .AddComponent(new MeshCollider())
                             .AddComponent(new Model("Content/terrain.wpk"))
                             .AddComponent(new RigidBody3D()
            {
                IsKinematic = true, CollisionGroup = collisionGroup, KineticFriction = 10, StaticFriction = 10
            })
                             .AddComponent(new MaterialsMap())
                             .AddComponent(new ModelRenderer());

            EntityManager.Add(terrain);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a Physical Box
        /// </summary>
        /// <param name="position">Entity Position</param>
        /// <param name="collisionGroup">Collision Group</param>
        /// <param name="isKinematic">Is Kinematic</param>
        /// <returns>A Box Entity</returns>
        private Entity CreateBox(Vector3 position, Physic3DCollisionGroup collisionGroup, bool isKinematic)
        {
            Entity primitive = new Entity("box" + instance++)
                               .AddComponent(new Transform3D()
            {
                Position = position, Scale = new Vector3(3, 0.5f, 2)
            })
                               .AddComponent(new BoxCollider())
                               .AddComponent(Model.CreateCube())
                               .AddComponent(new RigidBody3D()
            {
                IsKinematic = isKinematic, CollisionGroup = collisionGroup
            })
                               .AddComponent(new MaterialsMap())
                               .AddComponent(new ModelRenderer());

            return(primitive);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a Cylindric Entity
        /// </summary>
        /// <param name="position">Entity Position</param>
        /// <param name="isKinematic">Is Kinematic</param>
        /// <param name="collisionGroup">Collision group</param>
        /// <returns>A Cylindical entity</returns>
        private Entity CreateCylinder(Vector3 position, bool isKinematic, Physic3DCollisionGroup collisionGroup)
        {
            Entity primitive = new Entity("cylinder" + instance++)
                               .AddComponent(new Transform3D()
            {
                Position = position, Scale = new Vector3(1, 0.5f, 1), Rotation = new Vector3(MathHelper.ToRadians(90), 0, 0)
            })
                               .AddComponent(new SphereCollider()) // We use SphereCollider with Cylinder Model.
                               .AddComponent(Model.CreateCylinder())
                               .AddComponent(new RigidBody3D()
            {
                IsKinematic = isKinematic, CollisionGroup = collisionGroup, KineticFriction = 10, StaticFriction = 10
            })
                               .AddComponent(new MaterialsMap())
                               .AddComponent(new ModelRenderer());

            return(primitive);
        }
Exemplo n.º 17
0
        private void SetUpPhysicsOnWheels(Physic3DCollisionGroup wheelCollisionGroup)
        {
            var wheels = this.EntityManager.FindAllByTag("wheel").Cast <Entity>();

            if (wheels == null || wheels.Count() == 0)
            {
                return;
            }

            var chasis = this.EntityManager.Find("chasis");

            if (chasis == null)
            {
                return;
            }

            var i = 0;

            foreach (var wheel in wheels)
            {
                var wheelRigidBody = wheel.FindComponent <RigidBody3D>();

                if (wheelRigidBody == null)
                {
                    return;
                }

                wheelRigidBody.CollisionGroup = wheelCollisionGroup;

                var hingeJoint = new HingeJoint3D(chasis, Vector3.Zero, -Vector3.UnitY);
                var jointMap   = new JointMap3D()
                                 .AddJoint("chasisWheelJoint" + i++, hingeJoint);

                if (wheel.Name.Contains("Front"))
                {
                    hingeJoint.IsMotorEnabled = true;
                    hingeJoint.MotorVelocity  = MathHelper.Pi * 2;
                    hingeJoint.MotorDamping   = 1 / 500;
                    hingeJoint.MotorMaxForce  = 500;
                }

                wheel.AddComponent(jointMap);
            }
        }
Exemplo n.º 18
0
        private void SetUpPhysicsOnWheels(Physic3DCollisionGroup wheelCollisionGroup)
        {
            var wheels = this.EntityManager.FindAllByTag("wheel").Cast<Entity>();

            if (wheels == null || wheels.Count() == 0)
            {
                return;
            }

            var chasis = this.EntityManager.Find("chasis");

            if (chasis == null)
            {
                return;
            }

            var i = 0;

            foreach (var wheel in wheels)
            {
                var wheelRigidBody = wheel.FindComponent<RigidBody3D>();

                if (wheelRigidBody == null)
                {
                    return;
                }

                wheelRigidBody.CollisionGroup = wheelCollisionGroup;

                var hingeJoint = new HingeJoint3D(chasis, Vector3.Zero, -Vector3.UnitY);
                var jointMap = new JointMap3D()
                    .AddJoint("chasisWheelJoint" + i++, hingeJoint);

                if (wheel.Name.Contains("Front"))
                {
                    hingeJoint.IsMotorEnabled = true;
                    hingeJoint.MotorVelocity = MathHelper.Pi * 2;
                    hingeJoint.MotorDamping = 1 / 500;
                    hingeJoint.MotorMaxForce = 500;
                }

                wheel.AddComponent(jointMap);
            }
        }
Exemplo n.º 19
0
        protected override void CreateScene()
        {
            this.Load(WaveContent.Scenes.MyScene);

            // This sample needs Collision Groups to ignore such between chasis and wheels
            var chasisCollisionGroup = new Physic3DCollisionGroup();

            var wheelCollisionGroup = new Physic3DCollisionGroup();

            wheelCollisionGroup.IgnoreCollisionWith(chasisCollisionGroup);

            var groundCollisionGroup = new Physic3DCollisionGroup();

            groundCollisionGroup.DefineCollisionWith(chasisCollisionGroup);
            groundCollisionGroup.DefineCollisionWith(wheelCollisionGroup);

            this.SetUpPhysicsOnGround(chasisCollisionGroup);
            this.SetUpPhysicsOnWheels(wheelCollisionGroup);
            this.SetUpPhysicsOnChasis(groundCollisionGroup);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create Scene
        /// </summary>
        protected override void CreateScene()
        {
            RenderManager.DebugLines = true;

            // Createa a Free Camera (W, A, S, D Keyboard controlled)
            FreeCamera camera = new FreeCamera("MainCamera", new Vector3(0, 5, 5), Vector3.Zero)
            {
                BackgroundColor = Color.CornflowerBlue,
            };

            EntityManager.Add(camera.Entity);

            // We set group before entities grouping
            this.groupA = new Physic3DCollisionGroup();
            this.groupB = new Physic3DCollisionGroup();

            // GroupA RED will Ignore Self Group Collision
            this.groupA.IgnoreCollisionWith(this.groupA);

            // GroupA RED will Ignore GroupB BLUE Collision
            this.groupA.IgnoreCollisionWith(this.groupB);

            // GroupB BLUE will Collide Self group entities.
            // Every entity collide all groups by default for each new Collision group.
            // Use Physic3DCollisionGroup.DefaulCollisionGroup Property to get Engine Physic3D default Collision group

            // Creates a plane ground
            this.CreateGround();

            // Creates Blue-Blue enviroment
            this.CreateSphere(new Vector3(-2, 0, -3), true);
            this.CreateSphere(new Vector3(2, 0, -3), true);

            // Creates Blue-Red enviroment
            this.CreateSphere(new Vector3(-2, 0, -1), true);
            this.CreateSphere(new Vector3(2, 0, -1), false);

            // Creates Red-Red enviroment
            this.CreateSphere(new Vector3(-2, 0, 1), false);
            this.CreateSphere(new Vector3(2, 0, 1), false);
        }
Exemplo n.º 21
0
        public Creature(Vector2 startPosition)
        {
            var collisionGroup = new Physic3DCollisionGroup();

            //collisionGroup.DefineCollisionWith(Physic3DCollisionGroup.DefaulCollisionGroup);

            Behavior = new CreatureBehavior();

            entity = new Entity("Creature" + _creatureCount++)
                     .AddComponent(new Transform3D {
                Position = new Vector3(startPosition.X, 0, startPosition.Y), Scale = new Vector3(2)
            })
                     .AddComponent(new MaterialsMap(new BasicMaterial(Color.BlueViolet)))
                     .AddComponent(Model.CreateSphere())
                     .AddComponent(new SphereCollider())
                     .AddComponent(new RigidBody3D {
                Mass = 3, EnableContinuousContact = true, CollisionGroup = collisionGroup
            })
                     .AddComponent(new ModelRenderer())
                     .AddComponent(Behavior);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Create Scene
        /// </summary>
        protected override void CreateScene()
        {
            RenderManager.DebugLines = true;

            // Createa a Free Camera (W, A, S, D Keyboard controlled)
            FreeCamera camera = new FreeCamera("MainCamera", new Vector3(0, 5, 5), Vector3.Zero)
            {
                BackgroundColor = Color.CornflowerBlue,
            };
            EntityManager.Add(camera.Entity);

            // We set group before entities grouping
            this.groupA = new Physic3DCollisionGroup();
            this.groupB = new Physic3DCollisionGroup();

            // GroupA RED will Ignore Self Group Collision
            this.groupA.IgnoreCollisionWith(this.groupA);

            // GroupA RED will Ignore GroupB BLUE Collision
            this.groupA.IgnoreCollisionWith(this.groupB);

            // GroupB BLUE will Collide Self group entities.
            // Every entity collide all groups by default for each new Collision group.
            // Use Physic3DCollisionGroup.DefaulCollisionGroup Property to get Engine Physic3D default Collision group

            // Creates a plane ground
            this.CreateGround();

            // Creates Blue-Blue enviroment
            this.CreateSphere(new Vector3(-2, 0, -3), true);
            this.CreateSphere(new Vector3(2, 0, -3), true);

            // Creates Blue-Red enviroment
            this.CreateSphere(new Vector3(-2, 0, -1), true);
            this.CreateSphere(new Vector3(2, 0, -1), false);

            // Creates Red-Red enviroment
            this.CreateSphere(new Vector3(-2, 0, 1), false);
            this.CreateSphere(new Vector3(2, 0, 1), false);
        }
Exemplo n.º 23
0
        protected override void CreateScene()
        {
            this.Load(WaveContent.Scenes.MyScene);

            var groupA = new Physic3DCollisionGroup();
            var groupB = new Physic3DCollisionGroup();

            // GroupA RED will Ignore Self Group Collision
            groupA.IgnoreCollisionWith(groupA);

            // GroupA RED will Ignore GroupB BLUE Collision
            groupA.IgnoreCollisionWith(groupB);

            // Creates Red-Red enviroment
            this.AddEntityToCollisionGroup("sphereA01", groupA);
            this.AddEntityToCollisionGroup("sphereA02", groupA);
            // Creates Blue-Red enviroment
            this.AddEntityToCollisionGroup("sphereA03", groupA);
            this.AddEntityToCollisionGroup("sphereB01", groupB);
            // Creates Blue-Blue enviroment
            this.AddEntityToCollisionGroup("sphereB02", groupB);
            this.AddEntityToCollisionGroup("sphereB03", groupB);
        }
Exemplo n.º 24
0
        protected override void CreateScene()
        {
            this.Load(WaveContent.Scenes.MyScene);

            var groupA = new Physic3DCollisionGroup();
            var groupB = new Physic3DCollisionGroup();

            // GroupA RED will Ignore Self Group Collision
            groupA.IgnoreCollisionWith(groupA);

            // GroupA RED will Ignore GroupB BLUE Collision
            groupA.IgnoreCollisionWith(groupB);

            // Creates Red-Red enviroment
            this.AddEntityToCollisionGroup("sphereA01", groupA);
            this.AddEntityToCollisionGroup("sphereA02", groupA);
            // Creates Blue-Red enviroment
            this.AddEntityToCollisionGroup("sphereA03", groupA);
            this.AddEntityToCollisionGroup("sphereB01", groupB);
            // Creates Blue-Blue enviroment
            this.AddEntityToCollisionGroup("sphereB02", groupB);
            this.AddEntityToCollisionGroup("sphereB03", groupB);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Creates a Vehicle
        /// </summary>
        /// <param name="bodyCollisiongroup">Vehicle body collision group</param>
        /// <param name="wheelCollisionGroup">Vehicle Wheels collision group</param>
        private void CreateVehicle(Physic3DCollisionGroup bodyCollisiongroup, Physic3DCollisionGroup wheelCollisionGroup)
        {
            bool isKinetikVehicle = false;

            // Initial parts positions
            Vector3 bodyPosition   = new Vector3(0, 5, 0);
            Vector3 wheel1Position = bodyPosition + new Vector3(1, -0.3f, 0.7f);
            Vector3 wheel2Position = bodyPosition + new Vector3(1, -0.3f, -0.7f);
            Vector3 wheel3Position = bodyPosition + new Vector3(-1, -0.3f, 0.7f);
            Vector3 wheel4Position = bodyPosition + new Vector3(-1, -0.3f, -0.7f);

            // Vehicle Parts entities
            Entity vBody  = this.CreateBox(bodyPosition, bodyCollisiongroup, isKinetikVehicle);
            Entity wheel1 = this.CreateCylinder(wheel1Position, isKinetikVehicle, wheelCollisionGroup);
            Entity wheel2 = this.CreateCylinder(wheel2Position, isKinetikVehicle, wheelCollisionGroup);
            Entity wheel3 = this.CreateCylinder(wheel3Position, isKinetikVehicle, wheelCollisionGroup);
            Entity wheel4 = this.CreateCylinder(wheel4Position, isKinetikVehicle, wheelCollisionGroup);

            // Adds to scene
            EntityManager.Add(vBody);
            EntityManager.Add(wheel1);
            EntityManager.Add(wheel2);
            EntityManager.Add(wheel3);
            EntityManager.Add(wheel4);

            // Create Joints and define Motors
            wheel1.AddComponent(new HingeJoint(vBody, wheel1Position, Vector3.Forward)
            {
                IsMotorEnabled = true, MotorVelocity = MathHelper.ToRadians(-720), MotorDamping = 1 / 500, MotorMaxForce = 500
            });
            wheel2.AddComponent(new HingeJoint(vBody, wheel2Position, Vector3.Forward)
            {
                IsMotorEnabled = true, MotorVelocity = MathHelper.ToRadians(-720), MotorDamping = 1 / 500, MotorMaxForce = 500
            });
            wheel3.AddComponent(new HingeJoint(vBody, wheel3Position, Vector3.Forward));
            wheel4.AddComponent(new HingeJoint(vBody, wheel4Position, Vector3.Forward));
        }
Exemplo n.º 26
0
        private void DefineCollisionGroups()
        {
            this.sceneGroup = new Physic3DCollisionGroup();
            this.ballGroup = new Physic3DCollisionGroup();
            this.cameraGroup = new Physic3DCollisionGroup();

            this.cameraGroup.DefineCollisionWith(this.sceneGroup);
            this.cameraGroup.IgnoreCollisionWith(this.ballGroup);
            this.ballGroup.IgnoreCollisionWith(this.sceneGroup);
            this.ballGroup.IgnoreCollisionWith(this.ballGroup);

            this.sceneGroup.DefineCollisionWith(this.cameraGroup);
            this.sceneGroup.DefineCollisionWith(this.ballGroup);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates a Cylindric Entity
        /// </summary>
        /// <param name="position">Entity Position</param>
        /// <param name="isKinematic">Is Kinematic</param>
        /// <param name="collisionGroup">Collision group</param>
        /// <returns>A Cylindical entity</returns>
        private Entity CreateCylinder(Vector3 position, bool isKinematic, Physic3DCollisionGroup collisionGroup)
        {
            Entity primitive = new Entity("cylinder" + instance++)
                .AddComponent(new Transform3D() { Position = position, Scale = new Vector3(1, 0.5f, 1), Rotation = new Vector3(MathHelper.ToRadians(90), 0, 0) })
                .AddComponent(new SphereCollider()) // We use SphereCollider with Cylinder Model.
                .AddComponent(Model.CreateCylinder())
                .AddComponent(new RigidBody3D() { IsKinematic = isKinematic, CollisionGroup = collisionGroup, KineticFriction = 10, StaticFriction = 10 })
                .AddComponent(new MaterialsMap())
                .AddComponent(new ModelRenderer());

            return primitive;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a Physical Ground
        /// </summary>
        /// <param name="position">Ground position</param>
        /// <param name="collisionGroup">Ground Collision Group</param>
        private void CreateGround(Vector3 position, Physic3DCollisionGroup collisionGroup)
        {
            Entity terrain = new Entity("terrain" + instance++)
                .AddComponent(new Transform3D() { Position = position, Scale = new Vector3(4)})
                .AddComponent(new MeshCollider())
                .AddComponent(new Model("Content/terrain.wpk"))
                .AddComponent(new RigidBody3D() { IsKinematic = true, CollisionGroup = collisionGroup, KineticFriction = 10, StaticFriction = 10 })
                .AddComponent(new MaterialsMap())
                .AddComponent(new ModelRenderer());

            EntityManager.Add(terrain);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Creates a Vehicle
        /// </summary>
        /// <param name="bodyCollisiongroup">Vehicle body collision group</param>
        /// <param name="wheelCollisionGroup">Vehicle Wheels collision group</param>
        private void CreateVehicle(Physic3DCollisionGroup bodyCollisiongroup, Physic3DCollisionGroup wheelCollisionGroup)
        {
            bool isKinetikVehicle = false;

            // Initial parts positions
            Vector3 bodyPosition = new Vector3(0, 5, 0);
            Vector3 wheel1Position = bodyPosition + new Vector3( 1, -0.3f,  0.7f);
            Vector3 wheel2Position = bodyPosition + new Vector3( 1, -0.3f, -0.7f);
            Vector3 wheel3Position = bodyPosition + new Vector3(-1, -0.3f,  0.7f);
            Vector3 wheel4Position = bodyPosition + new Vector3(-1, -0.3f, -0.7f);

            // Vehicle Parts entities
            Entity vBody = this.CreateBox(bodyPosition, bodyCollisiongroup, isKinetikVehicle);
            Entity wheel1 = this.CreateCylinder(wheel1Position, isKinetikVehicle, wheelCollisionGroup);
            Entity wheel2 = this.CreateCylinder(wheel2Position, isKinetikVehicle, wheelCollisionGroup);
            Entity wheel3 = this.CreateCylinder(wheel3Position, isKinetikVehicle, wheelCollisionGroup);
            Entity wheel4 = this.CreateCylinder(wheel4Position, isKinetikVehicle, wheelCollisionGroup);

            // Adds to scene
            EntityManager.Add(vBody);
            EntityManager.Add(wheel1);
            EntityManager.Add(wheel2);
            EntityManager.Add(wheel3);
            EntityManager.Add(wheel4);

            // Create Joints and define Motors
            wheel1.AddComponent(new HingeJoint(vBody, wheel1Position, Vector3.Forward) { IsMotorEnabled = true, MotorVelocity = MathHelper.ToRadians(-720), MotorDamping = 1/500, MotorMaxForce = 500 });
            wheel2.AddComponent(new HingeJoint(vBody, wheel2Position, Vector3.Forward) { IsMotorEnabled = true, MotorVelocity = MathHelper.ToRadians(-720), MotorDamping = 1/500, MotorMaxForce = 500 });
            wheel3.AddComponent(new HingeJoint(vBody, wheel3Position, Vector3.Forward));
            wheel4.AddComponent(new HingeJoint(vBody, wheel4Position, Vector3.Forward));
        }
Exemplo n.º 30
0
 private void AddEntityToCollisionGroup(string entityName, Physic3DCollisionGroup group)
 {
     var entity = this.EntityManager.Find(entityName);
     var rigidBody = entity.FindComponent<RigidBody3D>();
     rigidBody.CollisionGroup = group;
 }
Exemplo n.º 31
0
        protected override void CreateScene()
        {
            Physic3DCollisionGroup DiceCollisionGroup = new Physic3DCollisionGroup();
            Physic3DCollisionGroup TableCollisionGroup = new Physic3DCollisionGroup();
            TableCollisionGroup.DefineCollisionWith(DiceCollisionGroup);
            DiceCollisionGroup.DefineCollisionWith(TableCollisionGroup);

            RenderManager.DebugLines = false;

            physicsArgs = new Physic3DCollisionEventArgs();

            RenderManager.BackgroundColor = Color.CornflowerBlue;
            CameraPoint point1 = new CameraPoint();
            CameraPoint point2 = new CameraPoint();
            CameraPoint point3 = new CameraPoint();
            CameraPoint point4 = new CameraPoint();

            Entity ground = this.CreateGround();
            this.Createwalls();
            ground.FindComponent<RigidBody3D>().CollisionGroup = TableCollisionGroup;

            //var AnimationCamera = new PathCamera("AnimationCamera", new Vector3(0, 50, 80), Vector3.Zero, );
            //var beh = new PathCameraBehavior(new List<point1,point2,point3,point4>());

            //EntityManager.Add(AnimationCamera);
            PhysicsManager.Gravity3D = new Vector3(0, -9.8f, 0);

            Entity Die1 = new Entity("Die1")
                .AddComponent(new Transform3D())
                .AddComponent(new RigidBody3D()
                {
                    Restitution = GenRand(0.4, 0.7),
                    AngularVelocity = new Vector3(2.5f, 0, 0)
                })
                .AddComponent(new MeshCollider())
                .AddComponent(new Model("Content/Dice_LowPoly_OBJ.wpk"))
                .AddComponent(
                    new MaterialsMap(new BasicMaterial("Content/Red_Diffuse.wpk")
                    {
                        ReferenceAlpha = 0.5f
                    }))
                //.AddComponent(new MaterialsMap(new BasicMaterial(Color.Black)))
                .AddComponent(new ModelRenderer());
            float scale = .005f;
            Die1.FindComponent<Transform3D>().Scale.X = scale;
            Die1.FindComponent<Transform3D>().Scale.Y = scale;
            Die1.FindComponent<Transform3D>().Scale.Z = scale;
            Die1.FindComponent<Transform3D>().Position.Y = 2f;
            Die1.FindComponent<Transform3D>().Position.X = 0f;
            Die1.FindComponent<RigidBody3D>().CollisionGroup = DiceCollisionGroup;
            //Die1.FindComponent<RigidBody3D>().EnableContinuousContact = true;
            Die1.FindComponent<RigidBody3D>().LinearVelocity = new Vector3(Getrandom(), 0f, -3f);
            Die1.FindComponent<MeshCollider>().IsActive = true;
            Console.WriteLine(Die1.FindComponent<RigidBody3D>().Restitution);
            EntityManager.Add(Die1);
            Thread.Sleep(new TimeSpan(1000));

            Entity Die2 = new Entity("Die2")
                .AddComponent(new Transform3D())
                .AddComponent(new RigidBody3D() {Restitution = GenRand(0.4, 0.7)})
                .AddComponent(new MeshCollider())
                .AddComponent(new Model("Content/Dice_LowPoly_OBJ.wpk"))
                .AddComponent(
                    new MaterialsMap(new BasicMaterial("Content/White_Diffuse.wpk")
                    {
                        ReferenceAlpha = 0.5f
                    }))
                //.AddComponent(new MaterialsMap(new BasicMaterial(Color.Black)))
                .AddComponent(new ModelRenderer());
            Die2.FindComponent<Transform3D>().Scale.X = scale;
            Die2.FindComponent<Transform3D>().Scale.Y = scale;
            Die2.FindComponent<Transform3D>().Scale.Z = scale;
            Die2.FindComponent<Transform3D>().Position.Y = 2f;
            Die2.FindComponent<Transform3D>().Position.X = 1f;
            Die2.FindComponent<RigidBody3D>().LinearVelocity = new Vector3(Getrandom(), 0f, -3f);
            Die2.FindComponent<RigidBody3D>().CollisionGroup = DiceCollisionGroup;
            //Die1.FindComponent<RigidBody3D>().EnableContinuousContact = true;
            Die2.FindComponent<MeshCollider>().IsActive = true;
            Console.WriteLine(Die2.FindComponent<RigidBody3D>().Restitution);
            EntityManager.Add(Die2);

            //var mainCamera = new ViewCamera("MainCamera", new Vector3(0, 3, 0),
            //    new Vector3(Die1.FindComponent<Transform3D>().Position.X,
            //        Die1.FindComponent<Transform3D>().Position.Y, Die1.FindComponent<Transform3D>().Position.Z)); //xyz
            //EntityManager.Add(mainCamera);
            //RenderManager.SetActiveCamera(mainCamera.Entity);

            var mainCamera = new FreeCamera("MainCamera", new Vector3(-10, 3, 0), Vector3.Zero);
            // new Vector3(Die1.FindComponent<Transform3D>().Position.X,
            //Die1.FindComponent<Transform3D>().Position.Y, Die1.FindComponent<Transform3D>().Position.Z));
            EntityManager.Add(mainCamera);
            RenderManager.SetActiveCamera(mainCamera.Entity);

            //mainCamera.Entity.AddComponent(new Cam(Die1));

            this.AddSceneBehavior(new sb(), sb.Order.PostUpdate);
        }