From: Kevin M. <ke...@vr...> - 2002-02-22 03:19:52
|
Hi, some guys were asking me after the club about my example app "aster". I don't think I caught their names, so hopefully they are on the list... anyway, I was talking to Josh about how to do the rotations in 3D using sin/cos as aster currently does it. If matrices scare you, then I have a much easier way for you: first, aster kept track of ship rotation using [theta]. since you want to include pitch (rotation about x axis), then you'll want another rotation variable, lets call it [phi]. you manipulate this var to control your ship's pitch. ok, so [theta] is rotation about Y axis, and [phi] is rotation about X axis. then for each one, calculate your heading. for [theta] we did this according to what we've learned in trig class: // get the forward vector of ship in the XZ plane yaw_vector_x = cos( deg2rad( theta + 90 ) ); yaw_vector_y = sin( deg2rad( theta + 90 ) ); well, for [phi[, you'll do something very similar... // get the forward vector of ship in the ZY plane pitch_vector_z = cos( phi + 180 ); pitch_vector_y = sin( phi + 180 ); that 180 might be off, so you may want to play with it. THEN... you'll simply add the vectors to get your ship's forward vector: shipForward[0] = yaw_vector_x; shipForward[1] = yaw_vector_y + pitch_vector_y; shipForward[2] = pitch_vector_z; then you should normalize this vector: norm( shipForward ) now the length is 1.0 instead of 2.0... hope this works, I haven't tried it but the math looks right... -- @--@---@---@----@-----@------@------@-----@----@---@---@--@ Kevin Meinert __ _ __ http://www.vrac.iastate.edu/~kevn \ || \| \ / ` Virtual Reality Applications Center \ ||.-'|--\\ Howe Hall, Iowa State University, Ames Iowa \|| \| \`__, ----------------------------------------------------------- |