示例#1
0
            public void ProcessTriangle(Vector3[] triangle, int partId, int triangleIndex)
            {
                //do a swept sphere for now
                Matrix     ident      = Matrix.Identity;
                CastResult castResult = new CastResult();

                castResult.Fraction = _hitFraction;
                SphereShape          pointShape    = new SphereShape(_ccdSphereRadius);
                TriangleShape        triShape      = new TriangleShape(triangle[0], triangle[1], triangle[2]);
                VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
                SubsimplexConvexCast convexCaster  = new SubsimplexConvexCast(pointShape, triShape, simplexSolver);

                //GjkConvexCast	convexCaster(&pointShape,convexShape,&simplexSolver);
                //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
                //local space?

                if (convexCaster.CalcTimeOfImpact(_ccdSphereFromTrans, _ccdSphereToTrans,
                                                  ident, ident, castResult))
                {
                    if (_hitFraction > castResult.Fraction)
                    {
                        _hitFraction = castResult.Fraction;
                    }
                }
            }
        public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex)
        {
            //aabb filter is already applied!
            CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo = new CollisionAlgorithmConstructionInfo();

            collisionAlgorithmConstructionInfo.Dispatcher = _dispatcher;

            CollisionObject collisionObject = _triBody;

            //debug drawing of the overlapping triangles

            /*if (m_dispatchInfoPtr && m_dispatchInfoPtr.m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0)
             * {
             *      Vector3 color = new Vector3(255, 255, 0);
             *      btTransform & tr = ob->WorldTransform;
             *      m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]), tr(triangle[1]), color);
             *      m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]), tr(triangle[2]), color);
             *      m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]), tr(triangle[0]), color);
             * }*/

            if (_convexBody.CollisionShape.IsConvex)
            {
                TriangleShape triangleShape = new TriangleShape(triangle[0], triangle[1], triangle[2]);
                triangleShape.Margin = _collisionMarginTriangle;

                CollisionShape tempShape = collisionObject.CollisionShape;
                collisionObject.CollisionShape = triangleShape;

                CollisionAlgorithm collisionAlgorithm = collisionAlgorithmConstructionInfo.Dispatcher.FindAlgorithm(_convexBody, _triBody, _manifold);

                _resultOut.SetShapeIdentifiers(-1, -1, partID, triangleIndex);
                collisionAlgorithm.ProcessCollision(_convexBody, _triBody, _dispatchInfo, _resultOut);
                collisionObject.CollisionShape = tempShape;
            }
        }
        public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
        {
            if (_manifold == null)
            {
                return;
            }

            SphereShape   sphere   = bodyA.CollisionShape as SphereShape;
            TriangleShape triangle = bodyB.CollisionShape as TriangleShape;

            /// report a contact. internally this will be kept persistent, and contact reduction is done
            resultOut.SetPersistentManifold(_manifold);
            SphereTriangleDetector detector = new SphereTriangleDetector(sphere, triangle);

            DiscreteCollisionDetectorInterface.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput();
            input.MaximumDistanceSquared = 1e30f;            //todo: tighter bounds
            input.TransformA             = bodyA.WorldTransform;
            input.TransformB             = bodyB.WorldTransform;

            detector.GetClosestPoints(input, resultOut, null);
        }
示例#4
0
 public SphereTriangleDetector(SphereShape sphere, TriangleShape triangle)
 {
     this._sphere = sphere;
     this._triangle = triangle;
 }
		public void ProcessTriangle(Vector3[] triangle, int partID, int triangleIndex)
		{
			//aabb filter is already applied!	
			CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo = new CollisionAlgorithmConstructionInfo();
			collisionAlgorithmConstructionInfo.Dispatcher = _dispatcher;

			CollisionObject collisionObject = _triBody;

			//debug drawing of the overlapping triangles
			/*if (m_dispatchInfoPtr && m_dispatchInfoPtr.m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0)
			{
				Vector3 color = new Vector3(255, 255, 0);
				btTransform & tr = ob->WorldTransform;
				m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]), tr(triangle[1]), color);
				m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]), tr(triangle[2]), color);
				m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]), tr(triangle[0]), color);
			}*/

			if (_convexBody.CollisionShape.IsConvex)
			{
				TriangleShape triangleShape = new TriangleShape(triangle[0], triangle[1], triangle[2]);
				triangleShape.Margin=_collisionMarginTriangle;

				CollisionShape tempShape = collisionObject.CollisionShape;
				collisionObject.CollisionShape = triangleShape;

				CollisionAlgorithm collisionAlgorithm = collisionAlgorithmConstructionInfo.Dispatcher.FindAlgorithm(_convexBody, _triBody, _manifold);

				_resultOut.SetShapeIdentifiers(-1, -1, partID, triangleIndex);
				collisionAlgorithm.ProcessCollision(_convexBody, _triBody, _dispatchInfo, _resultOut);
				collisionObject.CollisionShape = tempShape;
			}
		}
示例#6
0
 public SphereTriangleDetector(SphereShape sphere, TriangleShape triangle)
 {
     this._sphere   = sphere;
     this._triangle = triangle;
 }
			public void ProcessTriangle(Vector3[] triangle, int partId, int triangleIndex)
			{
				//do a swept sphere for now
				Matrix ident = Matrix.Identity;
				CastResult castResult = new CastResult();
				castResult.Fraction = _hitFraction;
				SphereShape pointShape = new SphereShape(_ccdSphereRadius);
				TriangleShape triShape = new TriangleShape(triangle[0], triangle[1], triangle[2]);
				VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
				SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(pointShape, triShape, simplexSolver);
				//GjkConvexCast	convexCaster(&pointShape,convexShape,&simplexSolver);
				//ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
				//local space?

				if (convexCaster.CalcTimeOfImpact(_ccdSphereFromTrans, _ccdSphereToTrans,
					ident, ident, castResult))
				{
					if (_hitFraction > castResult.Fraction)
						_hitFraction = castResult.Fraction;
				}
			}