BEPUphysics.CollisionShapes.CompoundShape.GetCollidableInstance C# (CSharp) Метод

GetCollidableInstance() публичный Метод

Retrieves an instance of an EntityCollidable that uses this EntityShape. Mainly used by compound bodies.
public GetCollidableInstance ( ) : EntityCollidable
Результат BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable
        public override EntityCollidable GetCollidableInstance()
        {
            return new CompoundCollidable(this);
        }

Usage Example

Пример #1
0
        public override void updatePhysics()
        {
            foreach (Chunk chunk in this.Chunks)
                chunk.Activate();

            bool hasVolume = false;
            List<CompoundShapeEntry> bodies = new List<CompoundShapeEntry>();
            float mass = 0.0f;
            float volume = 0.0f;
            foreach (Box box in this.Chunks.SelectMany(x => x.Boxes))
            {
                if (!box.Type.Fake)
                {
                    bodies.Add(box.GetCompoundShapeEntry());
                    float v = box.Width * box.Height * box.Depth;
                    volume += v;
                    mass += v * box.Type.Density;
                }
            }

            if (bodies.Count > 0)
            {
                Vector3 c;
                CompoundShape shape = new CompoundShape(bodies, out c);
                this.PhysicsEntity.Position += Vector3.TransformNormal(c - this.Offset.Value, this.Transform);
                this.Offset.Value = c;
                if (!this.main.EditorEnabled && this.EnablePhysics)
                {
                    hasVolume = true;
                    EntityCollidable collisionInfo = shape.GetCollidableInstance();
                    collisionInfo.Events.ContactCreated += new BEPUphysics.BroadPhaseEntries.Events.ContactCreatedEventHandler<BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable>(Events_ContactCreated);
                    collisionInfo.Tag = this;
                    this.PhysicsEntity.SetCollisionInformation(collisionInfo, mass);
                    // TODO: figure out how to manually override volume in new BEPUphysics
                    //this.PhysicsEntity.Volume = volume;
                    this.PhysicsEntity.ActivityInformation.Activate();
                }
            }

            if (!this.addedToSpace && hasVolume && !this.Suspended && !this.main.EditorEnabled)
            {
                this.main.Space.SpaceObjectBuffer.Add(this.PhysicsEntity);
                this.addedToSpace = true;
            }
            else if (this.addedToSpace && this.PhysicsEntity.Space != null && !hasVolume)
            {
                this.main.Space.SpaceObjectBuffer.Remove(this.PhysicsEntity);
                this.addedToSpace = false;
            }

            if (this.firstPhysicsUpdate)
                this.firstPhysicsUpdate = false;
            else
            {
                lock (this.physicsLock)
                    this.physicsUpdated = true;
            }
        }