Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void update(ElapsedTime elapsedTime) {
- float dt = (float) elapsedTime.stepTime;
- // Ensure the maximum acceleration isn't exceeded
- if (acceleration.lengthSquared() > maxAcceleration * maxAcceleration) {
- acceleration.normalise();
- acceleration.multiply(maxAcceleration);
- }
- // Update the velocity using the acceleration and ensure the
- // maximum velocity has not been exceeded
- velocity.add(acceleration.x * dt, acceleration.y * dt);
- if (velocity.lengthSquared() > maxVelocity * maxVelocity) {
- velocity.normalise();
- velocity.multiply(maxVelocity);
- }
- // Update the position using the velocity
- position.add(velocity.x * dt, velocity.y * dt);
- // Ensure the maximum angular acceleration isn't exceeded
- if (angularAcceleration < -maxAngularAcceleration
- || angularAcceleration > maxAngularAcceleration) {
- angularAcceleration = Math.signum(angularAcceleration)
- * maxAngularAcceleration;
- }
- // Update the angular velocity using the angular acceleration and
- // ensure the maximum angular velocity has not been exceeded
- angularVelocity += angularAcceleration * dt;
- if (angularVelocity < -maxAngularVelocity
- || angularVelocity > maxAngularVelocity) {
- angularVelocity = Math.signum(angularVelocity) * maxAngularVelocity;
- }
- // Update the orientation using the angular velocity
- orientation += angularVelocity * dt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement