コード例 #1
0
        public void setMotionState(btMotionState motionState)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException(ToString());
            }

            BulletAPI_BtRigidBody_setMotionState(m_handle, motionState.Handle);
        }
コード例 #2
0
 public btRigidBody(float mass, btMotionState motionState, btCollisionShape collisionShape, btVector3 localInertia)
 {
     m_constructionInfo = new btRigidBodyConstructionInfo();
     m_constructionInfo.m_collisionShape      = collisionShape;
     m_constructionInfo.m_localInertia        = localInertia;
     m_constructionInfo.m_motionState         = motionState;
     m_constructionInfo.m_startWorldTransform = btTransform.getIdentity();
     m_constructionInfo.SetGenericDefaultValues();
     m_constructionInfo.m_mass = mass;
     m_constructionInfo.commit();
     m_handle = BulletAPI_CreateBtRigidBody(m_constructionInfo.Handle);
 }
コード例 #3
0
ファイル: btRigidBody.cs プロジェクト: Belxjander/Asuna
 public btRigidBody(float mass, btMotionState motionState, btCollisionShape collisionShape, btVector3 localInertia)
 {
     
     m_constructionInfo = new btRigidBodyConstructionInfo();
     m_constructionInfo.m_collisionShape = collisionShape;
     m_constructionInfo.m_localInertia = localInertia;
     m_constructionInfo.m_motionState = motionState;
     m_constructionInfo.m_startWorldTransform = btTransform.getIdentity();
     m_constructionInfo.SetGenericDefaultValues();
     m_constructionInfo.m_mass = mass;
     m_constructionInfo.commit();
     m_handle = BulletAPI_CreateBtRigidBody(m_constructionInfo.Handle);
  }
コード例 #4
0
        public override void DeleteTerrain()
        {
            if (TerrainBody != null)
            {
                m_world.removeRigidBody(TerrainBody);
            }

            if (m_terrainShape != null)
            {
                m_terrainShape.Dispose();
                m_terrainShape = null;
            }

            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            
            if (m_terrainTransform != null)
            {
                m_terrainTransform.Dispose();
                m_terrainTransform = null;
            }

            if (m_terrainPosition != null)
            {
                m_terrainPosition.Dispose();
                m_terrainPosition = null;
            }
        }
コード例 #5
0
        public override void SetTerrain(float[] heightMap, double[,] normalHeightMap)
        {
            if (m_terrainShape != null)
                DeleteTerrain();

            float hfmax = -9000;
            float hfmin = 90000;
            
            for (int i = 0; i <heightMap.Length;i++)
            {
                if (Single.IsNaN(heightMap[i]) || Single.IsInfinity(heightMap[i]))
                {
                    heightMap[i] = 0f;
                }

                hfmin = (heightMap[i] < hfmin) ? heightMap[i] : hfmin;
                hfmax = (heightMap[i] > hfmax) ? heightMap[i] : hfmax;
            }
            // store this for later reference.
            // Note, we're storing it  after we check it for anomolies above
            _origheightmap = heightMap;

            hfmin = 0;
            hfmax = 256;

            m_terrainShape = new btHeightfieldTerrainShape((int)Constants.RegionSize, (int)Constants.RegionSize, heightMap,
                                                           1.0f, hfmin, hfmax, (int)btHeightfieldTerrainShape.UPAxis.Z,
                                                           (int)btHeightfieldTerrainShape.PHY_ScalarType.PHY_FLOAT, false);
            float AabbCenterX = Constants.RegionSize/2f;
            float AabbCenterY = Constants.RegionSize/2f;

            float AabbCenterZ = 0;
            float temphfmin, temphfmax;

            temphfmin = hfmin;
            temphfmax = hfmax;

            if (temphfmin < 0)
            {
                temphfmax = 0 - temphfmin;
                temphfmin = 0 - temphfmin;
            }
            else if (temphfmin > 0)
            {
                temphfmax = temphfmax + (0 - temphfmin);
                //temphfmin = temphfmin + (0 - temphfmin);
            }
            AabbCenterZ = temphfmax/2f;
            
            if (m_terrainPosition == null)
            {
                m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
            }
            else
            {
                try
                {
                    m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
                } 
                catch (ObjectDisposedException)
                {
                    m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
            }
            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition);
            m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
            TerrainBody = new btRigidBody(0, m_terrainMotionState, m_terrainShape);
            TerrainBody.setUserPointer((IntPtr)0);
            m_world.addRigidBody(TerrainBody);
        }
