Package com.bulletphysics.collision.shapes

Examples of com.bulletphysics.collision.shapes.ConvexShape


            break;
          }
          default: {
            if (shape.isConvex())
            {
              ConvexShape convexShape = (ConvexShape)shape;
              if (shape.getUserPointer() == null)
              {
                // create a hull approximation
                ShapeHull hull = new ShapeHull(convexShape);

                // JAVA NOTE: not needed
                ///// cleanup memory
                //m_shapeHulls.push_back(hull);

                float margin = shape.getMargin();
                hull.buildHull(margin);
                convexShape.setUserPointer(hull);

                //printf("numTriangles = %d\n", hull->numTriangles ());
                //printf("numIndices = %d\n", hull->numIndices ());
                //printf("numVertices = %d\n", hull->numVertices ());
              }
View Full Code Here


    ghostObject = new PairCachingGhostObject();
    ghostObject.setWorldTransform(startTransform);
    sweepBP.getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback());
    float characterHeight = 1.75f * characterScale;
    float characterWidth = 1.75f * characterScale;
    ConvexShape capsule = new CapsuleShape(characterWidth, characterHeight);
    ghostObject.setCollisionShape(capsule);
    ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);

    float stepHeight = 0.35f * characterScale;
    character = new KinematicCharacterController(ghostObject, capsule, stepHeight);
View Full Code Here

      CollisionShape collisionShape,
      Transform colObjWorldTransform,
      RayResultCallback resultCallback) {
    SphereShape pointShape = new SphereShape(0f);
    pointShape.setMargin(0f);
    ConvexShape castShape = pointShape;

    if (collisionShape.isConvex()) {
      CastResult castResult = new CastResult();
      castResult.fraction = resultCallback.closestHitFraction;

      ConvexShape convexShape = (ConvexShape) collisionShape;
      VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();

      //#define USE_SUBSIMPLEX_CONVEX_CAST 1
      //#ifdef USE_SUBSIMPLEX_CONVEX_CAST
      SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(castShape, convexShape, simplexSolver);
View Full Code Here

    if (collisionShape.isConvex()) {
      CastResult castResult = new CastResult();
      castResult.allowedPenetration = allowedPenetration;
      castResult.fraction = 1f; // ??

      ConvexShape convexShape = (ConvexShape) collisionShape;
      VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
      GjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver = new GjkEpaPenetrationDepthSolver();

      // JAVA TODO: should be convexCaster1
      //ContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver);
View Full Code Here

//      dispatchInfo.m_debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0));
//      resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth);
//      }
//  #else

    ConvexShape min0 = (ConvexShape) body0.getCollisionShape();
    ConvexShape min1 = (ConvexShape) body1.getCollisionShape();

    ClosestPointInput input = pointInputsPool.get();
    input.init();

    // JAVA NOTE: original: TODO: if (dispatchInfo.m_useContinuous)
    gjkPairDetector.setMinkowskiA(min0);
    gjkPairDetector.setMinkowskiB(min1);
    input.maximumDistanceSquared = min0.getMargin() + min1.getMargin() + manifoldPtr.getContactBreakingThreshold();
    input.maximumDistanceSquared *= input.maximumDistanceSquared;
    //input.m_stackAlloc = dispatchInfo.m_stackAllocator;

    //  input.m_maximumDistanceSquared = btScalar(1e30);

View Full Code Here

    // For proper CCD, better accuracy and handling of 'allowed' penetration should be added
    // also the mainloop of the physics should have a kind of toi queue (something like Brian Mirtich's application of Timewarp for Rigidbodies)

    // Convex0 against sphere for Convex1
    {
      ConvexShape convex0 = (ConvexShape) col0.getCollisionShape();

      SphereShape sphere1 = new SphereShape(col1.getCcdSweptSphereRadius()); // todo: allow non-zero sphere sizes, for better approximation
      ConvexCast.CastResult result = new ConvexCast.CastResult();
      VoronoiSimplexSolver voronoiSimplex = new VoronoiSimplexSolver();
      //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
      ///Simplification, one object is simplified as a sphere
      GjkConvexCast ccd1 = new GjkConvexCast(convex0, sphere1, voronoiSimplex);
      //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
      if (ccd1.calcTimeOfImpact(col0.getWorldTransform(tmpTrans1), col0.getInterpolationWorldTransform(tmpTrans2),
          col1.getWorldTransform(tmpTrans3), col1.getInterpolationWorldTransform(tmpTrans4), result)) {
        // store result.m_fraction in both bodies

        if (col0.getHitFraction() > result.fraction) {
          col0.setHitFraction(result.fraction);
        }

        if (col1.getHitFraction() > result.fraction) {
          col1.setHitFraction(result.fraction);
        }

        if (resultFraction > result.fraction) {
          resultFraction = result.fraction;
        }
      }
    }

    // Sphere (for convex0) against Convex1
    {
      ConvexShape convex1 = (ConvexShape) col1.getCollisionShape();

      SphereShape sphere0 = new SphereShape(col0.getCcdSweptSphereRadius()); // todo: allow non-zero sphere sizes, for better approximation
      ConvexCast.CastResult result = new ConvexCast.CastResult();
      VoronoiSimplexSolver voronoiSimplex = new VoronoiSimplexSolver();
      //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
View Full Code Here

    Transform tmpTrans = Stack.alloc(Transform.class);

    CollisionObject convexObj = isSwapped ? body1 : body0;
    CollisionObject planeObj = isSwapped ? body0 : body1;

    ConvexShape convexShape = (ConvexShape) convexObj.getCollisionShape();
    StaticPlaneShape planeShape = (StaticPlaneShape) planeObj.getCollisionShape();

    boolean hasCollision = false;
    Vector3f planeNormal = planeShape.getPlaneNormal(Stack.alloc(Vector3f.class));
    float planeConstant = planeShape.getPlaneConstant();

    Transform planeInConvex = Stack.alloc(Transform.class);
    convexObj.getWorldTransform(planeInConvex);
    planeInConvex.inverse();
    planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));

    Transform convexInPlaneTrans = Stack.alloc(Transform.class);
    convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
    convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));

    Vector3f tmp = Stack.alloc(Vector3f.class);
    tmp.negate(planeNormal);
    planeInConvex.basis.transform(tmp);

    Vector3f vtx = convexShape.localGetSupportingVertex(tmp, Stack.alloc(Vector3f.class));
    Vector3f vtxInPlane = Stack.alloc(vtx);
    convexInPlaneTrans.transform(vtxInPlane);

    float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
