Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075919 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:28:43 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Pitch and roll
Pages: 1 [2]
Print
Author Topic: Pitch and roll  (Read 861 times)
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #20 on: October 29, 2012, 12:47:59 PM »

So, uh, to give a vague answer to Quarry's original question, assuming quaternions. I think the following gives an Elite-like behaviour, which is neither rockets nor planes, but instead the player has control of speed and rotation completely independently. (this is not physically accurate, but that's how the game works).

I'm interpreting x and y input of the player as roll and pitch controls as requested, though most games would use yaw and pitch.

Code:
void ComputeMovement(Vector3 position, float speed, Quaternion rotation, float x, float y)
{
  Vector3 forward = r * Vector3(1, 0, 0)
  Vector3 up = r * Vector3(0, 1, 0)
  Vector3 right = r * Vector3(0, 0, 1)

  Quaternion delta_pitch = Quaternion.from_axis_angle(right, y * time_step)
  Quaternion delta_roll = Quaternion.from_axis_angle(forward, x * time_step)
 
  Quaternion new_rotation = rotation * delta_pitch * delta_roll;
  Vector3 new_position = position + forward * speed * time_step;
  return new_position, new_rotation;
}
Logged
Quarry
Level 10
*****



View Profile WWW
« Reply #21 on: October 29, 2012, 09:14:29 PM »

Where is the part where the rotation affects the position
Logged

 
Geti
Level 10
*****



View Profile WWW
« Reply #22 on: October 30, 2012, 05:17:16 AM »

It's the part where you multiply a vector that represented forwards in the entirely unrotated system by your rotation, and then add that to your (untransformed) position (scaled by your change in time multiplied by your speed, assuming you were smart enough to choose that forward vector to be of unit length).

Seriously you need to get better at asking questions, and at applying the answers you get to other questions to new problems. You can do a 3d rotation on any point or shape or whatever in 3d space, and you can compose transformations by applying them in sequence. The result can be cached if you need to use it more than once (eg for the transformation from world space to screen space).

I'm just spitting information at you because I'm not sure exactly where you're confused, and your 1 liner responses don't help that issue. Is this still stemming from your wish to learn about how to make 3d graphics go?

For those casually dropping conflicting info about gimbal lock, it'd be great if you'd try implementing something like this before offering advice. For the record, gimbal lock is a significant problem in this case and quarternions are the way to go.

Grumble grumble
Logged

Quarry
Level 10
*****



View Profile WWW
« Reply #23 on: October 30, 2012, 06:05:07 AM »

I-I-I'm sorry
Logged

 
Geti
Level 10
*****



View Profile WWW
« Reply #24 on: October 30, 2012, 02:48:26 PM »

So where are you having issues then? Being sorry in a one liner doesn't elucidate that for us.
Logged

Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic