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();
}
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();
}
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;
}
}
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();
}
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();
}
Aggregations