View Full Code Here

     * @param entity the entity to create a trigger for.
     */
    private boolean newTrigger(EntityRef entity) {
        LocationComponent location = entity.getComponent(LocationComponent.class);
        TriggerComponent trigger = entity.getComponent(TriggerComponent.class);
        ConvexShape shape = getShapeFor(entity);
        if (shape != null && location != null && trigger != null) {
            float scale = location.getWorldScale();
            shape.setLocalScaling(new Vector3f(scale, scale, scale));
            List<CollisionGroup> detectGroups = Lists.newArrayList(trigger.detectGroups);
            PairCachingGhostObject triggerObj = createCollider(
                    location.getWorldPosition(),
                    shape,
                    StandardCollisionGroup.SENSOR.getFlag(),
View Full Code Here

        }
        Vector3f pos = locComp.getWorldPosition();
        final float worldScale = locComp.getWorldScale();
        final float height = (movementComp.height - 2 * movementComp.radius) * worldScale;
        final float width = movementComp.radius * worldScale;
        ConvexShape shape = new CapsuleShape(width, height);
        shape.setMargin(0.1f);
        return createCustomCollider(pos, shape, movementComp.collisionGroup.getFlag(), combineGroups(movementComp.collidesWith),
                CollisionFlags.CHARACTER_OBJECT, owner);
    }
View Full Code Here

    }

    private RigidBody newRigidBody(EntityRef entity) {
        LocationComponent location = entity.getComponent(LocationComponent.class);
        RigidBodyComponent rigidBody = entity.getComponent(RigidBodyComponent.class);
        ConvexShape shape = getShapeFor(entity);
        if (location != null && rigidBody != null && shape != null) {
            float scale = location.getWorldScale();
            shape.setLocalScaling(new Vector3f(scale, scale, scale));

            if (rigidBody.mass < 1) {
                logger.warn("RigidBodyComponent.mass is set to less than 1.0, this can lead to strange behaviour, such as the objects moving through walls. " +
                        "Entity: {}", entity);
            }
            Vector3f fallInertia = new Vector3f();
            shape.calculateLocalInertia(rigidBody.mass, fallInertia);

            RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(rigidBody.mass, new EntityMotionState(entity), shape, fallInertia);
            BulletRigidBody collider = new BulletRigidBody(info);
            collider.rb.setUserPointer(entity);
            collider.rb.setAngularFactor(rigidBody.angularFactor);
View Full Code Here

TOP

Related Classes of com.bulletphysics.collision.shapes.ConvexShape

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.