Beispiel #1
0
 public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape)
 {
     CompoundShape shape = (pCompoundShape as BulletShapeXNA).shape as CompoundShape;
     shape.RecalculateLocalAabb();
 }
Beispiel #2
0
 public override float GetMargin(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.GetMargin();
 }
Beispiel #3
0
 public override Vector3 GetLocalScaling(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     IndexedVector3 scale = shape.GetLocalScaling();
     return new Vector3(scale.X,scale.Y,scale.Z);
 }
Beispiel #4
0
 public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms)
 {
     /* TODO */ return null;
 }
Beispiel #5
0
 public override int GetShapeType(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return (int)shape.GetShapeType();
 }
Beispiel #6
0
 public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape pCShape, int pii)
 {
     CompoundShape compoundshape = (pCShape as BulletShapeXNA).shape as CompoundShape;
     CollisionShape ret = null;
     ret = compoundshape.GetChildShape(pii);
     compoundshape.RemoveChildShapeByIndex(pii);
     return new BulletShapeXNA(ret, BSShapeTypeFromBroadPhaseNativeType(ret.GetShapeType()));
 }
Beispiel #7
0
 public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) { /* TODO */ }
Beispiel #8
0
 public override float GetContactBreakingThreshold(BulletShape pShape, float defaultFactor)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.GetContactBreakingThreshold(defaultFactor);
 }
Beispiel #9
0
 public override bool IsSoftBody(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.IsSoftBody();
 }
Beispiel #10
0
    public override BulletBody CreateBodyWithDefaultMotionState( BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
    {

        IndexedMatrix mat =
            IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
                                                                     pRawOrientation.Z, pRawOrientation.W));
        mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);

        CollisionShape shape = (pShape as BulletShapeXNA).shape;

        // TODO: Feed Update array into null
        RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
        body.SetWorldTransform(mat);
        body.SetUserPointer(pLocalID);
        return new BulletBodyXNA(pLocalID, body);
    }
Beispiel #11
0
 public override float GetAngularMotionDisc(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.GetAngularMotionDisc();
 }
Beispiel #12
0
    //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation);

    public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
    {
        CollisionWorld world = (pWorld as BulletWorldXNA).world;
        IndexedMatrix mat =
            IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
                                                                     pRawOrientation.Z, pRawOrientation.W));
        mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
        CollisionShape shape = (pShape as BulletShapeXNA).shape;
        //UpdateSingleAabb(world, shape);
        // TODO: Feed Update array into null
        SimMotionState motionState = new SimMotionState(this, pLocalID, mat, null);
        RigidBody body = new RigidBody(0,motionState,shape,IndexedVector3.Zero);
        RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(0, motionState, shape, IndexedVector3.Zero)
                                                         {
                                                             m_mass = 0
                                                         };
        /*
            m_mass = mass;
			m_motionState =motionState;
			m_collisionShape = collisionShape;
			m_localInertia = localInertia;
			m_linearDamping = 0f;
			m_angularDamping = 0f;
			m_friction = 0.5f;
			m_restitution = 0f;
			m_linearSleepingThreshold = 0.8f;
			m_angularSleepingThreshold = 1f;
			m_additionalDamping = false;
			m_additionalDampingFactor = 0.005f;
			m_additionalLinearDampingThresholdSqr = 0.01f;
			m_additionalAngularDampingThresholdSqr = 0.01f;
			m_additionalAngularDampingFactor = 0.01f;
            m_startWorldTransform = IndexedMatrix.Identity;
        */
        body.SetUserPointer(pLocalID);

        return new BulletBodyXNA(pLocalID, body);
    }
Beispiel #13
0
 public override bool DeleteCollisionShape(BulletWorld pWorld, BulletShape pShape)
 {
     //TODO:
     return false;
 }
Beispiel #14
0
    public override BulletShape DuplicateCollisionShape(BulletWorld pWorld, BulletShape pShape, uint id)
    {
        CollisionShape shape1 = (pShape as BulletShapeXNA).shape;

        // TODO:  Turn this from a reference copy to a Value Copy.
        BulletShapeXNA shape2 = new BulletShapeXNA(shape1, BSShapeTypeFromBroadPhaseNativeType(shape1.GetShapeType()));

        return shape2;
    }
 // Return 'true' if this and other refer to the same physical object
 public virtual bool ReferenceSame(BulletShape xx)
 {
     return(false);
 }