コード例 #6
0
        public override void SetTerrain (ITerrainChannel channel, short[] shortheightMap)
        {
            if (m_terrainShape != null)
                DeleteTerrain();

            float hfmax = 256;
            float hfmin = 0;
            
            // store this for later reference.
            // Note, we're storing it  after we check it for anomolies above
            _origheightmap = shortheightMap;

            hfmin = 0;
            hfmax = 256;

            float[] heightmap = new float[m_region.RegionSizeX * m_region.RegionSizeX];
            for (int i = 0; i < shortheightMap.Length; i++)
            {
                heightmap[i] = shortheightMap[i] / Constants.TerrainCompression;
            }

            m_terrainShape = new btHeightfieldTerrainShape(m_region.RegionSizeX, m_region.RegionSizeY, heightmap,
                                                           1.0f, hfmin, hfmax, (int)btHeightfieldTerrainShape.UPAxis.Z,
                                                           (int)btHeightfieldTerrainShape.PHY_ScalarType.PHY_FLOAT, false);
            float AabbCenterX = m_region.RegionSizeX / 2f;
            float AabbCenterY = m_region.RegionSizeY / 2f;

            float AabbCenterZ = 0;
            float temphfmin, temphfmax;

            temphfmin = hfmin;
            temphfmax = hfmax;

            if (temphfmin < 0)
            {
                temphfmax = 0 - temphfmin;
                temphfmin = 0 - temphfmin;
            }
            else if (temphfmin > 0)
            {
                temphfmax = temphfmax + (0 - temphfmin);
                //temphfmin = temphfmin + (0 - temphfmin);
            }
            AabbCenterZ = temphfmax/2f;
            
            if (m_terrainPosition == null)
            {
                m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
            }
            else
            {
                try
                {
                    m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
                } 
                catch (ObjectDisposedException)
                {
                    m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
            }
            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition);
            m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
            TerrainBody = new btRigidBody(0, m_terrainMotionState, m_terrainShape);
            TerrainBody.setUserPointer((IntPtr)0);
            m_world.addRigidBody(TerrainBody);
        }
コード例 #7
0
        internal void Dispose()
        {
            //TODO:
            DisableAxisMotor();
            DisposeOfBody();
            SetCollisionShape(null);

            if (tempMotionState3 != null && tempMotionState3.Handle != IntPtr.Zero)
            {
                tempMotionState3.Dispose();
                tempMotionState3 = null;
            }

            if (tempMotionState2 != null && tempMotionState2.Handle != IntPtr.Zero)
            {
                tempMotionState2.Dispose();
                tempMotionState2 = null;
            }

            if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
            {
                tempMotionState1.Dispose();
                tempMotionState1 = null;
            }

            if (tempTransform4 != null && tempTransform4.Handle != IntPtr.Zero)
            {
                tempTransform4.Dispose();
                tempTransform4 = null;
            }

            if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero)
            {
                tempTransform3.Dispose();
                tempTransform3 = null;
            }

            if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero)
            {
                tempTransform2.Dispose();
                tempTransform2 = null;
            }

            if (tempTransform1 != null && tempTransform1.Handle != IntPtr.Zero)
            {
                tempTransform1.Dispose();
                tempTransform1 = null;
            }

            if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
            {
                tempOrientation2.Dispose();
                tempOrientation2 = null;
            }

            if (tempOrientation1 != null && tempOrientation1.Handle != IntPtr.Zero)
            {
                tempOrientation1.Dispose();
                tempOrientation1 = null;
            }

            if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero)
            {
                tempInertia1.Dispose();
                tempInertia1 = null;
            }

            if (tempInertia2 != null && tempInertia2.Handle != IntPtr.Zero)
            {
                tempInertia2.Dispose();
                tempInertia1 = null;
            }


            if (tempAngularVelocity2 != null && tempAngularVelocity2.Handle != IntPtr.Zero)
            {
                tempAngularVelocity2.Dispose();
                tempAngularVelocity2 = null;
            }

            if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero)
            {
                tempAngularVelocity1.Dispose();
                tempAngularVelocity1 = null;
            }

            if (tempLinearVelocity2 != null && tempLinearVelocity2.Handle != IntPtr.Zero)
            {
                tempLinearVelocity2.Dispose();
                tempLinearVelocity2 = null;
            }

            if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero)
            {
                tempLinearVelocity1.Dispose();
                tempLinearVelocity1 = null;
            }

            if (tempSize2 != null && tempSize2.Handle != IntPtr.Zero)
            {
                tempSize2.Dispose();
                tempSize2 = null;
            }

            if (tempSize1 != null && tempSize1.Handle != IntPtr.Zero)
            {
                tempSize1.Dispose();
                tempSize1 = null;
            }

            if (tempPosition3 != null && tempPosition3.Handle != IntPtr.Zero)
            {
                tempPosition3.Dispose();
                tempPosition3 = null;
            }

            if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero)
            {
                tempPosition2.Dispose();
                tempPosition2 = null;
            }

            if (tempPosition1 != null && tempPosition1.Handle != IntPtr.Zero)
            {
                tempPosition1.Dispose();
                tempPosition1 = null;
            }
            if (AxisLockLinearLow != null && AxisLockLinearLow.Handle != IntPtr.Zero)
            {
                AxisLockLinearLow.Dispose();
                AxisLockLinearLow = null;
            }
            if (AxisLockLinearHigh != null && AxisLockLinearHigh.Handle != IntPtr.Zero)
            {
                AxisLockLinearHigh.Dispose();
                AxisLockLinearHigh = null;
            }

        }
