コード例 #1
0
 public BSConstraintHinge(BulletWorld world, BulletBody obj1, BulletBody obj2,
                 Vector3 pivotInA, Vector3 pivotInB,
                 Vector3 axisInA, Vector3 axisInB,
                 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2,
                             pivotInA, pivotInB, axisInA, axisInB,
                             useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
 }
コード例 #2
0
 public BSConstraintConeTwist(BulletWorld world, BulletBody obj1, BulletBody obj2,
                 Vector3 frameInAloc, Quaternion frameInArot,
                 Vector3 frameInBloc, Quaternion frameInBrot,
                 bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.CreateConeTwistConstraint(world, obj1, obj2,
                             frameInAloc, frameInArot, frameInBloc, frameInBrot,
                             disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
 }
コード例 #3
0
 public BSConstraintSlider(BulletWorld world, BulletBody obj1, BulletBody obj2,
                 Vector3 frameInAloc, Quaternion frameInArot,
                 Vector3 frameInBloc, Quaternion frameInBrot,
                 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.CreateSliderConstraint(world, obj1, obj2,
                             frameInAloc, frameInArot, frameInBloc, frameInBrot,
                             useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
 }
コード例 #4
0
    public BSConstraintSpring(BulletWorld world, BulletBody obj1, BulletBody obj2,
                    Vector3 frame1Loc, Quaternion frame1Rot,
                    Vector3 frame2Loc, Quaternion frame2Rot,
                    bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
        :base(world, obj1, obj2)
    {
        m_constraint = PhysicsScene.PE.Create6DofSpringConstraint(world, obj1, obj2,
                                frame1Loc, frame1Rot, frame2Loc, frame2Rot,
                                useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
        m_enabled = true;

        PhysicsScene.DetailLog("{0},BSConstraintSpring,create,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                            obj1.ID, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
        PhysicsScene.DetailLog("{0},BSConstraintSpring,create,  f1Loc={1},f1Rot={2},f2Loc={3},f2Rot={4},usefA={5},disCol={6}",
                    m_body1.ID, frame1Loc, frame1Rot, frame2Loc, frame2Rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
    }
コード例 #5
0
ファイル: BSPhysObject.cs プロジェクト: Gitlab11/opensim
    protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
    {
        IsInitialized = false;

        PhysScene = parentScene;
        LocalID = localID;
        PhysObjectName = name;
        Name = name;    // PhysicsActor also has the name of the object. Someday consolidate.
        TypeName = typeName;

        // Oddity if object is destroyed and recreated very quickly it could still have the old body.
        if (!PhysBody.HasPhysicalBody)
            PhysBody = new BulletBody(localID);

        // Clean out anything that might be in the physical actor list.
        // Again, a workaround for destroying and recreating an object very quickly.
        PhysicalActors.Dispose();

        UserSetCenterOfMassDisplacement = null;

        PrimAssetState = PrimAssetCondition.Unknown;

        // Initialize variables kept in base.
        // Beware that these cause taints to be queued whch can cause race conditions on startup.
        GravModifier = 1.0f;
        Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
        HoverActive = false;

        // Default material type. Also sets Friction, Restitution and Density.
        SetMaterial((int)MaterialAttributes.Material.Wood);

        CollisionsLastTickStep = -1;

        SubscribedEventsMs = 0;
        // Crazy values that will never be true
        CollidingStep = BSScene.NotASimulationStep;
        CollidingGroundStep = BSScene.NotASimulationStep;
        CollisionAccumulation = BSScene.NotASimulationStep;
        ColliderIsMoving = false;
        CollisionScore = 0;

        // All axis free.
        LockedLinearAxis = LockedAxisFree;
        LockedAngularAxis = LockedAxisFree;
    }
コード例 #6
0
    // 6 Dof constraint based on a midpoint between the two constrained bodies
    public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
                    Vector3 joinPoint,
                    bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
        : base(world)
    {
        m_body1 = obj1;
        m_body2 = obj2;
        if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody)
        {
            world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                            BSScene.DetailLogZero, world.worldID,
                            obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
            world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                            LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
            m_enabled = false;
        }
        else
        {
            m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2,
                                    joinPoint,
                                    useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);

            PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
                                m_body1.ID, world.worldID, m_constraint.AddrString,
                                obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);

            if (!m_constraint.HasPhysicalConstraint)
            {
                world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}",
                                LogHeader, obj1.ID, obj2.ID);
                m_enabled = false;
            }
            else
            {
                m_enabled = true;
            }
        }
    }
コード例 #7
0
    // Get the constraint between two bodies. There can be only one.
    // Return 'true' if a constraint was found.
    public bool TryGetConstraint(BulletBody body1, BulletBody body2, out BSConstraint returnConstraint)
    {
        bool found = false;
        BSConstraint foundConstraint = null;

        uint lookingID1 = body1.ID;
        uint lookingID2 = body2.ID;
        lock (m_constraints)
        {
            foreach (BSConstraint constrain in m_constraints)
            {
                if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2)
                    || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1))
                {
                    foundConstraint = constrain;
                    found = true;
                    break;
                }
            }
        }
        returnConstraint = foundConstraint;
        return found;
    }
コード例 #8
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 //BulletSimAPI.GetCollisionFlags(PhysBody.ptr)
 public override CollisionFlags GetCollisionFlags(BulletBody pCollisionObject)
 {
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody;
     uint flags = (uint)collisionObject.GetCollisionFlags();
     return (CollisionFlags) flags;
 }