Beispiel #16
0
 public override bool IsPolyhedral(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.IsPolyhedral();
 }
Beispiel #17
0
    //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot
    public override void AddChildShapeToCompoundShape(BulletShape pCShape, BulletShape paddShape, Vector3 displacementPos, Quaternion displacementRot)
    {
        IndexedMatrix relativeTransform = new IndexedMatrix();
        CompoundShape compoundshape = (pCShape as BulletShapeXNA).shape as CompoundShape;
        CollisionShape addshape = (paddShape as BulletShapeXNA).shape;

        relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z);
        relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W));
        compoundshape.AddChildShape(ref relativeTransform, addshape);

    }
Beispiel #18
0
 public override bool IsConvex(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.IsConvex();
 }
Beispiel #19
0
    public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) {

        if (cShape == null)
            return null;
        CompoundShape compoundShape = (cShape as BulletShapeXNA).shape as CompoundShape;
        CollisionShape shape = compoundShape.GetChildShape(indx);
        BulletShape retShape = new BulletShapeXNA(shape, BSShapeTypeFromBroadPhaseNativeType(shape.GetShapeType()));


        return retShape;
    }
Beispiel #20
0
 public override bool IsNonMoving(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.IsNonMoving();
 }
Beispiel #21
0
 public override void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb) { /* TODO */ }
Beispiel #22
0
 public override bool IsInfinite(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     return shape.IsInfinite();
 }
Beispiel #23
0
 public override BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
 {
     /* TODO */ return null;
 }
Beispiel #24
0
 public override bool IsNativeShape(BulletShape pShape)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     bool ret;
     switch (shape.GetShapeType())
     {
         case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
             case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
             case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
             case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
             ret = true;
             break;
         default:
             ret = false;
             break;
     }
     return ret;
 }
Beispiel #25
0
 public override void SetMargin(BulletShape pShape, float pMargin)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     shape.SetMargin(pMargin);
 }
Beispiel #26
0
    //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation
    public override BulletBody CreateGhostFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        IndexedMatrix bodyTransform = new IndexedMatrix();
        bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
        bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W));
        GhostObject gObj = new PairCachingGhostObject();
        gObj.SetWorldTransform(bodyTransform);
        CollisionShape shape = (pShape as BulletShapeXNA).shape;
        gObj.SetCollisionShape(shape);
        gObj.SetUserPointer(pLocalID);

        if (specialCollisionObjects.ContainsKey(pLocalID))
            specialCollisionObjects[pLocalID] = gObj;
        else
            specialCollisionObjects.Add(pLocalID, gObj);

        // TODO: Add to Special CollisionObjects!
        return new BulletBodyXNA(pLocalID, gObj);
    }
Beispiel #27
0
    public override void SetLocalScaling(BulletShape pShape, Vector3 pScale)
    {
        CollisionShape shape = (pShape as BulletShapeXNA).shape;
        IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
        shape.SetLocalScaling(ref vec);

    }
Beispiel #28
0
 public override void SetCollisionShape(BulletWorld pWorld, BulletBody pCollisionObject, BulletShape pShape)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     if (pShape == null)
     {
         collisionObject.SetCollisionShape(new EmptyShape());
     }
     else
     {
         CollisionShape shape = (pShape as BulletShapeXNA).shape;
         collisionObject.SetCollisionShape(shape);
     }
 }
Beispiel #29
0
 public override Vector3 CalculateLocalInertia(BulletShape pShape, float pphysMass)
 {
     CollisionShape shape = (pShape as BulletShapeXNA).shape;
     IndexedVector3 inertia = IndexedVector3.Zero;
     shape.CalculateLocalInertia(pphysMass, out inertia);
     return new Vector3(inertia.X, inertia.Y, inertia.Z);
 }
Beispiel #30
0
 public override int GetNumberOfCompoundChildren(BulletShape pCompoundShape)
 {
     CompoundShape compoundshape = (pCompoundShape as BulletShapeXNA).shape as CompoundShape;
     return compoundshape.GetNumChildShapes();
 }