コード例 #8
0
        public void SetBody(float mass)
        {

            if (!IsPhysical || childrenPrim.Count == 0)
            {
                if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
                    tempMotionState1.Dispose();
                if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero)
                    tempTransform2.Dispose();
                if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
                    tempOrientation2.Dispose();

                if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero)
                    tempPosition2.Dispose();

                tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W);
                tempPosition2 = new btVector3(_position.X, _position.Y, _position.Z);
                tempTransform2 = new btTransform(tempOrientation2, tempPosition2);
                tempMotionState1 = new btDefaultMotionState(tempTransform2, _parent_scene.TransZero);
                if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero)
                    tempInertia1.Dispose();
                tempInertia1 = new btVector3(0, 0, 0);


                prim_geom.calculateLocalInertia(mass, tempInertia1);

                if (mass != 0)
                    _parent_scene.addActivePrim(this);
                else
                    _parent_scene.remActivePrim(this);

                //     Body = new btRigidBody(mass, tempMotionState1, prim_geom);
                //else
                Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1);

                if (prim_geom is btGImpactMeshShape)
                {
                    ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
                    ((btGImpactMeshShape)prim_geom).updateBound();
                }
                //Body.setCollisionFlags(Body.getCollisionFlags() | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK);
                //Body.setUserPointer((IntPtr) (int)m_localID);
                _parent_scene.AddPrimToScene(this);
            }
            else
            {
                // bool hasTrimesh = false;
                lock (childrenPrim)
                {
                    foreach (BulletDotNETPrim chld in childrenPrim)
                    {
                        if (chld == null)
                            continue;

                        // if (chld.NeedsMeshing())
                        //     hasTrimesh = true;
                    }
                }

                //if (hasTrimesh)
                //{
                ProcessGeomCreationAsTriMesh(Vector3.Zero, Quaternion.Identity);
                // createmesh returns null when it doesn't mesh.

                /*
                if (_mesh is Mesh)
                {
                }
                else
                {
                    m_log.Warn("[PHYSICS]: Can't link a OpenSim.Region.Physics.Meshing.Mesh object");
                    return;
                }
                */



                foreach (BulletDotNETPrim chld in childrenPrim)
                {
                    if (chld == null)
                        continue;
                    Vector3 offset = chld.Position - Position;
                    Vector3 pos = new Vector3(offset.X, offset.Y, offset.Z);
                    pos *= Quaternion.Inverse(Orientation);
                    //pos *= Orientation;
                    offset = pos;
                    chld.ProcessGeomCreationAsTriMesh(offset, chld.Orientation);

                    _mesh.Append(chld._mesh);


                }
                setMesh(_parent_scene, _mesh);

                //}

                if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
                    tempMotionState1.Dispose();
                if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero)
                    tempTransform2.Dispose();
                if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
                    tempOrientation2.Dispose();

                if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero)
                    tempPosition2.Dispose();

                tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W);
                tempPosition2 = new btVector3(_position.X, _position.Y, _position.Z);
                tempTransform2 = new btTransform(tempOrientation2, tempPosition2);
                tempMotionState1 = new btDefaultMotionState(tempTransform2, _parent_scene.TransZero);
                if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero)
                    tempInertia1.Dispose();
                tempInertia1 = new btVector3(0, 0, 0);


                prim_geom.calculateLocalInertia(mass, tempInertia1);

                if (mass != 0)
                    _parent_scene.addActivePrim(this);
                else
                    _parent_scene.remActivePrim(this);

                //     Body = new btRigidBody(mass, tempMotionState1, prim_geom);
                //else
                Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1);

                if (prim_geom is btGImpactMeshShape)
                {
                    ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
                    ((btGImpactMeshShape)prim_geom).updateBound();
                }
                _parent_scene.AddPrimToScene(this);

            }

            if (IsPhysical)
                changeAngularLock(0);
        }
コード例 #9
0
        public BulletDotNETPrim(String primName, BulletDotNETScene parent_scene, Vector3 pos, Vector3 size,
                       Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical)
        {
            tempPosition1 = new btVector3(0, 0, 0);
            tempPosition2 = new btVector3(0, 0, 0);
            tempPosition3 = new btVector3(0, 0, 0);
            tempSize1 = new btVector3(0, 0, 0);
            tempSize2 = new btVector3(0, 0, 0);
            tempLinearVelocity1 = new btVector3(0, 0, 0);
            tempLinearVelocity2 = new btVector3(0, 0, 0);
            tempAngularVelocity1 = new btVector3(0, 0, 0);
            tempAngularVelocity2 = new btVector3(0, 0, 0);
            tempInertia1 = new btVector3(0, 0, 0);
            tempInertia2 = new btVector3(0, 0, 0);
            tempOrientation1 = new btQuaternion(0, 0, 0, 1);
            tempOrientation2 = new btQuaternion(0, 0, 0, 1);
            _parent_scene = parent_scene;
            tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero);
            tempTransform2 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ;
            tempTransform3 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ;
            tempTransform4 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ;

            tempMotionState1 = new btDefaultMotionState(_parent_scene.TransZero);
            tempMotionState2 = new btDefaultMotionState(_parent_scene.TransZero);
            tempMotionState3 = new btDefaultMotionState(_parent_scene.TransZero);


            AxisLockLinearLow = new btVector3(-1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize);
            int regionsize = (int)Constants.RegionSize;

            if (regionsize == 256)
                regionsize = 512;

            AxisLockLinearHigh = new btVector3((int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionSize);

            _target_velocity = Vector3.Zero;
            _velocity = Vector3.Zero;
            _position = pos;
            m_taintposition = pos;
            PID_D = parent_scene.bodyPIDD;
            PID_G = parent_scene.bodyPIDG;
            m_density = parent_scene.geomDefaultDensity;
            // m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
            // body_autodisable_frames = parent_scene.bodyFramesAutoDisable;

            prim_geom = null;
            Body = null;

            if (size.X <= 0) size.X = 0.01f;
            if (size.Y <= 0) size.Y = 0.01f;
            if (size.Z <= 0) size.Z = 0.01f;

            _size = size;
            m_taintsize = _size;
            _acceleration = Vector3.Zero;
            m_rotationalVelocity = Vector3.Zero;
            _orientation = rotation;
            m_taintrot = _orientation;
            _mesh = mesh;
            _pbs = pbs;

            _parent_scene = parent_scene;

            if (pos.Z < 0)
                m_isphysical = false;
            else
            {
                m_isphysical = pisPhysical;
                // If we're physical, we need to be in the master space for now.
                // linksets *should* be in a space together..  but are not currently
            }
            m_primName = primName;
            m_taintadd = true;
            _parent_scene.AddPhysicsActorTaint(this);

        }
コード例 #10
0
ファイル: btRigidBody.cs プロジェクト: Belxjander/Asuna
        public void setMotionState(btMotionState motionState)
        {
            if (m_disposed)
                throw new ObjectDisposedException(ToString());

            BulletAPI_BtRigidBody_setMotionState(m_handle, motionState.Handle);
        }
コード例 #11
0
ファイル: BulletDotNETScene.cs プロジェクト: N3X15/VoxelSim
        public override void SetTerrain(bool[] heightMap)
        {

            if (m_terrainShape != null)
                DeleteTerrain();

            m_terrainShape = AddPrim(
                "__TERRAIN__",
                new Vector3(Constants.RegionSize / 2, Constants.RegionSize / 2, Constants.RegionSize / 2),
                new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionSize),
                Quaternion.Identity,
                voxmesher.ToMesh(heightMap),
                PrimitiveBaseShape.Default,
                false);
            //float AabbCenterX = Constants.RegionSize/2f;
            //float AabbCenterY = Constants.RegionSize/2f;

            //float AabbCenterZ = 0f;
            /*
            float temphfmin, temphfmax;

            temphfmin = hfmin;
            temphfmax = hfmax;

            if (temphfmin < 0)
            {
                temphfmax = 0 - temphfmin;
                temphfmin = 0 - temphfmin;
            }
            else if (temphfmin > 0)
            {
                temphfmax = temphfmax + (0 - temphfmin);
                //temphfmin = temphfmin + (0 - temphfmin);
            }
            AabbCenterZ = temphfmax/2f;
            
            if (m_terrainPosition == null)
            {
                m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
            }
            else
            {
                try
                {
                    m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
                } 
                catch (ObjectDisposedException)
                {
                    m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
            }
            */
            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition);
            m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
        }