View Full Version : Roll, Pitch, and Yaw

BigRD

10-11-2001, 08:45 PM

I've been trying to figgure this out for a while now. The rotations are easy enough, but how do you move in the direction your faceing? I would like to eventualy make a flying game, but this has got me stumped so any help would be appreciated.

Thanks.

Gavin

10-12-2001, 12:51 AM

glTranslatef(x, y, x);

BigRD

10-12-2001, 05:55 AM

I know, but theres some math involved. Thats what I can't figure out. For ex. to walk around on th xz plain you have something like:

x=x+sin(ang*pi/180)

z=z+cos(ang*pi/180)

pleopard

10-12-2001, 07:44 AM

Sorry but I dont have time to explain this but ...

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

// Apply the viewing transformation associated with this instance.

void MRoamingNavigator::applyViewingTransformation()

{

// dbg << m_ReferencePosition.toString() << "\n";

// Translate to the reference position.

glTranslatef(

-referencePosition().x(),

-referencePosition().y(),

-referencePosition().z()

);

// Now perform transformation from reference

glRotatef(lookDownAngle(),1.0,0,0);

glRotatef(360.0 - headingAngle(),0,1.0,0);

glTranslatef(

-xOffset(),

-yOffset(),

-zOffset()

);

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

// Translate along the current line of sight.

void MRoamingNavigator::translate(double distance)

{

double d = m_NavigationGain*distance;

double hAng = headingAngle()*MConstants:: DegToRad;

double lAng = lookDownAngle()*MConstants:: DegToRad;

double xOff = m_ReferenceOffset.x() + sin(-hAng)*d;

double yOff = m_ReferenceOffset.y() - sin(lAng)*d;

if (yOff<m_MinimumHeight)

{

yOff = m_MinimumHeight;

}

double zOff = m_ReferenceOffset.z() - cos(-hAng)*d;

if (m_BoundingRadius>0)

{

if (

xOff>=-m_BoundingRadius && xOff<=m_BoundingRadius &&

yOff>=-m_BoundingRadius && zOff<=m_BoundingRadius &&

zOff>=-m_BoundingRadius && zOff<=m_BoundingRadius

)

{

m_ReferenceOffset.set(xOff,yOff,zOff);

}

}

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

// Slide left by a given distance.

void MRoamingNavigator::slideLeft(double distance)

{

double d = m_NavigationGain*distance;

double a = (headingAngle()-90.0)*MConstants:: DegToRad;

double xOff = m_ReferenceOffset.x() + sin(a)*d;

double zOff = m_ReferenceOffset.z() + cos(a)*d;

if (m_BoundingRadius>0)

{

xOff = Clip(xOff,-m_BoundingRadius,m_BoundingRadius);

zOff = Clip(zOff,-m_BoundingRadius,m_BoundingRadius);

}

if (m_BoundingRadius>0)

{

if (

xOff>=-m_BoundingRadius && xOff<=m_BoundingRadius &&

zOff>=-m_BoundingRadius && zOff<=m_BoundingRadius

)

{

m_ReferenceOffset.setX(xOff);

m_ReferenceOffset.setZ(zOff);

}

}

}

[This message has been edited by pleopard (edited 10-12-2001).]

[This message has been edited by pleopard (edited 10-12-2001).]

The Wolf

10-12-2001, 01:30 PM

The quick and dirty method:

glLoadIndentity();

glLoadMatrix(camera); // camera is a float camera[16]

glRotate(roll_angle, 0.0f,0.0f,1.0f);

glRotate(yaw_angle, 0.0f,1.0f,0.0f);

glRotate(pitch_angle, 1.0f,0.0f,0.0f);

glTranslatef(strafe,jump,dir);

glGetFloatv(GL_MODELVIEW_MATRIX, camera);

strafe: is the side to side movement.

jump: is the up down hover type movement,think helicopter going up or down.

dir: is the direction you're pointing at, this is your forward movement, if it's 1.0f you will move 1.0f in the direction you're looking.

in your main rendering loop, you can then do something like this:

glClearBuffer(....);

glLoadIdentity();

gluLookAt(camera[12],camera[13],camera[14], // position of camera

camera[12]+camera[8],camera[13]+camera[9], camera[14]+camera[15], //look at dir

camera[4], camera[5], camera[6] // up dir

);

Et Voila! I encourage you to find out more on the encoding of the matrices. And maybe later on learn quaternions.

Hope this helps.

le-Wolf

[This message has been edited by The Wolf (edited 10-12-2001).]

Why is that a quick and dirty method?

Is it because you shouldn't use that technique or is it because you shouldn't encode it directly in rendering code like that?

-Mezz

Korval

10-15-2001, 06:06 PM

It is "quick and dirty" because it uses a glGet. These are slow operations not meant for realtime use. I would call it "slow and dirty".

My suggestion is, don't use angles. Use vectors that point in the direction you want to go. That way, all you need to do is take the vector, multiply it by the speed/time, and add that to the current position.

Alessandro_dup1

10-17-2001, 12:10 AM

Hi, take a look at my web site and specifically to the flight model section at http://www.web-discovery.net/aerodynamics/1.htm

There i explain how to build an aircraft flight model.

Hope it helps !

Ysaneya

10-18-2001, 12:25 AM

I think the code you want is:

x = cos ( pitch ) * cos ( yaw )

y = sin ( yaw )

z = sin ( pitch ) * cos ( yaw )

Btw, beware of the angle unit (use radians) and the signs of the angles; you'll probably have to play with the values til it moves in the correct direction.

Y.

BigRD

10-18-2001, 07:19 AM

Thanks everybody for your replies. I haven't tried everything yet. I tried the quick and dirty method, but I need to learn more about matrixes so I can understand whats going on. Also thanks for the link. If anybody else know of any sites I can look at, send them to me. For some reason none of the search engins could find much on flight sims.

Anyway thanks again.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.