   3d manipulation
  hi, im currently programming at 3d game onto my nintendo ds (with c and a separate library for the ds) and i appreciate the fact that all (most?) people here talk about programming for a windows system, but i just need some help on formulas/ideas rather than actual coding.ok so i can load a 3d spaceship/racer (like fzero) textured model ive created, now for the movement! i have variables shipx, shipy and shipz which are coords for the ships location. i also have 3 coords called roll, pitch and yaw. the ds updates at 60fps so for every frame there is a main loop. in this main loop ive added a "moveship" function which checks whether or not left/right are pressed and varies the yaw accordingly, moves shipx and shipz with sin and cos functions on yaw. this moves it in a 2d plane. it also moves the shipy coords so it moves up/down according to the sin function of the pitch. it also rotates the ship with a simple rotate function depending on pitch, yaw and roll.problem 1: when i edit pitch, the ship looks upwards. however when i rotate it by holding left/right, the ship flattens and ends up pointing down when rotated 180 degrees.problem 2: take moving with yaw 0 and pitch 20, it moves how it should. now when i rotate its yaw 180 degrees, it still moves up while looking down.i think i need to use some sort of vector-calculation and also create 3 separate axis for the ship but am unsure of how to go about any of it. can anybody help me with manipulating an object in 3d? what would be the standard formulas used in a 3d video game for rotating/manipulating objects according to their direction/pitch/roll??thanks![Edited by - Rajveer on July 22, 2006 8:05:52 PM]
  noone got any ideas? :(   ;  How about using axis-angle instead of yaw-pitch-roll?It's likely a gimbal-lock problem.;  You may try to store a co-ordinate system (e.g. a matrix) with your ship. Then you can use the "forward" vector (e.g. the principal z or whatever) to move the ship into that direction. Furthur you can use the side vector for flying curves. Then, when updating from frame to frame you can apply incremental changes to the co-ordinate system w/o the try to compute yaw/pitch/roll angles from it or vice-versa, resp.From the mechanics it seems senseful to handle orientation and position of the co-ordinate system each by its own. E.g. something like that: Update the position by the current speed and forward vector, then update the current orientation considering the current curve steering input.   ;  cheers for the input guys!relsoft: read a bit about gimbal-lock on wikipedia and i see what u mean :) by axis angle you mean the ships own axis or the "real" axis's angles?haegarr: if im following you correctly, this coordinate system would be used to store the ships own axis which should be calculated right? im picturing a 3by3 matrix where the 1st row will store say the ships "zaxis" (vector to push it forward), the 2nd to store say the ships "xaxis" (left to right) and the third the ships yaxis?sorry if im totally off course :)   ;Quote:Original post by Rajveerhaegarr: if im following you correctly, this coordinate system would be used to store the ships own axis which should be calculated right? im picturing a 3by3 matrix where the 1st row will store say the ships "zaxis" (vector to push it forward), the 2nd to store say the ships "xaxis" (left to right) and the third the ships yaxis?Yes: A 3x3 matrix for the orientation and a 3 vector for the position.Whether the rows or columns denote the axis vectors depends on the matrix math you are using. If you transform a vector v by a matrix M this wayv' := M * vthen you're using column vectors (e.g. like OpenGL). The other way isv' := v * Mthen you're using row vectors (e.g. like D3D).Because of the matrix vector product rules the 1st column/row denotes the x axis vector, the 2nd the y axis vector, and the 3rd the z axis vector (assuming that a vector stores its components in x-y-z order).Now it depends on how your ship is oriented w.r.t. the x,y,z axes. E.g. it may have its front in z direction, wings in x direction, and top in y direction (but may be anything else; its just a convention you have to define). In the example the forward vector is obviously the z axis vector.EDIT: Multiplying many rotation matrices together will yield earlier or later in a degradation of the matrix. I.e. at some point the ship will be started to be scaled/sheared. That is normal. If you start notice that your ship suffers from that problem, you need to implement some rotation matrix normalization/ortogonalization scheme.   ;  cheers for helping out haegarr :)ill try programming when i get back home tomorrow, before i do though i just want to make sure i know what im doing.the first matrix which will store the ships axis vectors will be made of sin/cos functions of the relevant angles e.g. for the ships z-axis, the x coordinate will be sin(direction), z coord will be cos(direction) and im not sure what the y coord will be (not sin(pitch) as it depends on what direction the ship is looking in). then why would i need the second matrix? couldn't i just use the first matrix for rotations too? or am i missing something?i feel like i need a tutorial website or something on simple 3d transformations/rotations as i seem to be missing alot out! sorry to be wasting your time :(   ;  Actually, I'd need one too, so if you can supply one, you'd be helping two guys... ;)but if I understand well what you say, we need a Vertor3 for the position (which is the normal order of things) and a 3x3 matrix for the rotation? which is basically composed of 3 Vector3 to keep the vector of each of the object's axis? if we are in the OpenGL we should store it like this:xyzxyzxyzand if we're in Direct3D we should store it like this :xxxyyyzzzAm I right?by multiplying the a Vector3 (x, y, z) with our rotation matrix, it should give the behavior of a normal space ship, so nose up when y goes up and nose down when y goes down no matter which axis we face (±x, ±z) Am I right again?thanks for the helpThunderMusic   ;  ok i understand why you would need two separate matrices, that makes sense.the first matrix, to store the ships coordinates, would be used for transformations right?   