Beispiel #31
0
    // Create terrain mesh from a heightmap.
    public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap,
                                                    Vector3 minCoords, Vector3 maxCoords)
        : base(physicsScene, regionBase, id)
    {
        int indicesCount;
        int[] indices;
        int verticesCount;
        float[] vertices;

        m_savedHeightMap = initialMap;

        m_sizeX = (int)(maxCoords.X - minCoords.X);
        m_sizeY = (int)(maxCoords.Y - minCoords.Y);

        bool meshCreationSuccess = false;
        if (BSParam.TerrainMeshMagnification == 1)
        {
            // If a magnification of one, use the old routine that is tried and true.
            meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh(m_physicsScene,
                                            initialMap, m_sizeX, m_sizeY,       // input size
                                            Vector3.Zero,                       // base for mesh
                                            out indicesCount, out indices, out verticesCount, out vertices);
        }
        else
        {
            // Other magnifications use the newer routine
            meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh2(m_physicsScene,
                                            initialMap, m_sizeX, m_sizeY,       // input size
                                            BSParam.TerrainMeshMagnification,
                                            physicsScene.TerrainManager.DefaultRegionSize,
                                            Vector3.Zero,                       // base for mesh
                                            out indicesCount, out indices, out verticesCount, out vertices);
        }
        if (!meshCreationSuccess)
        {
            // DISASTER!!
            m_physicsScene.DetailLog("{0},BSTerrainMesh.create,failedConversionOfHeightmap,id={1}", BSScene.DetailLogZero, ID);
            m_physicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh! base={1}", LogHeader, TerrainBase);
            // Something is very messed up and a crash is in our future.
            return;
        }

        m_physicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,id={1},indices={2},indSz={3},vertices={4},vertSz={5}",
                                BSScene.DetailLogZero, ID, indicesCount, indices.Length, verticesCount, vertices.Length);

        m_terrainShape = m_physicsScene.PE.CreateMeshShape(m_physicsScene.World, indicesCount, indices, verticesCount, vertices);
        if (!m_terrainShape.HasPhysicalShape)
        {
            // DISASTER!!
            m_physicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape,id={1}", BSScene.DetailLogZero, ID);
            m_physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain mesh! base={1}", LogHeader, TerrainBase);
            // Something is very messed up and a crash is in our future.
            return;
        }

        Vector3 pos = regionBase;
        Quaternion rot = Quaternion.Identity;

        m_terrainBody = m_physicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot);
        if (!m_terrainBody.HasPhysicalBody)
        {
            // DISASTER!!
            m_physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase);
            // Something is very messed up and a crash is in our future.
            return;
        }
        physicsScene.PE.SetShapeCollisionMargin(m_terrainShape, BSParam.TerrainCollisionMargin);

        // Set current terrain attributes
        m_physicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction);
        m_physicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction);
        m_physicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution);
        m_physicsScene.PE.SetContactProcessingThreshold(m_terrainBody, BSParam.TerrainContactProcessingThreshold);
        m_physicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT);

        // Static objects are not very massive.
        m_physicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero);

        // Put the new terrain to the world of physical objects
        m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_terrainBody);

        // Redo its bounding box now that it is in the world
        m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_terrainBody);

        m_terrainBody.collisionType = CollisionType.Terrain;
        m_terrainBody.ApplyCollisionMask(m_physicsScene);

        if (BSParam.UseSingleSidedMeshes)
        {
            m_physicsScene.DetailLog("{0},BSTerrainMesh.settingCustomMaterial,id={1}", BSScene.DetailLogZero, id);
            m_physicsScene.PE.AddToCollisionFlags(m_terrainBody, CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
        }

        // Make it so the terrain will not move or be considered for movement.
        m_physicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION);
    }
