Search in sources :

Example 41 with Stack

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

the class CompoundShape method addChildShape.

public void addChildShape(Transform localTransform, CollisionShape shape) {
    //m_childTransforms.push_back(localTransform);
    //m_childShapes.push_back(shape);
    CompoundShapeChild child = new CompoundShapeChild();
    child.transform.set(localTransform);
    child.childShape = shape;
    child.childShapeType = shape.getShapeType();
    child.childMargin = shape.getMargin();
    children.add(child);
    Stack stack = Stack.enter();
    // extend the local aabbMin/aabbMax
    Vector3f _localAabbMin = stack.allocVector3f(), _localAabbMax = stack.allocVector3f();
    shape.getAabb(localTransform, _localAabbMin, _localAabbMax);
    // JAVA NOTE: rewritten
    //		for (int i=0;i<3;i++)
    //		{
    //			if (this.localAabbMin[i] > _localAabbMin[i])
    //			{
    //				this.localAabbMin[i] = _localAabbMin[i];
    //			}
    //			if (this.localAabbMax[i] < _localAabbMax[i])
    //			{
    //				this.localAabbMax[i] = _localAabbMax[i];
    //			}
    //		}
    VectorUtil.setMin(this.localAabbMin, _localAabbMin);
    VectorUtil.setMax(this.localAabbMax, _localAabbMax);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 42 with Stack

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

the class ConeShape method localGetSupportingVertex.

@Override
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
    Vector3f supVertex = coneLocalSupport(vec, out);
    if (getMargin() != 0f) {
        Stack stack = Stack.enter();
        Vector3f vecnorm = stack.alloc(vec);
        if (vecnorm.lengthSquared() < (BulletGlobals.FLT_EPSILON * BulletGlobals.FLT_EPSILON)) {
            vecnorm.set(-1f, -1f, -1f);
        }
        vecnorm.normalize();
        supVertex.scaleAdd(getMargin(), vecnorm, supVertex);
        stack.leave();
    }
    return supVertex;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 43 with Stack

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

the class ConeShape method calculateLocalInertia.

@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
    Stack stack = Stack.enter();
    Transform identity = stack.allocTransform();
    identity.setIdentity();
    Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
    getAabb(identity, aabbMin, aabbMax);
    Vector3f halfExtents = stack.allocVector3f();
    halfExtents.sub(aabbMax, aabbMin);
    halfExtents.scale(0.5f);
    float margin = getMargin();
    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);
    //inertia.x() = scaledmass * (y2+z2);
    //inertia.y() = scaledmass * (x2+z2);
    //inertia.z() = scaledmass * (x2+y2);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 44 with Stack

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

the class ConvexHullShape method localGetSupportingVertex.

@Override
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
    Vector3f supVertex = localGetSupportingVertexWithoutMargin(vec, out);
    if (getMargin() != 0f) {
        Stack stack = Stack.enter();
        Vector3f vecnorm = stack.alloc(vec);
        if (vecnorm.lengthSquared() < (BulletGlobals.FLT_EPSILON * BulletGlobals.FLT_EPSILON)) {
            vecnorm.set(-1f, -1f, -1f);
        }
        vecnorm.normalize();
        supVertex.scaleAdd(getMargin(), vecnorm, supVertex);
        stack.leave();
    }
    return out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 45 with Stack

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

the class ConvexHullShape method localGetSupportingVertexWithoutMargin.

@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
    Vector3f supVec = out;
    supVec.set(0f, 0f, 0f);
    float newDot, maxDot = -1e30f;
    Stack stack = Stack.enter();
    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();
    for (int i = 0; i < points.size(); i++) {
        VectorUtil.mul(vtx, points.getQuick(i), localScaling);
        newDot = vec.dot(vtx);
        if (newDot > maxDot) {
            maxDot = newDot;
            supVec.set(vtx);
        }
    }
    stack.leave();
    return out;
}
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