当前位置: 首页>>代码示例>>C#>>正文


C# ObjectArray.Add方法代码示例

本文整理汇总了C#中ObjectArray.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectArray.Add方法的具体用法?C# ObjectArray.Add怎么用?C# ObjectArray.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectArray的用法示例。


在下文中一共展示了ObjectArray.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessAllTriangles

        public override void ProcessAllTriangles(ITriangleCallback callback, ref Vector3 aabbMin, ref Vector3 aabbMax)
        {
	        Vector3 halfExtents = (aabbMax - aabbMin) * .5f;
	        float radius = halfExtents.Length();
	        Vector3 center = (aabbMax + aabbMin) * 0.5f;
        	
	        //this is where the triangles are generated, given AABB and plane equation (normal/constant)

	        Vector3 tangentDir0 = Vector3.Zero;
            Vector3 tangentDir1 = Vector3.Zero;

	        //tangentDir0/tangentDir1 can be precalculated
	        TransformUtil.PlaneSpace1(ref m_planeNormal,ref tangentDir0,ref tangentDir1);

            Vector3 supVertex0 = Vector3.Zero;
            Vector3 supVertex1 = Vector3.Zero;

	        Vector3 projectedCenter = center - (Vector3.Dot(m_planeNormal,center) - m_planeConstant)*m_planeNormal;

            ObjectArray<Vector3> triangle = new ObjectArray<Vector3>(3);
	        triangle.Add(projectedCenter + tangentDir0*radius + tangentDir1*radius);
            triangle.Add(projectedCenter + tangentDir0 * radius - tangentDir1 * radius);
            triangle.Add(projectedCenter - tangentDir0 * radius - tangentDir1 * radius);

	        callback.ProcessTriangle(triangle,0,0);

	        triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
	        triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
	        triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;

	        callback.ProcessTriangle(triangle,0,1);

        }
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:33,代码来源:StaticPlaneShape.cs

示例2: GImpactVsShapeFindPairs

        protected void GImpactVsShapeFindPairs(
                          ref IndexedMatrix trans0,
                          ref IndexedMatrix trans1,
                          GImpactShapeInterface shape0,
                          CollisionShape shape1,
                          ObjectArray<int> collided_primitives)
        {
            AABB boxshape = new AABB();


            if (shape0.HasBoxSet())
            {
                IndexedMatrix trans1to0 = trans0.Inverse();
                //trans1to0 *= trans1;
                trans1to0 = trans1to0 * trans1;
                //trans1to0 = MathUtil.BulletMatrixMultiply(trans1,trans1to0);
                shape1.GetAabb(ref trans1to0, out boxshape.m_min, out boxshape.m_max);
                if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo)
                {
                    MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "GImpactAglo::GImpactVsShapeFindPairs trans1to0", trans1to0);
                    MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box min", boxshape.m_min);
                    MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box max", boxshape.m_max);
                }
                shape0.GetBoxSet().BoxQuery(ref boxshape, collided_primitives);
            }
            else
            {
                shape1.GetAabb(ref trans1, out boxshape.m_min, out boxshape.m_max);

                AABB boxshape0 = new AABB();
                int i = shape0.GetNumChildShapes();

                while (i-- != 0)
                {
                    shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max);

                    if (boxshape.HasCollision(ref boxshape0))
                    {
                        collided_primitives.Add(i);
                    }
                }

            }


        }
开发者ID:JohnLouderback,项目名称:illuminati-engine-xna,代码行数:46,代码来源:GImpactCollisionAlgorithm.cs

