chmod

11-02-2008 08:28:14

Hello again all. I've taken some advise from an earlier thread about using counter-steering as opposed to angular damping for controlling my spacecraft.

Here is a quick rundown of what I'm attempting. All the methods below are for dealing with my Ship object. Ship has a created NxActor stored in m_body.

In each of the actions below the intensity is a reading from the joystick and can be between -32k and 32k. m_steering_to_apply is just a 3d vector storing up all the forces I will later add in the update method.

Apparently, I completely misunderstand angular momentum. Can anyone help me understand how I could fix the update method to correctly counter-steer against any rotation.

The problem right now is that this code works fine if I only steer on one axis, but as soon as I turn along a second axis, it goes nuts and starts spinning me all over the place. I'm guessing angular momentum is in the global space? So confused right now. Thanks for any help!

Here is a quick rundown of what I'm attempting. All the methods below are for dealing with my Ship object. Ship has a created NxActor stored in m_body.

In each of the actions below the intensity is a reading from the joystick and can be between -32k and 32k. m_steering_to_apply is just a 3d vector storing up all the forces I will later add in the update method.

void Ship::action_Pitch(double elapsed, int intensity) {

if (abs(intensity) < 2000.0)

return;

m_steering_to_apply.x = m_pitch_force * elapsed * (intensity / (1024.0*32.0));

}

void Ship::action_Roll(double elapsed, int intensity) {

if (abs(intensity) < 2000.0)

return;

m_steering_to_apply.z = m_roll_force * elapsed * (intensity / (1024.0*32.0)) * -1;

}

void Ship::action_Yaw(double elapsed, int intensity) {

if (abs(intensity) < 2000.0)

return;

m_steering_to_apply.y = m_yaw_force * elapsed *(intensity / (1024.0*32.0)) * -1;

}

void Ship::update(double elapsed) {

// boring stuff removed...

NxVec3 vel = m_body->getAngularMomentum();

if (abs(m_steering_to_apply.x) < 1000 && abs(vel.x) > 0)

m_steering_to_apply.x = constrain((vel.x * 15), -m_pitch_force, m_pitch_force) * -elapsed;

if (abs(m_steering_to_apply.y) < 1000 && abs(vel.y) > 0)

m_steering_to_apply.y = constrain((vel.y * 15), -m_yaw_force, m_yaw_force) * -elapsed;

if (abs(m_steering_to_apply.z) < 1000 && abs(vel.z) > 0)

m_steering_to_apply.z = constrain((vel.z * 15), -m_roll_force, m_roll_force) * -elapsed;

if (!m_steering_to_apply.isZero()) {

m_body->addLocalTorque(m_steering_to_apply, NX_SMOOTH_IMPULSE);

m_steering_to_apply.zero();

}

Apparently, I completely misunderstand angular momentum. Can anyone help me understand how I could fix the update method to correctly counter-steer against any rotation.

The problem right now is that this code works fine if I only steer on one axis, but as soon as I turn along a second axis, it goes nuts and starts spinning me all over the place. I'm guessing angular momentum is in the global space? So confused right now. Thanks for any help!