Inheritance: PhysicsScene
Ejemplo n.º 1
0
        internal void Step(float timestep, BulletDotNETScene _parent_scene)
        {
            parent_scene = _parent_scene;
            if (m_body == null || m_type == Vehicle.TYPE_NONE)
            {
                return;
            }

            /*if (m_prim.m_force.X == 0.0f && m_prim.m_force.Y == 0.0f && m_prim.m_force.Z == 0.0f && m_prim.IsPhysical)
             * {
             *  //  keep track of where we stopped.  No more slippin' & slidin'
             *  if (!m_prim._zeroFlag)
             *  {
             *      m_prim._zeroFlag = true;
             *      m_prim.m_zeroPosition.X = m_prim.m_taintposition.X;
             *      m_prim.m_zeroPosition.Y = m_prim.m_taintposition.Y;
             *      m_prim.m_zeroPosition.Z = m_prim.m_taintposition.Z;
             *      m_prim.m_velocity = Vector3.Zero;
             *      m_prim.Body.setLinearVelocity(new btVector3(0, 0, 0));
             *  }
             * }*/

            MoveLinear(timestep);
            MoveAngular(timestep);
            LimitRotation(timestep);
        }
Ejemplo n.º 2
0
 public PhysicsScene GetScene(string sceneIdentifier)
 {
     if (m_scene == null)
     {
         m_scene = new BulletDotNETScene(sceneIdentifier);
     }
     return m_scene;
 }
Ejemplo n.º 3
0
 public PhysicsScene GetScene(string sceneIdentifier)
 {
     if (m_scene == null)
     {
         m_scene = new BulletDotNETScene(sceneIdentifier);
     }
     return(m_scene);
 }
        // private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();

        public BulletDotNETCharacter(string avName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor)
        {
            m_taintedForce    = new PhysicsVector();
            m_velocity        = new PhysicsVector();
            m_target_velocity = new PhysicsVector();
            m_position        = pos;
            m_zeroPosition    = new PhysicsVector(pos.X, pos.Y, pos.Z); // this is a class, not a struct.  Must make new, or m_zeroPosition will == position regardless
            m_acceleration    = new PhysicsVector();
            m_parent_scene    = parent_scene;
            PID_D             = pid_d;
            PID_P             = pid_p;
            CAPSULE_RADIUS    = capsule_radius;
            m_density         = density;
            heightFudgeFactor = height_fudge_factor;
            walkDivisor       = walk_divisor;
            runDivisor        = rundivisor;

            for (int i = 0; i < 11; i++)
            {
                m_colliderarr[i] = false;
            }
            for (int i = 0; i < 11; i++)
            {
                m_colliderGroundarr[i] = false;
            }
            CAPSULE_LENGTH           = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f;
            m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH;
            m_isPhysical             = false; // current status: no ODE information exists
            m_tainted_isPhysical     = true;  // new tainted status: need to create ODE information

            m_parent_scene.AddPhysicsActorTaint(this);

            // m_name = avName;
            tempVector1 = new btVector3(0, 0, 0);
            tempVector2 = new btVector3(0, 0, 0);
            tempVector3 = new btVector3(0, 0, 0);
            tempVector4 = new btVector3(0, 0, 0);

            tempVector5RayCast = new btVector3(0, 0, 0);
            tempVector6RayCast = new btVector3(0, 0, 0);
            tempVector7RayCast = new btVector3(0, 0, 0);

            tempQuat1  = new btQuaternion(0, 0, 0, 1);
            tempTrans1 = new btTransform(tempQuat1, tempVector1);
            // m_movementComparision = new PhysicsVector(0, 0, 0);
            m_CapsuleOrientationAxis = new btVector3(1, 0, 1);
        }
Ejemplo n.º 5
0
        internal void Step(float timestep, BulletDotNETScene _parent_scene)
        {
            parent_scene = _parent_scene;
            if (m_body == null || m_type == Vehicle.TYPE_NONE)
                return;
            /*if (m_prim.m_force.X == 0.0f && m_prim.m_force.Y == 0.0f && m_prim.m_force.Z == 0.0f && m_prim.IsPhysical)
            {
                //  keep track of where we stopped.  No more slippin' & slidin'
                if (!m_prim._zeroFlag)
                {
                    m_prim._zeroFlag = true;
                    m_prim.m_zeroPosition.X = m_prim.m_taintposition.X;
                    m_prim.m_zeroPosition.Y = m_prim.m_taintposition.Y;
                    m_prim.m_zeroPosition.Z = m_prim.m_taintposition.Z;
                    m_prim.m_velocity = Vector3.Zero;
                    m_prim.Body.setLinearVelocity(new btVector3(0, 0, 0));
                }
            }*/

            MoveLinear(timestep);
            MoveAngular(timestep);
            LimitRotation(timestep);
        }
Ejemplo n.º 6
0
        public BulletDotNETCharacter(string avName, BulletDotNETScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor)
        {
            m_position = pos;
            m_zeroPosition = pos;
            m_parent_scene = parent_scene;
            PID_D = pid_d;
            PID_P = pid_p;
            CAPSULE_RADIUS = capsule_radius;
            m_density = density;
            heightFudgeFactor = height_fudge_factor;
            walkDivisor = walk_divisor;
            runDivisor = rundivisor;
            
            for (int i = 0; i < 11; i++)
            {
                m_colliderarr[i] = false;
            }
            for (int i = 0; i < 11; i++)
            {
                m_colliderGroundarr[i] = false;
            }
            CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f;
            m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH;
            m_isPhysical = false; // current status: no ODE information exists
            m_tainted_isPhysical = true; // new tainted status: need to create ODE information

            m_parent_scene.AddPhysicsActorTaint(this);
            
            // m_name = avName;
            tempVector1 = new btVector3(0, 0, 0);
            tempVector2 = new btVector3(0, 0, 0);
            tempVector3 = new btVector3(0, 0, 0);
            tempVector4 = new btVector3(0, 0, 0);

            tempVector5RayCast = new btVector3(0, 0, 0);
            tempVector6RayCast = new btVector3(0, 0, 0);
            tempVector7RayCast = new btVector3(0, 0, 0);

            tempQuat1 = new btQuaternion(0, 0, 0, 1);
            tempTrans1 = new btTransform(tempQuat1, tempVector1);
            // m_movementComparision = new PhysicsVector(0, 0, 0);
            m_CapsuleOrientationAxis = new btVector3(1, 0, 1);
        }
Ejemplo n.º 7
0
        private void setMesh(BulletDotNETScene _parent_scene, IMesh mesh)
        {
            // TODO: Set Collision Body Mesh
            // This sleeper is there to moderate how long it takes between
            // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object
            m_log.Debug("_________SetMesh");
            Thread.Sleep(10);

            //Kill Body so that mesh can re-make the geom
            if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero)
            {
                if (childPrim)
                {
                    if (_parent != null)
                    {
                        BulletDotNETPrim parent = (BulletDotNETPrim)_parent;
                        parent.ChildDelink(this);
                    }
                }
                else
                {
                    //disableBody();
                }
            }

            //IMesh oldMesh = primMesh;

            //primMesh = mesh;

            //float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
            //int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
            ////Array.Reverse(indexList);
            //primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory

            IMesh oldMesh = primMesh;

            primMesh = mesh;

            float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
            int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
            //Array.Reverse(indexList);
            mesh.releaseSourceMeshData(); // free up the original mesh data to save memory


            int VertexCount = vertexList.GetLength(0) / 3;
            int IndexCount = indexList.GetLength(0);

            if (btshapeArray != null && btshapeArray.Handle != IntPtr.Zero)
                btshapeArray.Dispose();
            //Array.Reverse(indexList);
            btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)),
                                                                                     VertexCount, vertexList, 3 * sizeof(float));
            SetCollisionShape(new btGImpactMeshShape(btshapeArray));
            //((btGImpactMeshShape) prim_geom).updateBound();
            ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
            ((btGImpactMeshShape)prim_geom).updateBound();
            _parent_scene.SetUsingGImpact();
            //if (oldMesh != null)
            //{
            //    oldMesh.releasePinned();
            //    oldMesh = null;
            //}

        }
Ejemplo n.º 8
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);

        }