public override void Start()
 {
     this.controllingPlayer = ((CharacterInformationComponent)Parent.GetComponent("CharacterInformationComponent")).PlayerIndex;
     this.movementComponent = (MoveComponent)Parent.GetComponent("MoveComponent");
     this.bepuPhysicsComponent = (BepuPhysicsComponent)Parent.GetComponent("BepuPhysicsComponent");
     this.health = (VitalityComponent)Parent.GetComponent("VitalityComponent");
 }
Esempio n. 2
0
            public void RecordContact <TManifold>(BepuPhysicsComponent A, BepuPhysicsComponent B, ref TManifold manifold) where TManifold : struct, IContactManifold <TManifold>
            {
                // sanity checking
                if (A == null || B == null || manifold.Count == 0)
                {
                    return;
                }

                BepuRigidbodyComponent ar = (A as BepuRigidbodyComponent);
                BepuRigidbodyComponent br = (B as BepuRigidbodyComponent);

                // do we want to store this collision?
                if ((ar?.CollectCollisions ?? false))
                {
                    int index = Interlocked.Increment(ref ar.processingPhysicalContactCount) - 1;
                    if (index < ar.CurrentPhysicalContacts.Length)
                    {
                        ar.CurrentPhysicalContacts[index].A      = A;
                        ar.CurrentPhysicalContacts[index].B      = B;
                        ar.CurrentPhysicalContacts[index].Normal = BepuHelpers.ToXenko(manifold.SimpleGetNormal());
                        ar.CurrentPhysicalContacts[index].Offset = BepuHelpers.ToXenko(manifold.SimpleGetOffset());
                    }
                }
                if ((br?.CollectCollisions ?? false))
                {
                    int index = Interlocked.Increment(ref br.processingPhysicalContactCount) - 1;
                    if (index < br.CurrentPhysicalContacts.Length)
                    {
                        br.CurrentPhysicalContacts[index].A      = B;
                        br.CurrentPhysicalContacts[index].B      = A;
                        br.CurrentPhysicalContacts[index].Normal = -BepuHelpers.ToXenko(manifold.SimpleGetNormal());
                        br.CurrentPhysicalContacts[index].Offset = B.Position - (A.Position + BepuHelpers.ToXenko(manifold.SimpleGetOffset()));
                    }
                }
            }
        public override void Start()
        {
            base.Start();

            // Get a reference to the transform component
            this.physicsComponent = (BepuPhysicsComponent)Parent.GetComponent("BepuPhysicsComponent");
        }
Esempio n. 4
0
            public bool LoopBody(CollidableReference reference)
            {
                BepuPhysicsComponent bpc = BepuSimulation.getFromReference(reference);

                if (((uint)bpc.CollisionGroup & lookingFor) != 0)
                {
                    components.Add(bpc);
                }
                return(true);
            }
Esempio n. 5
0
        public void Swap()
        {
            Normal.X = -Normal.X;
            Normal.Y = -Normal.Y;
            Normal.Z = -Normal.Z;
            Offset   = B.Position - (A.Position + Offset);
            var C = A;

            A = B;
            B = C;
        }
Esempio n. 6
0
            public bool ConfigureContactManifold(int workerIndex, CollidablePair pair, int childIndexA, int childIndexB, ref ConvexContactManifold manifold)
            {
                BepuPhysicsComponent A = getFromReference(pair.A);
                BepuPhysicsComponent B = getFromReference(pair.B);

                if (((uint)A.CanCollideWith & (uint)B.CollisionGroup) != 0)
                {
                    RecordContact(A, B, ref manifold);
                    return(!A.GhostBody && !B.GhostBody);
                }
                return(false);
            }
Esempio n. 7
0
            public unsafe bool ConfigureContactManifold <TManifold>(int workerIndex, CollidablePair pair, ref TManifold manifold, out PairMaterialProperties pairMaterial) where TManifold : struct, IContactManifold <TManifold>
            {
                BepuPhysicsComponent a = getFromReference(pair.A);
                BepuPhysicsComponent b = getFromReference(pair.B);

                pairMaterial.FrictionCoefficient              = a.FrictionCoefficient * b.FrictionCoefficient;
                pairMaterial.MaximumRecoveryVelocity          = (a.MaximumRecoveryVelocity + b.MaximumRecoveryVelocity) * 0.5f;
                pairMaterial.SpringSettings.AngularFrequency  = (a.SpringSettings.AngularFrequency + b.SpringSettings.AngularFrequency) * 0.5f;
                pairMaterial.SpringSettings.TwiceDampingRatio = (a.SpringSettings.TwiceDampingRatio + b.SpringSettings.TwiceDampingRatio) * 0.5f;
                if (((uint)a.CanCollideWith & (uint)b.CollisionGroup) != 0)
                {
                    RecordContact(a, b, ref manifold);
                    return(!a.GhostBody && !b.GhostBody);
                }
                return(false);
            }
