Search in sources :

Example 61 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class ShapeHull method buildHull.

public boolean buildHull(float margin) {
    Stack stack = Stack.enter();
    Vector3f norm = stack.allocVector3f();
    int numSampleDirections = NUM_UNITSPHERE_POINTS;
    {
        int numPDA = shape.getNumPreferredPenetrationDirections();
        if (numPDA != 0) {
            for (int i = 0; i < numPDA; i++) {
                shape.getPreferredPenetrationDirection(i, norm);
                unitSpherePoints.getQuick(numSampleDirections).set(norm);
                numSampleDirections++;
            }
        }
    }
    ObjectArrayList<Vector3f> supportPoints = new ObjectArrayList<Vector3f>();
    MiscUtil.resize(supportPoints, NUM_UNITSPHERE_POINTS + ConvexShape.MAX_PREFERRED_PENETRATION_DIRECTIONS * 2, Suppliers.NEW_VECTOR3F_SUPPLIER);
    for (int i = 0; i < numSampleDirections; i++) {
        shape.localGetSupportingVertex(unitSpherePoints.getQuick(i), supportPoints.getQuick(i));
    }
    HullDesc hd = new HullDesc();
    hd.flags = HullFlags.TRIANGLES;
    hd.vcount = numSampleDirections;
    //#ifdef BT_USE_DOUBLE_PRECISION
    //hd.mVertices = &supportPoints[0];
    //hd.mVertexStride = sizeof(btVector3);
    //#else
    hd.vertices = supportPoints;
    //hd.vertexStride = 3 * 4;
    //#endif
    HullLibrary hl = new HullLibrary();
    HullResult hr = new HullResult();
    if (!hl.createConvexHull(hd, hr)) {
        stack.leave();
        return false;
    }
    MiscUtil.resize(vertices, hr.numOutputVertices, Suppliers.NEW_VECTOR3F_SUPPLIER);
    for (int i = 0; i < hr.numOutputVertices; i++) {
        vertices.getQuick(i).set(hr.outputVertices.getQuick(i));
    }
    numIndices = hr.numIndices;
    MiscUtil.resize(indices, numIndices, 0);
    for (int i = 0; i < numIndices; i++) {
        indices.set(i, hr.indices.get(i));
    }
    // free temporary hull result that we just copied
    hl.releaseResult(hr);
    stack.leave();
    return true;
}
Also used : ObjectArrayList(com.bulletphysics.util.ObjectArrayList) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 62 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class StaticPlaneShape method processAllTriangles.

@Override
public void processAllTriangles(TriangleCallback callback, Vector3f aabbMin, Vector3f aabbMax) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Vector3f tmp1 = stack.allocVector3f();
    Vector3f tmp2 = stack.allocVector3f();
    Vector3f halfExtents = stack.allocVector3f();
    halfExtents.sub(aabbMax, aabbMin);
    halfExtents.scale(0.5f);
    float radius = halfExtents.length();
    Vector3f center = stack.allocVector3f();
    center.add(aabbMax, aabbMin);
    center.scale(0.5f);
    // this is where the triangles are generated, given AABB and plane equation (normal/constant)
    Vector3f tangentDir0 = stack.allocVector3f(), tangentDir1 = stack.allocVector3f();
    // tangentDir0/tangentDir1 can be precalculated
    TransformUtil.planeSpace1(planeNormal, tangentDir0, tangentDir1);
    Vector3f supVertex0 = stack.allocVector3f(), supVertex1 = stack.allocVector3f();
    Vector3f projectedCenter = stack.allocVector3f();
    tmp.scale(planeNormal.dot(center) - planeConstant, planeNormal);
    projectedCenter.sub(center, tmp);
    Vector3f[] triangle = new Vector3f[] { stack.allocVector3f(), stack.allocVector3f(), stack.allocVector3f() };
    tmp1.scale(radius, tangentDir0);
    tmp2.scale(radius, tangentDir1);
    VectorUtil.add(triangle[0], projectedCenter, tmp1, tmp2);
    tmp1.scale(radius, tangentDir0);
    tmp2.scale(radius, tangentDir1);
    tmp.sub(tmp1, tmp2);
    VectorUtil.add(triangle[1], projectedCenter, tmp);
    tmp1.scale(radius, tangentDir0);
    tmp2.scale(radius, tangentDir1);
    tmp.sub(tmp1, tmp2);
    triangle[2].sub(projectedCenter, tmp);
    callback.processTriangle(triangle, 0, 0);
    tmp1.scale(radius, tangentDir0);
    tmp2.scale(radius, tangentDir1);
    tmp.sub(tmp1, tmp2);
    triangle[0].sub(projectedCenter, tmp);
    tmp1.scale(radius, tangentDir0);
    tmp2.scale(radius, tangentDir1);
    tmp.add(tmp1, tmp2);
    triangle[1].sub(projectedCenter, tmp);
    tmp1.scale(radius, tangentDir0);
    tmp2.scale(radius, tangentDir1);
    VectorUtil.add(triangle[2], projectedCenter, tmp1, tmp2);
    callback.processTriangle(triangle, 0, 1);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 63 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class StridingMeshInterface method internalProcessAllTriangles.