示例3: BuildAndProcessIslands

        public void BuildAndProcessIslands(IDispatcher dispatcher, CollisionWorld collisionWorld, IIslandCallback callback)
        {
	        ObjectArray<CollisionObject> collisionObjects = collisionWorld.GetCollisionObjectArray();

	        BuildIslands(dispatcher,collisionWorld);

	        int endIslandIndex=1;
	        int startIslandIndex;
	        int numElem = GetUnionFind().GetNumElements();

            //BT_PROFILE("processIslands");

	        if(!m_splitIslands)
	        {
		        ObjectArray<PersistentManifold> manifolds = dispatcher.GetInternalManifoldPointer();
		        int maxNumManifolds = dispatcher.GetNumManifolds();
		        callback.ProcessIsland(collisionObjects,collisionObjects.Count,manifolds,maxNumManifolds, -1);
	        }
	        else
	        {
		        // Sort manifolds, based on islands
		        // Sort the vector using predicate and std::sort
		        //std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);

		        int numManifolds = m_islandmanifold.Count;
                if (numManifolds != 0 && m_islandmanifold[0].GetNumContacts() > 0)
                {
                    int ibreak = 0;
                }


		        //we should do radix sort, it it much faster (O(n) instead of O (n log2(n))
                //m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
                //((ObjectArray<PersistentManifold>)m_islandmanifold).Sort();
                m_islandmanifold.Sort(new Comparison<PersistentManifold>(PersistentManifoldSortPredicate));

		        //now process all active islands (sets of manifolds for now)

		        int startManifoldIndex = 0;
		        int endManifoldIndex = 1;

		        //int islandId;

	            //	printf("Start Islands\n");

		        //traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated
		        for ( startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex)
		        {
                    int islandId = GetUnionFind().GetElement(startIslandIndex).m_id;

                    if (BulletGlobals.g_streamWriter != null && debugIslands)
                    {
                        BulletGlobals.g_streamWriter.WriteLine(String.Format("buildAndProcessIslands start[{0}] end[{1}] id[{2}]", startIslandIndex, endIslandIndex, islandId));
                    }


                    bool islandSleeping = false;
        	                
			        for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (GetUnionFind().GetElement(endIslandIndex).m_id == islandId);endIslandIndex++)
			        {
			            int i = GetUnionFind().GetElement(endIslandIndex).m_sz;
			            CollisionObject colObj0 = collisionObjects[i];
			            m_islandBodies.Add(colObj0);
			            if (!colObj0.IsActive())
                        {
                            islandSleeping = true;
                            //islandSleeping = false;
                        }
			        }
        	                
			        //find the accompanying contact manifold for this islandId
			        int numIslandManifolds = 0;
			        PersistentManifold startManifold = null;

			        if (startManifoldIndex<numManifolds)
			        {
				        int curIslandId = GetIslandId(m_islandmanifold[startManifoldIndex]);
				        if (curIslandId == islandId)
				        {
					        startManifold = m_islandmanifold[startManifoldIndex];
        				
					        for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == GetIslandId(m_islandmanifold[endManifoldIndex]));endManifoldIndex++)
					        {

					        }
					        /// Process the actual simulation, only if not sleeping/deactivated
					        numIslandManifolds = endManifoldIndex-startManifoldIndex;
				        }

			        }

			        if (!islandSleeping)
			        {
                        // pass shortedned list to callback.
                        ObjectArray<PersistentManifold> subList = new ObjectArray<PersistentManifold>();
                        for(int i=0;i<numIslandManifolds;++i)
                        {
                            subList.Add(m_islandmanifold[startManifoldIndex+i]);
                        }
				        callback.ProcessIsland(m_islandBodies,m_islandBodies.Count,subList,numIslandManifolds, islandId);
//.........这里部分代码省略.........
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:101,代码来源:SimulationIslandManager.cs

示例4: coordinates


//.........这里部分代码省略.........
                case 0:
                    {
                        if (quantizedAabbMin[1] > startX)
                            startX = quantizedAabbMin[1];
                        if (quantizedAabbMax[1] < endX)
                            endX = quantizedAabbMax[1];
                        if (quantizedAabbMin[2] > startJ)
                            startJ = quantizedAabbMin[2];
                        if (quantizedAabbMax[2] < endJ)
                            endJ = quantizedAabbMax[2];
                        break;
                    }
                case 1:
                    {
                        if (quantizedAabbMin[0] > startX)
                            startX = quantizedAabbMin[0];
                        if (quantizedAabbMax[0] < endX)
                            endX = quantizedAabbMax[0];
                        if (quantizedAabbMin[2] > startJ)
                            startJ = quantizedAabbMin[2];
                        if (quantizedAabbMax[2] < endJ)
                            endJ = quantizedAabbMax[2];
                        break;
                    };
                case 2:
                    {
                        if (quantizedAabbMin[0] > startX)
                            startX = quantizedAabbMin[0];
                        if (quantizedAabbMax[0] < endX)
                            endX = quantizedAabbMax[0];
                        if (quantizedAabbMin[1] > startJ)
                            startJ = quantizedAabbMin[1];
                        if (quantizedAabbMax[1] < endJ)
                            endJ = quantizedAabbMax[1];
                        break;
                    }
                default:
                    {
                        //need to get valid m_upAxis
                        Debug.Assert(false);
                        break;
                    }
            }

            ObjectArray<Vector3> vertices = new ObjectArray<Vector3>();
            Vector3[] tempVectors = new Vector3[3];
            for (int j = startJ; j < endJ; j++)
            {
                for (int x = startX; x < endX; x++)
                {
                    if (m_flipQuadEdges || (m_useDiamondSubdivision && (((j + x) & 1) > 0)))
                    {
                        //first triangle
                        GetVertex(x, j, ref tempVectors[0]);
                        GetVertex(x + 1, j, ref tempVectors[1]);
                        GetVertex(x + 1, j + 1, ref tempVectors[2]);
                        vertices.Clear();
                        for (int a = 0; a < tempVectors.Length; ++a)
                        {
                            vertices.Add(tempVectors[a]);
                        }
                        callback.ProcessTriangle(vertices, x, j);
                        //second triangle
                        GetVertex(x, j, ref tempVectors[0]);
                        GetVertex(x + 1, j + 1, ref tempVectors[1]);
                        GetVertex(x, j + 1, ref tempVectors[2]);
                        vertices.Clear();
                        for (int a = 0; a < tempVectors.Length; ++a)
                        {
                            vertices.Add(tempVectors[a]);
                        }
                        callback.ProcessTriangle(vertices, x, j);
                    }
                    else
                    {
                        //first triangle
                        GetVertex(x, j, ref tempVectors[0]);
                        GetVertex(x, j + 1, ref tempVectors[1]);
                        GetVertex(x + 1, j, ref tempVectors[2]);
                        vertices.Clear();
                        for (int a = 0; a < tempVectors.Length; ++a)
                        {
                            vertices.Add(tempVectors[a]);
                        }
                        callback.ProcessTriangle(vertices, x, j);

                        //second triangle
                        GetVertex(x + 1, j, ref tempVectors[0]);
                        GetVertex(x, j + 1, ref tempVectors[1]);
                        GetVertex(x + 1, j + 1, ref tempVectors[2]);
                        vertices.Clear();
                        for (int a = 0; a < tempVectors.Length; ++a)
                        {
                            vertices.Add(tempVectors[a]);
                        }
                        callback.ProcessTriangle(vertices, x, j);
                    }
                }
            }
        }
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:101,代码来源:HeightfieldTerrainShape.cs

