Search in sources :

Example 91 with Vector3f

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

the class WheelInfo method updateWheel.

public void updateWheel(RigidBody chassis, RaycastInfo raycastInfo) {
    if (raycastInfo.isInContact) {
        Stack stack = Stack.enter();
        float project = raycastInfo.contactNormalWS.dot(raycastInfo.wheelDirectionWS);
        Vector3f chassis_velocity_at_contactPoint = stack.allocVector3f();
        Vector3f relpos = stack.allocVector3f();
        relpos.sub(raycastInfo.contactPointWS, chassis.getCenterOfMassPosition(stack.allocVector3f()));
        chassis.getVelocityInLocalPoint(relpos, chassis_velocity_at_contactPoint);
        float projVel = raycastInfo.contactNormalWS.dot(chassis_velocity_at_contactPoint);
        if (project >= -0.1f) {
            suspensionRelativeVelocity = 0f;
            clippedInvContactDotSuspension = 1f / 0.1f;
        } else {
            float inv = -1f / project;
            suspensionRelativeVelocity = projVel * inv;
            clippedInvContactDotSuspension = inv;
        }
        stack.leave();
    } else {
        // Not in contact : position wheel in a nice (rest length) position
        raycastInfo.suspensionLength = getSuspensionRestLength();
        suspensionRelativeVelocity = 0f;
        raycastInfo.contactNormalWS.negate(raycastInfo.wheelDirectionWS);
        clippedInvContactDotSuspension = 1f;
    }
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 92 with Vector3f

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

the class GImpactCollisionAlgorithm method gimpact_vs_concave.

public void gimpact_vs_concave(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, ConcaveShape shape1, boolean swapped) {
    // create the callback
    GImpactTriangleCallback tricallback = new GImpactTriangleCallback();
    tricallback.algorithm = this;
    tricallback.body0 = body0;
    tricallback.body1 = body1;
    tricallback.gimpactshape0 = shape0;
    tricallback.swapped = swapped;
    tricallback.margin = shape1.getMargin();
    // getting the trimesh AABB
    Stack stack = Stack.enter();
    Transform gimpactInConcaveSpace = stack.allocTransform();
    body1.getWorldTransform(gimpactInConcaveSpace);
    gimpactInConcaveSpace.inverse();
    gimpactInConcaveSpace.mul(body0.getWorldTransform(stack.allocTransform()));
    Vector3f minAABB = stack.allocVector3f(), maxAABB = stack.allocVector3f();
    shape0.getAabb(gimpactInConcaveSpace, minAABB, maxAABB);
    shape1.processAllTriangles(tricallback, minAABB, maxAABB);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 93 with Vector3f

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

the class GImpactCollisionAlgorithm method gimpacttrimeshpart_vs_plane_collision.

protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
    Stack stack = Stack.enter();
    Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
    Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
    StaticPlaneShape planeshape = shape1;
    Vector4f plane = stack.allocVector4f();
    PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
    // test box against plane
    AABB tribox = stack.allocAABB();
    shape0.getAabb(orgtrans0, tribox.min, tribox.max);
    tribox.increment_margin(planeshape.getMargin());
    if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
        return;
    }
    shape0.lockChildShapes();
    float margin = shape0.getMargin() + planeshape.getMargin();
    Vector3f vertex = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    int vi = shape0.getVertexCount();
    while ((vi--) != 0) {
        shape0.getVertex(vi, vertex);
        orgtrans0.transform(vertex);
        float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
        if (//add contact
        distance < 0f) {
            if (swapped) {
                tmp.set(-plane.x, -plane.y, -plane.z);
                addContactPoint(body1, body0, vertex, tmp, distance);
            } else {
                tmp.set(plane.x, plane.y, plane.z);
                addContactPoint(body0, body1, vertex, tmp, distance);
            }
        }
    }
    shape0.unlockChildShapes();
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) StaticPlaneShape(com.bulletphysics.collision.shapes.StaticPlaneShape) Transform(com.bulletphysics.linearmath.Transform) AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 94 with Vector3f

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

the class GImpactMeshShapePart method calculateLocalInertia.

@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
    lockChildShapes();
    //#define CALC_EXACT_INERTIA 1
    //#ifdef CALC_EXACT_INERTIA
    inertia.set(0f, 0f, 0f);
    int i = getVertexCount();
    float pointmass = mass / (float) i;
    Stack stack = Stack.enter();
    Vector3f pointintertia = stack.allocVector3f();
    while ((i--) != 0) {
        getVertex(i, pointintertia);
        GImpactMassUtil.get_point_inertia(pointintertia, pointmass, pointintertia);
        inertia.add(pointintertia);
    }
    //#else
    //
    //// Calc box inertia
    //
    //float lx= localAABB.max.x - localAABB.min.x;
    //float ly= localAABB.max.y - localAABB.min.y;
    //float lz= localAABB.max.z - localAABB.min.z;
    //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);
    //
    //#endif
    unlockChildShapes();
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 95 with Vector3f

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

the class GeometryOperations method edge_plane.

/**
	 * Calc a plane from a triangle edge an a normal.
	 */
public static void edge_plane(Vector3f e1, Vector3f e2, Vector3f normal, Vector4f plane) {
    Stack stack = Stack.enter();
    Vector3f planenormal = stack.allocVector3f();
    planenormal.sub(e2, e1);
    planenormal.cross(planenormal, normal);
    planenormal.normalize();
    plane.set(planenormal);
    plane.w = e2.dot(planenormal);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) 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