public void internalProcessAllTriangles(InternalTriangleIndexCallback callback, Vector3f aabbMin, Vector3f aabbMax) {
    Stack stack = Stack.enter();
    int graphicssubparts = getNumSubParts();
    Vector3f[] triangle = /*[3]*/
    new Vector3f[] { stack.allocVector3f(), stack.allocVector3f(), stack.allocVector3f() };
    Vector3f meshScaling = getScaling(stack.allocVector3f());
    for (int part = 0; part < graphicssubparts; part++) {
        VertexData data = getLockedReadOnlyVertexIndexBase(part);
        for (int i = 0, cnt = data.getIndexCount() / 3; i < cnt; i++) {
            data.getTriangle(i * 3, meshScaling, triangle);
            callback.internalProcessTriangleIndex(triangle, part, i);
        }
        unLockReadOnlyVertexBase(part);
    }
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 64 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class TriangleMeshShape method localGetSupportingVertex.

public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Vector3f supportVertex = out;
    Transform ident = stack.allocTransform();
    ident.setIdentity();
    SupportVertexCallback supportCallback = new SupportVertexCallback(vec, ident);
    Vector3f aabbMax = stack.allocVector3f();
    aabbMax.set(1e30f, 1e30f, 1e30f);
    tmp.negate(aabbMax);
    processAllTriangles(supportCallback, tmp, aabbMax);
    supportCallback.getSupportVertexLocal(supportVertex);
    stack.leave();
    return out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 65 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class DiscreteDynamicsWorld method updateActivationState.

protected void updateActivationState(float timeStep) {
    BulletStats.pushProfile("updateActivationState");
    Stack stack = Stack.enter();
    int sp = stack.getSp();
    try {
        Vector3f tmp = stack.allocVector3f();
        for (int i = 0; i < collisionObjects.size(); i++) {
            CollisionObject colObj = collisionObjects.getQuick(i);
            RigidBody body = RigidBody.upcast(colObj);
            if (body != null) {
                body.updateDeactivation(timeStep);
                if (body.wantsSleeping()) {
                    if (body.isStaticOrKinematicObject()) {
                        body.setActivationState(CollisionObject.ISLAND_SLEEPING);
                    } else {
                        if (body.getActivationState() == CollisionObject.ACTIVE_TAG) {
                            body.setActivationState(CollisionObject.WANTS_DEACTIVATION);
                        }
                        if (body.getActivationState() == CollisionObject.ISLAND_SLEEPING) {
                            tmp.set(0f, 0f, 0f);
                            body.setAngularVelocity(tmp);
                            body.setLinearVelocity(tmp);
                        }
                    }
                } else {
                    if (body.getActivationState() != CollisionObject.DISABLE_DEACTIVATION) {
                        body.setActivationState(CollisionObject.ACTIVE_TAG);
                    }
                }
            }
        }
    } finally {
        stack.leave(sp);
        BulletStats.popProfile();
    }
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Vector3f(javax.vecmath.Vector3f) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Aggregations

Vector3f (javax.vecmath.Vector3f)266 Stack (com.bulletphysics.util.Stack)197 Transform (com.bulletphysics.linearmath.Transform)53 Matrix3f (javax.vecmath.Matrix3f)25 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)14 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 Matrix4f (javax.vecmath.Matrix4f)10 Vector4f (javax.vecmath.Vector4f)8 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)7 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)6 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 SphereShape (com.bulletphysics.collision.shapes.SphereShape)4 RigidBody (com.bulletphysics.dynamics.RigidBody)4 HashMap (java.util.HashMap)4 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)3 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3