Beispiel #32
0
        // 'physicalUpdate' is true if these changes came directly from the physics engine. Don't need to rebuild then.
        // Called at taint-time.
        public override void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable updated)
        {
            if (!LinksetRoot.IsPhysicallyActive)
            {
                // No reason to do this physical stuff for static linksets.
                DetailLog("{0},BSLinksetCompound.UpdateProperties,notPhysical", LinksetRoot.LocalID);
                return;
            }

            // The user moving a child around requires the rebuilding of the linkset compound shape
            // One problem is this happens when a border is crossed -- the simulator implementation
            //    stores the position into the group which causes the move of the object
            //    but it also means all the child positions get updated.
            //    What would cause an unnecessary rebuild so we make sure the linkset is in a
            //    region before bothering to do a rebuild.
            if (!IsRoot(updated) && m_physicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition))
            {
                // If a child of the linkset is updating only the position or rotation, that can be done
                //    without rebuilding the linkset.
                // If a handle for the child can be fetch, we update the child here. If a rebuild was
                //    scheduled by someone else, the rebuild will just replace this setting.

                bool updatedChild = false;
                // Anything other than updating position or orientation usually means a physical update
                //     and that is caused by us updating the object.
                if ((whichUpdated & ~(UpdatedProperties.Position | UpdatedProperties.Orientation)) == 0)
                {
                    // Find the physical instance of the child
                    if (!RebuildScheduled &&                      // if rebuilding, let the rebuild do it
                        !LinksetRoot.IsIncomplete &&              // if waiting for assets or whatever, don't change
                        LinksetRoot.PhysShape.HasPhysicalShape && // there must be a physical shape assigned
                        m_physicsScene.PE.IsCompound(LinksetRoot.PhysShape.physShapeInfo))
                    {
                        // It is possible that the linkset is still under construction and the child is not yet
                        //    inserted into the compound shape. A rebuild of the linkset in a pre-step action will
                        //    build the whole thing with the new position or rotation.
                        // The index must be checked because Bullet references the child array but does no validity
                        //    checking of the child index passed.
                        int numLinksetChildren = m_physicsScene.PE.GetNumberOfCompoundChildren(LinksetRoot.PhysShape.physShapeInfo);
                        if (updated.LinksetChildIndex < numLinksetChildren)
                        {
                            BulletShape linksetChildShape = m_physicsScene.PE.GetChildShapeFromCompoundShapeIndex(LinksetRoot.PhysShape.physShapeInfo, updated.LinksetChildIndex);
                            if (linksetChildShape.HasPhysicalShape)
                            {
                                // Found the child shape within the compound shape
                                m_physicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape.physShapeInfo, updated.LinksetChildIndex,
                                                                       updated.RawPosition - LinksetRoot.RawPosition,
                                                                       updated.RawOrientation * OMV.Quaternion.Inverse(LinksetRoot.RawOrientation),
                                                                       true /* shouldRecalculateLocalAabb */);
                                updatedChild = true;
                                DetailLog("{0},BSLinksetCompound.UpdateProperties,changeChildPosRot,whichUpdated={1},pos={2},rot={3}",
                                          updated.LocalID, whichUpdated, updated.RawPosition, updated.RawOrientation);
                            }
                            else // DEBUG DEBUG
                            {   // DEBUG DEBUG
                                DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,noChildShape,shape={1}",
                                          updated.LocalID, linksetChildShape);
                            }   // DEBUG DEBUG
                        }
                        else // DEBUG DEBUG
                        {   // DEBUG DEBUG
                            // the child is not yet in the compound shape. This is non-fatal.
                            DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,childNotInCompoundShape,numChildren={1},index={2}",
                                      updated.LocalID, numLinksetChildren, updated.LinksetChildIndex);
                        }   // DEBUG DEBUG
                    }
                    else // DEBUG DEBUG
                    {   // DEBUG DEBUG
                        DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,noBodyOrNotCompound", updated.LocalID);
                    }   // DEBUG DEBUG

                    if (!updatedChild)
                    {
                        // If couldn't do the individual child, the linkset needs a rebuild to incorporate the new child info.
                        // Note: there are several ways through this code that will not update the child if
                        //    the linkset is being rebuilt. In this case, scheduling a rebuild is a NOOP since
                        //    there will already be a rebuild scheduled.
                        DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild.schedulingRebuild,whichUpdated={1}",
                                  updated.LocalID, whichUpdated);
                        Refresh(updated);
                    }
                }
            }
        }