List of usage examples for com.badlogic.gdx.math Vector3 isZero
@Override
public boolean isZero(final float margin)
From source file:com.badlogic.gdx.ai.tests.steer.bullet.SteeringBulletEntity.java
License:Apache License
protected void applySteering(SteeringAcceleration<Vector3> steering, float deltaTime) { boolean anyAccelerations = false; // Update position and linear velocity if (!steeringOutput.linear.isZero()) { body.applyCentralForce(steeringOutput.linear.scl(deltaTime)); anyAccelerations = true;//from w ww. ja va 2 s .co m } // Update orientation and angular velocity if (isIndependentFacing()) { if (steeringOutput.angular != 0) { body.applyTorque(tmpVector3.set(0, steeringOutput.angular * deltaTime, 0)); anyAccelerations = true; } } else { // If we haven't got any velocity, then we can do nothing. Vector3 linVel = getLinearVelocity(); if (!linVel.isZero(MathUtils.FLOAT_ROUNDING_ERROR)) { // // TODO: Commented out!!! // Looks like the code below creates troubles in combination with the applyCentralForce above // Maybe we should be more consistent by only applying forces or setting velocities. // // float newOrientation = vectorToAngle(linVel); // Vector3 angVel = body.getAngularVelocity(); // angVel.y = (newOrientation - oldOrientation) % MathUtils.PI2; // if (angVel.y > MathUtils.PI) angVel.y -= MathUtils.PI2; // angVel.y /= deltaTime; // body.setAngularVelocity(angVel); // anyAccelerations = true; // oldOrientation = newOrientation; } } if (anyAccelerations) { body.activate(); // TODO: // Looks like truncating speeds here after applying forces doesn't work as expected. // We should likely cap speeds form inside an InternalTickCallback, see // http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Simulation_Tick_Callbacks // Cap the linear speed Vector3 velocity = body.getLinearVelocity(); float currentSpeedSquare = velocity.len2(); float maxLinearSpeed = getMaxLinearSpeed(); if (currentSpeedSquare > maxLinearSpeed * maxLinearSpeed) { body.setLinearVelocity(velocity.scl(maxLinearSpeed / (float) Math.sqrt(currentSpeedSquare))); } // Cap the angular speed Vector3 angVelocity = body.getAngularVelocity(); if (angVelocity.y > getMaxAngularSpeed()) { angVelocity.y = getMaxAngularSpeed(); body.setAngularVelocity(angVelocity); } } }