示例5: BuildCorner

        public CollisionShape BuildCorner()
        {
            // slope.
            IndexedVector3[] vertices = new IndexedVector3[]{new IndexedVector3(0,0,0),new IndexedVector3(1,0,0),new IndexedVector3(0,0,1),new IndexedVector3(1,0,1),
                            new IndexedVector3(0,1,0),new IndexedVector3(1,1,0),new IndexedVector3(0,1,1),new IndexedVector3(1,1,1)};



            //int[] indices = new int[] { 0, 4, 5, 4, 6, 7, 7, 5, 4, 0, 4, 6, 6, 2, 0, 2, 6, 7, 4,5,0,2,2,7,5};
            //int[] indices = new int[] { 0, 4, 5, 4, 6, 7, 7, 5, 4,  6, 4,0,0,2,6, 7, 6, 2, 4, 5, 0, 2, 2, 7, 5 };
            int[] indices = new int[] { 1,4,5,
                1,5,7,
                7,3,1,
                3,7,6,
                7,5,4,
                4,6,7,
                4,1,3,
                3,6,4
            };

            int vertStride = 1;
            int indexStride = 3;

            ObjectArray<IndexedVector3> vertexArray = new ObjectArray<IndexedVector3>();
            for (int i = 0; i < vertices.Length; ++i)
            {
                vertexArray.Add(vertices[i]);
            }

            ObjectArray<int> intArray = new ObjectArray<int>();
            for (int i = 0; i < indices.Length; ++i)
            {
                intArray.Add(indices[i]);
            }
            TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(indices.Length/3, intArray, indexStride, vertexArray.Count, vertexArray, vertStride);
            TriangleMeshShape triangleMesh = new TriangleMeshShape(indexVertexArray);
            //TriangleMeshShape triangleMesh = new BvhTriangleMeshShape(indexVertexArray,true,true);
            return triangleMesh;




        }
开发者ID:ousttrue,项目名称:bullet-xna,代码行数:43,代码来源:BasicDemo.cs

示例6: BuildCorner

        public static CollisionShape BuildCorner(IndexedVector3[] vertices, int[] indices)
        {
            int vertStride = 1;
            int indexStride = 3;

            ObjectArray<IndexedVector3> vertexArray = new ObjectArray<IndexedVector3>();
            for (int i = 0; i < vertices.Length; ++i)
            {
                vertexArray.Add(vertices[i]);
            }

            ObjectArray<int> intArray = new ObjectArray<int>();
            for (int i = 0; i < indices.Length; ++i)
            {
                intArray.Add(indices[i]);
            }
            TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(indices.Length / 3, intArray, indexStride, vertexArray.Count, vertexArray, vertStride);
            TriangleMeshShape triangleMesh = new TriangleMeshShape(indexVertexArray);
            return triangleMesh;
        }
