Search in sources :

Example 1 with TriangleShape

use of com.bulletphysics.collision.shapes.TriangleShape in project bdx by GoranM.

the class TriangleConvexcastCallback method processTriangle.

public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) {
    TriangleShape triangleShape = new TriangleShape(triangle[0], triangle[1], triangle[2]);
    triangleShape.setMargin(triangleCollisionMargin);
    VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
    GjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver = new GjkEpaPenetrationDepthSolver();
    //#define  USE_SUBSIMPLEX_CONVEX_CAST 1
    //if you reenable USE_SUBSIMPLEX_CONVEX_CAST see commented out code below
    //#ifdef USE_SUBSIMPLEX_CONVEX_CAST
    // TODO: implement ContinuousConvexCollision
    SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(convexShape, triangleShape, simplexSolver);
    //#else
    // //btGjkConvexCast	convexCaster(m_convexShape,&triangleShape,&simplexSolver);
    //btContinuousConvexCollision convexCaster(m_convexShape,&triangleShape,&simplexSolver,&gjkEpaPenetrationSolver);
    //#endif //#USE_SUBSIMPLEX_CONVEX_CAST
    CastResult castResult = new CastResult();
    castResult.fraction = 1f;
    if (convexCaster.calcTimeOfImpact(convexShapeFrom, convexShapeTo, triangleToWorld, triangleToWorld, castResult)) {
        // add hit
        if (castResult.normal.lengthSquared() > 0.0001f) {
            if (castResult.fraction < hitFraction) {
                /* btContinuousConvexCast's normal is already in world space */
                /*
					//#ifdef USE_SUBSIMPLEX_CONVEX_CAST
					// rotate normal into worldspace
					convexShapeFrom.basis.transform(castResult.normal);
					//#endif //USE_SUBSIMPLEX_CONVEX_CAST
					*/
                castResult.normal.normalize();
                reportHit(castResult.normal, castResult.hitPoint, castResult.fraction, partId, triangleIndex);
            }
        }
    }
}
Also used : TriangleShape(com.bulletphysics.collision.shapes.TriangleShape) CastResult(com.bulletphysics.collision.narrowphase.ConvexCast.CastResult)

Aggregations

CastResult (com.bulletphysics.collision.narrowphase.ConvexCast.CastResult)1 TriangleShape (com.bulletphysics.collision.shapes.TriangleShape)1