コード例 #9
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
    //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping);
    public override void SetAngularDamping(BulletBody pBody, float angularDamping)
    {
        RigidBody body = (pBody as BulletBodyXNA).rigidBody;
        float lineardamping = body.GetLinearDamping();
        body.SetDamping(lineardamping, angularDamping);

    }
コード例 #10
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override int GetNumConstraintRefs(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     return body.GetNumConstraintRefs();
 }
コード例 #11
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void RemoveConstraintRef(BulletBody pBody, BulletConstraint pConstraint)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     TypedConstraint constrain = (pConstraint as BulletConstraintXNA).constrain;
     body.RemoveConstraintRef(constrain);
 }
コード例 #12
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override Vector3 GetAngularFactor(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 iv3 =  body.GetAngularFactor();
     return new Vector3(iv3.X, iv3.Y, iv3.Z);
 }
コード例 #13
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override bool WantsSleeping(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     return body.WantsSleeping();
 }
コード例 #14
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void Translate(BulletBody pCollisionObject, Vector3 trans)
 {
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody;
     collisionObject.Translate(new IndexedVector3(trans.X,trans.Y,trans.Z));
 }
コード例 #15
0
 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2) : base(world)
 {
     m_body1   = obj1;
     m_body2   = obj2;
     m_enabled = false;
 }
コード例 #16
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override Vector3 GetVelocityInLocalPoint(BulletBody pBody, Vector3 pos)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z);
     IndexedVector3 iv3 = body.GetVelocityInLocalPoint(ref posiv3);
     return new Vector3(iv3.X, iv3.Y, iv3.Z);
 }
コード例 #17
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override float GetCcdMotionThreshold(BulletBody pCollisionObject)
 {
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody;
     return collisionObject.GetCcdSquareMotionThreshold();
 }
コード例 #18
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void UpdateDeactivation(BulletBody pBody, float timeStep)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     body.UpdateDeactivation(timeStep);
 }
コード例 #19
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
    public override float GetCcdSweptSphereRadius(BulletBody pCollisionObject)
    {
        CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody;
        return collisionObject.GetCcdSweptSphereRadius();

    }
コード例 #20
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void SetAngularFactor(BulletBody pBody, float factor)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     body.SetAngularFactor(factor);
 }
コード例 #21
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override IntPtr GetUserPointer(BulletBody pCollisionObject)
 {
     CollisionObject shape = (pCollisionObject as BulletBodyXNA).body;
     return (IntPtr)shape.GetUserPointer();
 }
コード例 #22
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override bool IsInWorld(BulletWorld pWorld, BulletBody pCollisionObject)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     return world.IsInWorld(collisionObject);
 }
コード例 #23
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void SetUserPointer(BulletBody pCollisionObject, IntPtr val)
 {
     CollisionObject shape = (pCollisionObject as BulletBodyXNA).body;
     shape.SetUserPointer(val);
 }
コード例 #24
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override BulletConstraint GetConstraintRef(BulletBody pBody, int index)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     return new BulletConstraintXNA(body.GetConstraintRef(index));
 }
コード例 #25
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void SetGravity(BulletBody pBody, Vector3 pGravity)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     if (body != null) // Can't set collisionobject.set gravity
     {
         IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z);
         body.SetGravity(gravity);
     }
 }
コード例 #26
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void SetInterpolationLinearVelocity(BulletBody pCollisionObject, Vector3 VehicleVelocity)
 {
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody;
     IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z);
     collisionObject.SetInterpolationLinearVelocity(ref velocity);
 }
コード例 #27
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
    public override BulletConstraint Create6DofConstraintFixed(BulletWorld pWorld, BulletBody pBody1,
                                        Vector3 pframe1, Quaternion pframe1rot,
                                        bool pUseLinearReferenceFrameB, bool pdisableCollisionsBetweenLinkedBodies)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody;
        IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
        IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
        IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
        frame1._origin = frame1v;

        Generic6DofConstraint consttr = new Generic6DofConstraint(body1, ref frame1, pUseLinearReferenceFrameB);
        consttr.CalculateTransforms();
        world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies);

        return new BulletConstraintXNA(consttr);
    }
コード例 #28
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override void UpdateInertiaTensor(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     if (body != null)  // can't update inertia tensor on CollisionObject
         body.UpdateInertiaTensor();
 }
コード例 #29
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
    /// <summary>
    ///
    /// </summary>
    /// <param name="pWorld"></param>
    /// <param name="pBody1"></param>
    /// <param name="pBody2"></param>
    /// <param name="pjoinPoint"></param>
    /// <param name="puseLinearReferenceFrameA"></param>
    /// <param name="pdisableCollisionsBetweenLinkedBodies"></param>
    /// <returns></returns>
    public override BulletConstraint Create6DofConstraintToPoint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody;
        RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody;
        IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
        IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));

        IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
        IndexedMatrix mat = IndexedMatrix.Identity;
        mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
        frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint;
        frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint;

        Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
        consttr.CalculateTransforms();
        world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies);

        return new BulletConstraintXNA(consttr);
    }
コード例 #30
0
ファイル: BSTerrainMesh.cs プロジェクト: CassieEllen/opensim
    // 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);
    }
コード例 #31
0
ファイル: BSAPIXNA.cs プロジェクト: CassieEllen/opensim
 public override Vector3 GetLinearVelocity(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 iv3 = body.GetLinearVelocity();
     return new Vector3(iv3.X, iv3.Y, iv3.Z);
 }