开发者ID:ousttrue,项目名称:bullet-xna,代码行数:20,代码来源:CornerDemo.cs

示例7: GetCollidingObjectsInsidePairCachingGhostObject

        // Portable static method: prerequisite call: m_dynamicsWorld.getBroadphase().getOverlappingPairCache().setInternalGhostPairCallback(new btGhostPairCallback()); 
        public static void GetCollidingObjectsInsidePairCachingGhostObject(DiscreteDynamicsWorld m_dynamicsWorld, PairCachingGhostObject m_pairCachingGhostObject, ObjectArray<CollisionObject> collisionArrayOut)
        {
            bool addOnlyObjectsWithNegativeDistance = true;	// With "false" things don't change much, and the code is a bit faster and cleaner...


            collisionArrayOut.Resize(0);
            if (m_pairCachingGhostObject == null || m_dynamicsWorld == null) return;

            //#define USE_PLAIN_COLLISION_WORLD // We dispatch all collision pairs of the ghost object every step (slow)
#if USE_PLAIN_COLLISION_WORLD
	//======================================================================================================
	// I thought this line was no longer needed, but it seems to be necessary (and I believe it's an expensive call):
	m_dynamicsWorld.getDispatcher().dispatchAllCollisionPairs(m_pairCachingGhostObject.getOverlappingPairCache(), m_dynamicsWorld.getDispatchInfo(), m_dynamicsWorld.getDispatcher());
	// Maybe the call can be automatically triggered by some other Bullet call (I'm almost sure I could comment it out in another demo I made long ago...)
	// So by now the general rule is: in real projects, simply comment it out and see if it works!
	//======================================================================================================
	// UPDATE: in dynamic worlds, the line above can be commented out and the broadphase pair can be retrieved through the call to findPair(...) below.
	// In collision worlds probably the above line is needed only if collision detection for all the bodies hasn't been made... This is something
	// I'm still not sure of... the general rule is to try to comment out the line above and try to use findPair(...) and see if it works whenever possible....
	//======================================================================================================
#endif //USE_PLAIN_COLLISION_WORLD

            ObjectArray<BroadphasePair> collisionPairs = m_pairCachingGhostObject.GetOverlappingPairCache().GetOverlappingPairArray();
            int numObjects = collisionPairs.Count;
            PersistentManifoldArray m_manifoldArray = new PersistentManifoldArray();
            bool added;
            for (int i = 0; i < numObjects; i++)
            {
                m_manifoldArray.Resize(0);

#if USE_PLAIN_COLLISION_WORLD
		const btBroadphasePair& collisionPair = collisionPairs[i];
		if (collisionPair.m_algorithm) collisionPair.m_algorithm.getAllContactManifolds(m_manifoldArray);
		else {	// THIS SHOULD NEVER HAPPEN, AND IF IT DOES, PLEASE RE-ENABLE the "call" a few lines above...
			printf("No collisionPair.m_algorithm - probably m_dynamicsWorld.getDispatcher().dispatchAllCollisionPairs(...) must be missing.\n");	
		}	
#else // USE_PLAIN_COLLISION_WORLD
                BroadphasePair cPair = collisionPairs[i];
                //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
                BroadphasePair collisionPair = m_dynamicsWorld.GetPairCache().FindPair(cPair.m_pProxy0, cPair.m_pProxy1);
                if (collisionPair == null)
                {
                    continue;

                }
                if (collisionPair.m_algorithm != null)
                {
                    collisionPair.m_algorithm.GetAllContactManifolds(m_manifoldArray);
                }
                else
                {	// THIS SHOULD NEVER HAPPEN, AND IF IT DOES, PLEASE RE-ENABLE the "call" a few lines above...
                    //printf("No collisionPair.m_algorithm - probably m_dynamicsWorld.getDispatcher().dispatchAllCollisionPairs(...) must be missing.\n");	
                }
#endif //USE_PLAIN_COLLISION_WORLD

                added = false;
                for (int j = 0; j < m_manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = m_manifoldArray[j];
                    // Here we are in the narrowphase, but can happen that manifold.getNumContacts()==0:
                    if (addOnlyObjectsWithNegativeDistance)
                    {
                        for (int p = 0, numContacts = manifold.GetNumContacts(); p < numContacts; p++)
                        {
                            ManifoldPoint pt = manifold.GetContactPoint(p);
                            if (pt.GetDistance() < 0.0)
                            {
                                // How can I be sure that the colObjs are all distinct ? I use the "added" flag.
                                collisionArrayOut.Add((CollisionObject)(manifold.GetBody0() == m_pairCachingGhostObject ? manifold.GetBody1() : manifold.GetBody0()));
                                added = true;
                                break;
                            }
                        }
                        if (added)
                        {
                            break;
                        }
                    }
                    else if (manifold.GetNumContacts() > 0)
                    {
                        collisionArrayOut.Add((CollisionObject)(manifold.GetBody0() == m_pairCachingGhostObject ? manifold.GetBody1() : manifold.GetBody0()));
                        break;
                    }
                }
            }
        }
