Example #1
0
        /// <summary>
        /// Create a physics component.
        /// </summary>
        public PhysicsComponent(BaseEntity parent, PhysicsComponentDefinition compDef)
            : base(parent)
        {
            if ((null != compDef.PhysicsModelPath) && (compDef.PhysicsModelPath.Length > 0))
            {
                this.physMesh = this.parentEntity.Game.ModelLoader.LoadStaticModel(compDef.PhysicsModelPath);
            }

            this.shapeType          = compDef.ShapeType;
            this.mass               = compDef.Mass;
            this.collisionGroupType = compDef.CollisionGroupType;
            this.isDynamic          = compDef.IsDynamic;
            this.affectedByGravity  = compDef.AffectedByGravity;

            this.height   = compDef.Height;
            this.width    = compDef.Width;
            this.depth    = compDef.Depth;
            this.diameter = compDef.Diameter;

            InitializeActor();

            if (this.shapeType != ShapeType.TriangleMesh &&
                this.shapeType != ShapeType.Heightfield &&
                this.isDynamic)
            {
                ActivateComponent();
            }
        }
Example #2
0
        public static BaseComponent LoadFromDefinition(ContentManager content, string definitionPath, BaseEntity parent)
        {
            PhysicsComponentDefinition compDef = content.Load <PhysicsComponentDefinition>(definitionPath);

            PhysicsComponent newComponent = new PhysicsComponent(parent, compDef);

            return(newComponent);
        }
Example #3
0
        public WaterVolumePhysicsComponent(BaseEntity parent, PhysicsComponentDefinition compDef)
            : base(parent)
        {
            var waterComp = this.parentEntity.GetComponentByType(ComponentType.WaterComponent) as WaterComponent;

            if (null == waterComp)
            {
                throw new Exception("Water Component must be added to an entity prior to WaterVolumePhysicsComponent. Make sure in the EntityDefinition XML file that WaterComponent comes first.");
            }

            this.entitiesInWater = new Dictionary <Int64, Vector3>();
            this.dirtyValues     = new Dictionary <Int64, Vector3>();

            this.updatesEntityPosition = false;

            this.shapeType          = ShapeType.Box;
            this.mass               = 1.0f;
            this.collisionGroupType = compDef.CollisionGroupType;
            this.isDynamic          = false;

            this.height = compDef.Height;
            this.width  = waterComp.Width;
            this.depth  = waterComp.Length;

            var getPhysSceneMsg = ObjectPool.Aquire <MsgGetPhysicsScene>();

            getPhysSceneMsg.UniqueTarget = this.parentEntity.UniqueID;
            this.parentEntity.Game.SendInterfaceMessage(getPhysSceneMsg, InterfaceType.Physics);

            IPhysicsScene physScene = getPhysSceneMsg.PhysicsScene;

            if (physScene != null)
            {
                CreateActor(physScene);

                if (this.actor != null)
                {
                    var setCollGroup = ObjectPool.Aquire <MsgSetActorToCollisionGroup>();
                    setCollGroup.Actor     = this.actor;
                    setCollGroup.GroupType = this.collisionGroupType;
                    this.parentEntity.Game.SendInterfaceMessage(setCollGroup, InterfaceType.Physics);

                    var addToSceneMsg = ObjectPool.Aquire <MsgAddEntityToPhysicsScene>();
                    addToSceneMsg.Actor    = this.actor;
                    addToSceneMsg.EntityID = this.parentEntity.UniqueID;
                    this.parentEntity.Game.SendInterfaceMessage(addToSceneMsg, InterfaceType.Physics);
                }
            }

            ActivateComponent();
        }
Example #4
0
 public PhantomPhysicsComponent(BaseEntity parent, PhysicsComponentDefinition compDef)
     : base(parent, compDef)
 {
     ActivateComponent();
 }