Search in sources :

Example 56 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class PolyhedralConvexShape method calculateLocalInertia.

@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
    // not yet, return box inertia
    Stack stack = Stack.enter();
    float margin = getMargin();
    Transform ident = stack.allocTransform();
    ident.setIdentity();
    Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
    getAabb(ident, aabbMin, aabbMax);
    Vector3f halfExtents = stack.allocVector3f();
    halfExtents.sub(aabbMax, aabbMin);
    halfExtents.scale(0.5f);
    float lx = 2f * (halfExtents.x + margin);
    float ly = 2f * (halfExtents.y + margin);
    float lz = 2f * (halfExtents.z + margin);
    float x2 = lx * lx;
    float y2 = ly * ly;
    float z2 = lz * lz;
    float scaledmass = mass * 0.08333333f;
    inertia.set(y2 + z2, x2 + z2, x2 + y2);
    inertia.scale(scaledmass);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 57 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class PolyhedralConvexShape method localGetSupportingVertexWithoutMargin.

//	/** optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp */
//	public Hull optionalHull = null;
@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
    int i;
    Stack stack = Stack.enter();
    Vector3f supVec = out;
    supVec.set(0f, 0f, 0f);
    float maxDot = -1e30f;
    Vector3f vec = stack.alloc(vec0);
    float lenSqr = vec.lengthSquared();
    if (lenSqr < 0.0001f) {
        vec.set(1f, 0f, 0f);
    } else {
        float rlen = 1f / (float) Math.sqrt(lenSqr);
        vec.scale(rlen);
    }
    Vector3f vtx = stack.allocVector3f();
    float newDot;
    for (i = 0; i < getNumVertices(); i++) {
        getVertex(i, vtx);
        newDot = vec.dot(vtx);
        if (newDot > maxDot) {
            maxDot = newDot;
            supVec = vtx;
        }
    }
    stack.leave();
    return out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 58 with Stack

use of com.bulletphysics.util.Stack 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 59 with Stack

use of com.bulletphysics.util.Stack 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 60 with Stack

use of com.bulletphysics.util.Stack 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)

Aggregations

Stack (com.bulletphysics.util.Stack)252 Vector3f (javax.vecmath.Vector3f)197 Transform (com.bulletphysics.linearmath.Transform)65 Matrix3f (javax.vecmath.Matrix3f)23 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)15 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)15 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)10 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)10 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)10 Vector4f (javax.vecmath.Vector4f)8 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)6 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)5 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 RigidBody (com.bulletphysics.dynamics.RigidBody)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3