开发者ID:ousttrue,项目名称:bullet-xna,代码行数:87,代码来源:GhostObjectDemo.cs

示例8: BuildLargeMesh

CollisionShape BuildLargeMesh()
{
	//int vertStride = sizeof(IndexedVector3);
	//int indexStride = 3*sizeof(int);

	int vertStride = 1;
	int indexStride = 3;

	ObjectArray<IndexedVector3> vertexArray = new ObjectArray<IndexedVector3>();
	for (int i = 0; i < vertices.Length; ++i)
	{
		vertexArray.Add(vertices[i]);
	}

	ObjectArray<int> intArray = new ObjectArray<int>();
	for (int i = 0; i < indices.Length; ++i)
	{
		intArray.Add(indices[i]);
	}
    //TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(DemoMeshes.BUNNY_NUM_TRIANGLES, DemoMeshes.gBunnyIndices, 3, DemoMeshes.BUNNY_NUM_VERTICES, DemoMeshes.gBunnyVertices, 3);

    TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(numTriangles, intArray, indexStride, vertexArray.Count, vertexArray, vertStride);
    TriangleMeshShape triangleMesh = new TriangleMeshShape(indexVertexArray);
    //TriangleMeshShape triangleMesh = new BvhTriangleMeshShape(indexVertexArray,true,true);
	return triangleMesh;

}
开发者ID:JohnLouderback,项目名称:illuminati-engine-xna,代码行数:27,代码来源:LargeMeshDemo.cs

示例9: FetchLeafs

 public static void FetchLeafs(Dbvt pdbvt, DbvtNode root, ObjectArray<DbvtNode> leafs, int depth)
 {
     if (root.IsInternal() && depth != 0)
     {
         FetchLeafs(pdbvt, root._children[0], leafs, depth - 1);
         FetchLeafs(pdbvt, root._children[1], leafs, depth - 1);
         DeleteNode(pdbvt, root);
     }
     else
     {
         leafs.Add(root);
     }
 }
开发者ID:JohnLouderback,项目名称:illuminati-engine-xna,代码行数:13,代码来源:Dbvt.cs

示例10: QueryNode

        public void QueryNode(QuadTreeNode node, ObjectArray<QuadTreeNode> results, IndexedVector3 source,IndexedVector3 direction)
        {
            //if(node.children == null && node.Intersects(raySource,rayTarget))
            // add the lowest level.

            if (node.children == null)
            {
                results.Add(node);
#if DEBUG_ACCELERATOR
                if (BulletGlobals.gDebugDraw != null)
                {

                    IndexedVector3 drawMin = new IndexedVector3(node.boundingBox.Min);
                    IndexedVector3 drawMax = new IndexedVector3(node.boundingBox.Max);

                    IndexedVector3 worldMin = LocalToWorld2(drawMin);
                    IndexedVector3 worldMax = LocalToWorld2(drawMax);

                    BulletGlobals.gDebugDraw.DrawAabb(worldMin, worldMax, new IndexedVector3(1, 1, 1));
                }
#endif
            }
            else
            {


                // simple rescursive for now.
                for (int i = 0; i < 4; ++i)
                {
                    if (node.children[i].Intersects(source,direction))
                    {
                        QueryNode(node.children[i], results, source,direction);
                    }
                }
            }
        }
开发者ID:JohnLouderback,项目名称:illuminati-engine-xna,代码行数:36,代码来源:HeightfieldTerrainShape.cs

