Search in sources :

Example 96 with Stack

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

the class RaycastVehicle method updateVehicle.

public void updateVehicle(float step) {
    for (int i = 0; i < getNumWheels(); i++) {
        updateWheelTransform(i, false);
    }
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    currentVehicleSpeedKmHour = 3.6f * getRigidBody().getLinearVelocity(tmp).length();
    Transform chassisTrans = getChassisWorldTransform(stack.allocTransform());
    Vector3f forwardW = stack.allocVector3f();
    forwardW.set(chassisTrans.basis.getElement(0, indexForwardAxis), chassisTrans.basis.getElement(1, indexForwardAxis), chassisTrans.basis.getElement(2, indexForwardAxis));
    if (forwardW.dot(getRigidBody().getLinearVelocity(tmp)) < 0f) {
        currentVehicleSpeedKmHour *= -1f;
    }
    //
    // simulate suspension
    //
    int i = 0;
    for (i = 0; i < wheelInfo.size(); i++) {
        float depth;
        depth = rayCast(wheelInfo.getQuick(i));
    }
    updateSuspension(step);
    for (i = 0; i < wheelInfo.size(); i++) {
        // apply suspension force
        WheelInfo wheel = wheelInfo.getQuick(i);
        float suspensionForce = wheel.wheelsSuspensionForce;
        float gMaxSuspensionForce = 6000f;
        if (suspensionForce > gMaxSuspensionForce) {
            suspensionForce = gMaxSuspensionForce;
        }
        Vector3f impulse = stack.allocVector3f();
        impulse.scale(suspensionForce * step, wheel.raycastInfo.contactNormalWS);
        Vector3f relpos = stack.allocVector3f();
        relpos.sub(wheel.raycastInfo.contactPointWS, getRigidBody().getCenterOfMassPosition(tmp));
        getRigidBody().applyImpulse(impulse, relpos);
    }
    updateFriction(step);
    for (i = 0; i < wheelInfo.size(); i++) {
        WheelInfo wheel = wheelInfo.getQuick(i);
        Vector3f relpos = stack.allocVector3f();
        relpos.sub(wheel.raycastInfo.hardPointWS, getRigidBody().getCenterOfMassPosition(tmp));
        Vector3f vel = getRigidBody().getVelocityInLocalPoint(relpos, stack.allocVector3f());
        if (wheel.raycastInfo.isInContact) {
            Transform chassisWorldTransform = getChassisWorldTransform(stack.allocTransform());
            Vector3f fwd = stack.allocVector3f();
            fwd.set(chassisWorldTransform.basis.getElement(0, indexForwardAxis), chassisWorldTransform.basis.getElement(1, indexForwardAxis), chassisWorldTransform.basis.getElement(2, indexForwardAxis));
            float proj = fwd.dot(wheel.raycastInfo.contactNormalWS);
            tmp.scale(proj, wheel.raycastInfo.contactNormalWS);
            fwd.sub(tmp);
            float proj2 = fwd.dot(vel);
            wheel.deltaRotation = (proj2 * step) / (wheel.wheelsRadius);
            wheel.rotation += wheel.deltaRotation;
        } else {
            wheel.rotation += wheel.deltaRotation;
        }
        // damping of rotation when not in contact
        wheel.deltaRotation *= 0.99f;
    }
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) ContactConstraint(com.bulletphysics.dynamics.constraintsolver.ContactConstraint) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) Stack(com.bulletphysics.util.Stack)

Example 97 with Stack

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

the class RaycastVehicle method updateWheelTransformsWS.

public void updateWheelTransformsWS(WheelInfo wheel, boolean interpolatedTransform) {
    wheel.raycastInfo.isInContact = false;
    Stack stack = Stack.enter();
    Transform chassisTrans = getChassisWorldTransform(stack.allocTransform());
    if (interpolatedTransform && (getRigidBody().getMotionState() != null)) {
        getRigidBody().getMotionState().getWorldTransform(chassisTrans);
    }
    wheel.raycastInfo.hardPointWS.set(wheel.chassisConnectionPointCS);
    chassisTrans.transform(wheel.raycastInfo.hardPointWS);
    wheel.raycastInfo.wheelDirectionWS.set(wheel.wheelDirectionCS);
    chassisTrans.basis.transform(wheel.raycastInfo.wheelDirectionWS);
    wheel.raycastInfo.wheelAxleWS.set(wheel.wheelAxleCS);
    chassisTrans.basis.transform(wheel.raycastInfo.wheelAxleWS);
    stack.leave();
}
Also used : Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 98 with Stack

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

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

the class BvhTree method _build_sub_tree.

protected void _build_sub_tree(BvhDataArray primitive_boxes, int startIndex, int endIndex) {
    int curIndex = num_nodes;
    num_nodes++;
    assert ((endIndex - startIndex) > 0);
    if ((endIndex - startIndex) == 1) {
        // We have a leaf node
        //setNodeBound(curIndex,primitive_boxes[startIndex].m_bound);
        //m_node_array[curIndex].setDataIndex(primitive_boxes[startIndex].m_data);
        node_array.set(curIndex, primitive_boxes, startIndex);
        return;
    }
    // calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
    // split axis
    int splitIndex = _calc_splitting_axis(primitive_boxes, startIndex, endIndex);
    splitIndex = _sort_and_calc_splitting_index(primitive_boxes, startIndex, endIndex, splitIndex);
    //calc this node bounding box
    Stack stack = Stack.enter();
    AABB node_bound = stack.allocAABB();
    AABB tmpAABB = stack.allocAABB();
    node_bound.invalidate();
    for (int i = startIndex; i < endIndex; i++) {
        primitive_boxes.getBound(i, tmpAABB);
        node_bound.merge(tmpAABB);
    }
    setNodeBound(curIndex, node_bound);
    // build left branch
    _build_sub_tree(primitive_boxes, startIndex, splitIndex);
    // build right branch
    _build_sub_tree(primitive_boxes, splitIndex, endIndex);
    node_array.setEscapeIndex(curIndex, num_nodes - curIndex);
    stack.leave();
}
Also used : AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 100 with Stack

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

the class GImpactBvh method find_collision.

//public static float getAverageTreeCollisionTime();
public static void find_collision(GImpactBvh boxset0, Transform trans0, GImpactBvh boxset1, Transform trans1, PairSet collision_pairs) {
    if (boxset0.getNodeCount() == 0 || boxset1.getNodeCount() == 0) {
        return;
    }
    Stack stack = Stack.enter();
    BoxBoxTransformCache trans_cache_1to0 = stack.allocBoxBoxTransformCache();
    trans_cache_1to0.calc_from_homogenic(trans0, trans1);
    //#ifdef TRI_COLLISION_PROFILING
    //bt_begin_gim02_tree_time();
    //#endif //TRI_COLLISION_PROFILING
    _find_collision_pairs_recursive(boxset0, boxset1, collision_pairs, trans_cache_1to0, 0, 0, true);
    //#ifdef TRI_COLLISION_PROFILING
    //bt_end_gim02_tree_time();
    //#endif //TRI_COLLISION_PROFILING
    stack.leave();
}
Also used : BoxBoxTransformCache(com.bulletphysics.extras.gimpact.BoxCollision.BoxBoxTransformCache) 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