Ace_Man

04-25-2000, 08:49 PM

Can someone help me on a 3D movement problem...I got my code to move me in whatever direction I'm facing, however, when I turn, "I" rotate around my 3d world instead of it rotating around me. (Does that make sense?) I don't pivot in place....I'm struggling with the Trig for this so any help would be greatly appreciated...Thanks again...My code for what I have is below...

if(GetAsyncKeyState(VK_UP)) {

xPos -= (float) sin(yRot * pi/180)* 1.5;

zPos -= (float) cos(yRot * pi/180) * 1.5;

}

if(GetAsyncKeyState(VK_DOWN)) {

xPos += (float) sin(yRot * pi/180) *1.5;

zPos += (float) cos(yRot * pi/180) * 1.5;

}

if(GetAsyncKeyState(VK_RIGHT)) {

yRot -= 1.5;

}

if(GetAsyncKeyState(VK_LEFT)) {

yRot += 1.5;

}

and in my drawing method......

void drawPicture() {

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

float scene = 360 - yRot;

glRotatef(scene, 0, 1, 0);

glTranslatef(-xPos, 0, -zPos);

...Draw my picture...

}

if(GetAsyncKeyState(VK_UP)) {

xPos -= (float) sin(yRot * pi/180)* 1.5;

zPos -= (float) cos(yRot * pi/180) * 1.5;

}

if(GetAsyncKeyState(VK_DOWN)) {

xPos += (float) sin(yRot * pi/180) *1.5;

zPos += (float) cos(yRot * pi/180) * 1.5;

}

if(GetAsyncKeyState(VK_RIGHT)) {

yRot -= 1.5;

}

if(GetAsyncKeyState(VK_LEFT)) {

yRot += 1.5;

}

and in my drawing method......

void drawPicture() {

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

float scene = 360 - yRot;

glRotatef(scene, 0, 1, 0);

glTranslatef(-xPos, 0, -zPos);

...Draw my picture...

}