Esempio n. 8
0
            public PhysicsElementInfo(BepuPhysicsComponent component, SkeletonUpdater skeleton)
            {
                shape = component.ColliderShape;
                var rigidbodyComponent = component as BepuRigidbodyComponent;

                isKinematic    = rigidbodyComponent != null && rigidbodyComponent.IsKinematic;
                colliderShapes = component.ColliderShapes != null?CloneDescs(component.ColliderShapes) : null;

                var componentBase = component as BepuPhysicsSkinnedComponentBase;

                boneName      = componentBase?.NodeName;
                this.skeleton = skeleton;
                boneIndex     = componentBase?.BoneIndex ?? -1;
                var triggerBase = component as BepuPhysicsTriggerComponentBase;

                isTrigger = triggerBase != null && triggerBase.IsTrigger;
            }
Esempio n. 9
0
        public Entity CreateDebugEntity(BepuPhysicsComponent component, RenderGroup renderGroup, bool alwaysAddOffset = false)
        {
            if (component?.ColliderShape == null)
            {
                return(null);
            }

            if (component.DebugEntity != null)
            {
                return(null);
            }

            var debugEntity = new Entity();

            var skinnedElement = component as BepuPhysicsSkinnedComponentBase;

            if (skinnedElement != null && skinnedElement.BoneIndex != -1)
            {
                Vector3    scale, pos;
                Quaternion rot;
                skinnedElement.BoneWorldMatrixOut.Decompose(out scale, out rot, out pos);
                debugEntity.Transform.Position = pos;
                debugEntity.Transform.Rotation = rot;
            }
            else
            {
                Vector3    scale, pos;
                Quaternion rot;
                component.Entity.Transform.WorldMatrix.Decompose(out scale, out rot, out pos);
                debugEntity.Transform.Position = pos;
                debugEntity.Transform.Rotation = rot;
            }

            var shouldNotAddOffset = component is BepuRigidbodyComponent;//|| component is BepuCharacterComponent;

            //don't add offset for non bone dynamic and kinematic as it is added already in the updates
            var colliderEntity = CreateChildEntity(component, component.ColliderShape, renderGroup, alwaysAddOffset || !shouldNotAddOffset);

            if (colliderEntity != null)
            {
                debugEntity.AddChild(colliderEntity);
            }

            return(debugEntity);
        }
Esempio n. 10
0
            public bool HasChanged(BepuPhysicsComponent component, SkeletonUpdater skeletonUpdater)
            {
                var componentBase = component as BepuPhysicsSkinnedComponentBase;
                var triggerBase   = component as BepuPhysicsTriggerComponentBase;
                var newBoneName   = componentBase?.NodeName;
                var newIndex      = componentBase?.BoneIndex ?? -1;
                var rb            = component as BepuRigidbodyComponent;

                return(shape != component.ColliderShape ||
                       (colliderShapes == null && component.ColliderShapes != null) ||
                       (colliderShapes != null && component.ColliderShapes == null) ||
                       DescsAreDifferent(colliderShapes, component.ColliderShapes) ||
                       component.ColliderShapeChanged ||
                       (rb != null && isKinematic != rb.IsKinematic) ||
                       skeleton != skeletonUpdater ||
                       boneIndex != newIndex ||
                       boneIndex == -1 && skeletonUpdater != null && !string.IsNullOrEmpty(boneName) || //force recreation if we have a skeleton?.. wrong name tho is also possible...
                       triggerBase != null && triggerBase.IsTrigger != isTrigger ||
                       shape != null && component.DebugEntity == null ||                                //force recreation in this case as well
                       boneName != newBoneName);
            }
Esempio n. 11
0
 public override void Start()
 {
     controllingPlayer = ((CharacterInformationComponent) Parent.GetComponent("CharacterInformationComponent")).PlayerIndex;
     bepuPhysicsComponent = ((BepuPhysicsComponent) Parent.GetComponent("BepuPhysicsComponent"));
 }
