Esempio n. 1
0
 public PhysicsActor AddPrim(String name, OpenMetaverse.Vector3 position, OpenMetaverse.Vector3 size, OpenMetaverse.Quaternion rotation,
                             IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical)
 {
     BulletXPrim newPrim = null;
     lock (BulletXLock)
     {
         newPrim = new BulletXPrim(name, this, position, size, rotation, mesh, pbs, isPhysical);
         _prims.Add(newPrim.RigidBody, newPrim);
     }
     return newPrim;
 }
Esempio n. 2
0
        //added by jed zhu
        //calculas the collision between the Prim and Actor
        //
        private int Collision(BulletXCharacter actorA, BulletXPrim primB)
        {
            int[] indexBase;
            Vector3[] vertexBase;
            Vector3 vNormal;
            // Vector3 vP1;
            // Vector3 vP2;
            // Vector3 vP3;
            IMesh mesh = primB.GetMesh();

            float fdistance;
            if (primB == null)
                return 3;
            if (mesh == null)
                return 2;
            if (actorA == null)
                return 3;

            int iVertexCount = mesh.getVertexList().Count;
            int iIndexCount = mesh.getIndexListAsInt().Length;
            if (iVertexCount == 0)
                return 3;
            if (iIndexCount == 0)
                return 3;
            lock (BulletXScene.BulletXLock)
            {
                indexBase = mesh.getIndexListAsInt();
                vertexBase = new Vector3[iVertexCount];
                
                for (int i = 0; i < iVertexCount; i++)
                {
                    OpenMetaverse.Vector3 v = mesh.getVertexList()[i];
                    if (v != null) // Note, null has special meaning. See meshing code for details
                        vertexBase[i] = BulletXMaths.PhysicsVectorToXnaVector3(v);
                    else
                        vertexBase[i] = Vector3.Zero;
                }
                
                for (int ix = 0; ix < iIndexCount; ix += 3)
                {
                    int ia = indexBase[ix + 0];
                    int ib = indexBase[ix + 1];
                    int ic = indexBase[ix + 2];
                    //
                    Vector3 v1 = vertexBase[ib] - vertexBase[ia];
                    Vector3 v2 = vertexBase[ic] - vertexBase[ia];

                    Vector3.Cross(ref v1, ref v2, out vNormal);
                    Vector3.Normalize(ref vNormal, out vNormal);

                    fdistance = Vector3.Dot(vNormal, vertexBase[ia]) + 0.50f;
                    if (preCheckCollision(actorA, vNormal, fdistance) == 1)
                    {
                        if (CheckCollision(actorA, ia, ib, ic, vNormal, vertexBase) == 1)
                        {
                            //PhysicsVector v = actorA.Position;
                            //Vector3 v3 = BulletXMaths.PhysicsVectorToXnaVector3(v);
                            //Vector3 vp = vNormal * (fdistance - Vector3.Dot(vNormal, v3) + 0.2f);
                            //actorA.Position += BulletXMaths.XnaVector3ToPhysicsVector(vp);
                            return 1;
                        }
                    }
                }
            }


            return 0;
        }