示例11: InitializePolyhedralFeatures

        ///optional method mainly used to generate multiple contact points by clipping polyhedral features (faces/edges)
        public virtual bool InitializePolyhedralFeatures()
        {
#if USE_CONVEX_HULL_COMPUTER
            if (m_polyhedron != null)
            {
                m_polyhedron = null;
            }

            m_polyhedron = new ConvexPolyhedron();

            ObjectArray<IndexedVector3> tmpVertices = new ObjectArray<IndexedVector3>();
            for (int i = 0; i < GetNumVertices(); i++)
            {
                IndexedVector3 newVertex;
                GetVertex(i, out newVertex);
                tmpVertices.Add(newVertex);
            }

            ConvexHullComputer conv = new ConvexHullComputer();
            //conv.compute(&tmpVertices[0].getX(), sizeof(IndexedVector3),tmpVertices.Count,0.0f,0.0f);
            conv.Compute(tmpVertices, 0, tmpVertices.Count, 0.0f, 0.0f);



            ObjectArray<IndexedVector3> faceNormals = new ObjectArray<IndexedVector3>();
            int numFaces = conv.faces.size();
            faceNormals.Resize(numFaces);
            ConvexHullComputer convexUtil = conv;



            m_polyhedron.m_faces.Resize(numFaces);
            int numVertices = convexUtil.vertices.Count;
            m_polyhedron.m_vertices.Resize(numVertices);
            for (int p = 0; p < numVertices; p++)
            {
                m_polyhedron.m_vertices[p] = convexUtil.vertices[p];
            }

            for (int i = 0; i < numFaces; i++)
            {
                int face = convexUtil.faces[i];
                //printf("face=%d\n",face);
                Edge firstEdge = convexUtil.edges[face];
                Edge edge = firstEdge;

                IndexedVector3[] edges = new IndexedVector3[3];
                int numEdges = 0;
                //compute face normals

                float maxCross2 = 0.0f;
                int chosenEdge = -1;

                do
                {
                    int src = edge.GetSourceVertex();
                    m_polyhedron.m_faces[i].m_indices.Add(src);
                    int targ = edge.GetTargetVertex();
                    IndexedVector3 wa = convexUtil.vertices[src];

                    IndexedVector3 wb = convexUtil.vertices[targ];
                    IndexedVector3 newEdge = wb - wa;
                    newEdge.Normalize();
                    if (numEdges < 2)
                    {
                        edges[numEdges++] = newEdge;
                    }

                    edge = edge.GetNextEdgeOfFace();
                } while (edge != firstEdge);

                float planeEq = 1e30f;


                if (numEdges == 2)
                {
                    faceNormals[i] = IndexedVector3.Cross(edges[0], edges[1]);
                    faceNormals[i].Normalize();
                    m_polyhedron.m_faces[i].m_plane[0] = -faceNormals[i].X;
                    m_polyhedron.m_faces[i].m_plane[1] = -faceNormals[i].Y;
                    m_polyhedron.m_faces[i].m_plane[2] = -faceNormals[i].Z;
                    m_polyhedron.m_faces[i].m_plane[3] = planeEq;

                }
                else
                {
                    Debug.Assert(false);//degenerate?
                    faceNormals[i] = IndexedVector3.Zero;
                }

                for (int v = 0; v < m_polyhedron.m_faces[i].m_indices.Count; v++)
                {
                    float eq = IndexedVector3.Dot(m_polyhedron.m_vertices[m_polyhedron.m_faces[i].m_indices[v]], faceNormals[i]);
                    if (planeEq > eq)
                    {
                        planeEq = eq;
                    }
                }
                m_polyhedron.m_faces[i].m_plane[3] = planeEq;
//.........这里部分代码省略.........
开发者ID:JohnLouderback,项目名称:illuminati-engine-xna,代码行数:101,代码来源:PolyhedralConvexShape.cs

示例12: SolveConstraints

		protected virtual void SolveConstraints(ContactSolverInfo solverInfo)
		{
			//sorted version of all btTypedConstraint, based on islandId
			ObjectArray<TypedConstraint> sortedConstraints = new ObjectArray<TypedConstraint>(GetNumConstraints());

			if (BulletGlobals.g_streamWriter != null && debugDiscreteDynamicsWorld)
			{
				BulletGlobals.g_streamWriter.WriteLine("solveConstraints");
			}


			for (int i = 0; i < GetNumConstraints(); i++)
			{
				sortedConstraints.Add(m_constraints[i]);
			}

			//	btAssert(0);

			//sortedConstraints.quickSort(btSortConstraintOnIslandPredicate());
			sortedConstraints.Sort(new SortConstraintOnIslandPredicate());

			ObjectArray<TypedConstraint> constraintsPtr = GetNumConstraints() > 0 ? sortedConstraints : null;

			InplaceSolverIslandCallback solverCallback = new InplaceSolverIslandCallback(solverInfo, m_constraintSolver, constraintsPtr, sortedConstraints.Count, m_debugDrawer, m_dispatcher1);

			if (BulletGlobals.g_streamWriter != null && debugDiscreteDynamicsWorld)
			{
				BulletGlobals.g_streamWriter.WriteLine("prepareSolve");
			}

			m_constraintSolver.PrepareSolve(GetCollisionWorld().GetNumCollisionObjects(), GetCollisionWorld().GetDispatcher().GetNumManifolds());

			if (BulletGlobals.g_streamWriter != null && debugDiscreteDynamicsWorld)
			{
				BulletGlobals.g_streamWriter.WriteLine("buildAndProcessIsland");
			}

			/// solve all the constraints for this island
			m_islandManager.BuildAndProcessIslands(GetCollisionWorld().GetDispatcher(), GetCollisionWorld(), solverCallback);

			solverCallback.ProcessConstraints();

			m_constraintSolver.AllSolved(solverInfo, m_debugDrawer);
		}
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:44,代码来源:DiscreteDynamicsWorld.cs

示例13: InternalProcessAllTriangles

		public virtual void	InternalProcessAllTriangles(IInternalTriangleIndexCallback callback,ref Vector3 aabbMin,ref Vector3 aabbMax)
        {
	        int numtotalphysicsverts = 0;
	        int part,graphicssubparts = GetNumSubParts();
	        Object vertexbase = null;
            Object indexbase = null;
	        int indexstride = 3;
	        PHY_ScalarType type = PHY_ScalarType.PHY_FLOAT;
	        PHY_ScalarType gfxindextype = PHY_ScalarType.PHY_INTEGER;
	        int stride = 0,numverts = 0 ,numtriangles = 0;

            ObjectArray<Vector3> triangle = new ObjectArray<Vector3>(3);
			// ugly.  - could do with either a static , or allowing these methods to take a list or a fixed array...		
			triangle.Add(Vector3.Zero);
			triangle.Add(Vector3.Zero);
			triangle.Add(Vector3.Zero);

	        float graphicsBase = 0f;

	        Vector3 meshScaling = GetScaling();

	        ///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
	        for (part=0;part<graphicssubparts ;part++)
	        {
		        getLockedReadOnlyVertexIndexBase(out vertexbase,out numverts,out type,out stride,out indexbase,out indexstride,out numtriangles,out gfxindextype,part);
		        numtotalphysicsverts+=numtriangles*3; //upper bound

		        switch (gfxindextype)
		        {
		        case PHY_ScalarType.PHY_INTEGER:
			        {
                        ObjectArray<int> indexList = (ObjectArray<int>)indexbase;
						//ObjectArray<float> vertexList = (ObjectArray<float>)vertexbase;

						// hack for now - need to tidy this..

						if (vertexbase is ObjectArray<Vector3>)
						{
                            ObjectArray<Vector3> vertexList = (ObjectArray<Vector3>)vertexbase;
							for (int gfxindex = 0; gfxindex < numtriangles; gfxindex++)
							{
								// FIXME - Work ref the properindexing on this.
								int index = gfxindex * indexstride;
								int triIndex = (gfxindex * indexstride);

								triangle[0] = vertexList[indexList[triIndex]] * meshScaling;
								triangle[1] = vertexList[indexList[triIndex+1]] * meshScaling;
								triangle[2] = vertexList[indexList[triIndex+2]] * meshScaling;


								callback.InternalProcessTriangleIndex(triangle, part, gfxindex);
							}
						}
                        else if (vertexbase is ObjectArray<float>)
						{
							//triangle[0] = new Vector3(vertexList[indexList[triIndex]] * meshScaling.X, vertexList[indexList[triIndex + 1]] * meshScaling.Y, vertexList[indexList[triIndex + 2]] * meshScaling.Z);
							//triangle[1] = new Vector3(vertexList[indexList[triIndex]] * meshScaling.X, vertexList[indexList[triIndex + 1]] * meshScaling.Y, vertexList[indexList[triIndex + 2]] * meshScaling.Z);
							//triangle[2] = new Vector3(vertexList[indexList[triIndex]] * meshScaling.X, vertexList[indexList[triIndex + 1]] * meshScaling.Y, vertexList[indexList[triIndex + 2]] * meshScaling.Z);
							ObjectArray<float> vertexList = (ObjectArray<float>)vertexbase;
							for (int gfxindex = 0; gfxindex < numtriangles; gfxindex++)
							{
								// FIXME - Work ref the properindexing on this.
								int index = gfxindex * indexstride;
								int triIndex = (gfxindex * indexstride);

								// ugly!!
								triangle[0] = new Vector3(vertexList[indexList[triIndex]], vertexList[indexList[triIndex] + 1], vertexList[indexList[triIndex] + 2]) * meshScaling;
								triangle[1] = new Vector3(vertexList[indexList[triIndex+1]], vertexList[indexList[triIndex+1] + 1], vertexList[indexList[triIndex+1] + 2]) * meshScaling;
								triangle[2] = new Vector3(vertexList[indexList[triIndex+2]], vertexList[indexList[triIndex+2] + 1], vertexList[indexList[triIndex+2] + 2]) * meshScaling;
								callback.InternalProcessTriangleIndex(triangle, part, gfxindex);
							}


						}
						else
						{
							Debug.Assert(false); // unsupported type ....
						}
				        break;
			        }
		        case PHY_ScalarType.PHY_SHORT:
			        {
                        ObjectArray<ushort> indexList = (ObjectArray<ushort>)indexbase;

                        if (vertexbase is ObjectArray<Vector3>)
						{
							ObjectArray<Vector3> vertexList = (ObjectArray<Vector3>)vertexbase;
							for (int gfxindex = 0; gfxindex < numtriangles; gfxindex++)
							{
								// FIXME - Work ref the properindexing on this.
								int index = gfxindex * indexstride;
								int triIndex = (gfxindex * indexstride);

								triangle[0] = vertexList[indexList[triIndex]] * meshScaling;
								triangle[1] = vertexList[indexList[triIndex + 1]] * meshScaling;
								triangle[2] = vertexList[indexList[triIndex + 2]] * meshScaling;


								callback.InternalProcessTriangleIndex(triangle, part, gfxindex);
							}
//.........这里部分代码省略.........
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:101,代码来源:StridingMeshInterface.cs

示例14: ResizeSolverConstraintList

		public static void ResizeSolverConstraintList(ObjectArray<SolverConstraint> list, int newSize)
		{
			int listSize = list.Count;
			int sizeDiff = newSize - listSize;
			// grow if needed
			if (listSize < newSize)
			{
				for (int i = 0; i < sizeDiff; ++i)
				{
					list.Add(new SolverConstraint());
				}
			}
			else
			{
				// Trim down
				for (int i = sizeDiff; i < 0; ++i)
				{
					list.RemoveAt(list.Count - 1);
				}
			}
		}
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:21,代码来源:SequentialImpulseConstraintSolver.cs

示例15: ClipFace

        ///the clipFace method is used internally
        public static void ClipFace(ObjectArray<IndexedVector3> pVtxIn, ObjectArray<IndexedVector3> ppVtxOut, ref IndexedVector3 planeNormalWS, float planeEqWS)
        {
            int ve;
            float ds, de;
            int numVerts = pVtxIn.Count;
            if (numVerts < 2)
                return;

            IndexedVector3 firstVertex = pVtxIn[pVtxIn.Count - 1];
            IndexedVector3 endVertex = pVtxIn[0];

            ds = IndexedVector3.Dot(ref planeNormalWS, ref firstVertex);
            ds += planeEqWS;

            for (ve = 0; ve < numVerts; ve++)
            {
                endVertex = pVtxIn[ve];

                de = IndexedVector3.Dot(ref planeNormalWS, ref endVertex);
                de += planeEqWS;

                if (ds < 0)
                {
                    if (de < 0)
                    {
                        // Start < 0, end < 0, so output endVertex
                        ppVtxOut.Add(endVertex);
                    }
                    else
                    {
                        // Start < 0, end >= 0, so output intersection
                        ppVtxOut.Add(MathUtil.Vector3Lerp(ref firstVertex, ref endVertex, (float)(ds * 1.0f / (ds - de))));
                    }
                }
                else
                {
                    if (de < 0)
                    {
                        // Start >= 0, end < 0 so output intersection and end
                        ppVtxOut.Add(MathUtil.Vector3Lerp(ref firstVertex, ref endVertex, (float)(ds * 1.0f / (ds - de))));
                        ppVtxOut.Add(endVertex);
                    }
                }
                firstVertex = endVertex;
                ds = de;
            }

        }
开发者ID:ousttrue,项目名称:bullet-xna,代码行数:49,代码来源:PolyhedralContactClipping.cs


注:本文中的ObjectArray.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。