Esempio n. 12
0
        private Entity CreateChildEntity(BepuPhysicsComponent component, BepuColliderShape shape, RenderGroup renderGroup, bool addOffset)
        {
            if (shape == null)
            {
                return(null);
            }

            switch (shape.Type)
            {
            case ColliderShapeTypes.Compound:
            {
                var entity = new Entity();

                //We got to recurse
                var compound = (BepuCompoundColliderShape)shape;
                for (int i = 0; i < compound.Count; i++)
                {
                    var subShape  = compound[i];
                    var subEntity = CreateChildEntity(component, subShape, renderGroup, true);         //always add offsets to compounds
                    if (subEntity != null)
                    {
                        entity.AddChild(subEntity);
                    }
                }

                entity.Transform.LocalMatrix = Matrix.Identity;
                entity.Transform.UseTRS      = false;

                compound.DebugEntity = entity;

                return(entity);
            }

            case ColliderShapeTypes.Box:
            case ColliderShapeTypes.Capsule:
            case ColliderShapeTypes.ConvexHull:
            case ColliderShapeTypes.Cylinder:
            case ColliderShapeTypes.Sphere:
            case ColliderShapeTypes.Cone:
            case ColliderShapeTypes.StaticPlane:
            case ColliderShapeTypes.StaticMesh:
            case ColliderShapeTypes.Heightfield:
            {
                IDebugPrimitive debugPrimitive;
                var             type = shape.GetType();
                //if (type == typeof(BepuHeightfieldColliderShape))
                //{
                //    if (!updatableDebugMeshCache.TryGetValue(shape, out debugPrimitive))
                //    {
                //        debugPrimitive = shape.CreateUpdatableDebugPrimitive(graphicsDevice);
                //        updatableDebugMeshCache[shape] = debugPrimitive;
                //    }
                //    if (!updatableDebugMeshes.ContainsKey(shape))
                //    {
                //        updatableDebugMeshes.Add(shape, debugPrimitive);
                //    }
                //}
                //else
                if (type == typeof(BepuCapsuleColliderShape) ||
                    type == typeof(BepuConvexHullColliderShape)
                    //|| type == typeof(BepuStaticMeshColliderShape)
                    )
                {
                    if (!debugMeshCache2.TryGetValue(shape, out debugPrimitive))
                    {
                        debugPrimitive = new DebugPrimitive {
                            shape.CreateDebugPrimitive(graphicsDevice)
                        };
                        debugMeshCache2[shape] = debugPrimitive;
                    }
                }
                else
                {
                    if (!debugMeshCache.TryGetValue(shape.GetType(), out debugPrimitive))
                    {
                        debugPrimitive = new DebugPrimitive {
                            shape.CreateDebugPrimitive(graphicsDevice)
                        };
                        debugMeshCache[shape.GetType()] = debugPrimitive;
                    }
                }

                var model = new Model
                {
                    GetMaterial(component, shape),
                };
                foreach (var meshDraw in debugPrimitive.GetMeshDraws())
                {
                    model.Add(new Mesh {
                            Draw = meshDraw
                        });
                }

                var entity = new Entity
                {
                    new ModelComponent
                    {
                        Model       = model,
                        RenderGroup = renderGroup,
                    },
                };

                var offset = addOffset ? Matrix.RotationQuaternion(shape.LocalRotation) * Matrix.Translation(shape.LocalOffset) : Matrix.Identity;

                entity.Transform.LocalMatrix = shape.DebugPrimitiveMatrix * offset * Matrix.Scaling(shape.Scaling);

                entity.Transform.UseTRS = false;

                shape.DebugEntity = entity;

                return(entity);
            }

            default:
                return(null);
            }
        }
 public override void Start()
 {
     this.bepuPhysicsComponent = (BepuPhysicsComponent)Parent.GetComponent("BepuPhysicsComponent");
 }
 public override void Start()
 {
     vitalityComponent = (VitalityComponent)Parent.GetComponent("VitalityComponent");
     bepuPhysicsComponent = (BepuPhysicsComponent)Parent.GetComponent("BepuPhysicsComponent");
     cubeRenderComponent = (BasicModelComponent)Parent.GetComponent("BasicModelComponent");
 }