Rotating Player

Started by
7 comments, last by Kris2456 19 years, 10 months ago
I have a player class which handles how my player model moves. What iw ant is for the player tobe able to control it, with the mouse. I have a crappy system which i made which uses fairly retarded vectors to make the player strafe. But itlooks rubish. I need an explenation of the maths behing making the player rotate and go down the view vector. PS.Im not talking bout the camera, imusing a model, so no gluLookAt please! ------------ "Here lies a toppled God, His fall was not a small one, We but built his pedastle, A narrow, and a tall one" Frank Herbert (Dune:Messiah)
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Advertisement
ok, i know it has something to o with PosX += sin(angle)* speed.
But its no working, and im not sure if im doing it right..
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
to move forward:
posx += sin(angleY)*speed
posz -= cos(angleY)*speed
to strafe:
posx += sin(angleY+90)*speed //90 in degrees
posz -= cos(angleY+90)*speed

then in your idle statement or whatever:
capture your mouse position
subdivide mouse position with your previous captured mouse position
set angleY = mouseposX
set angleX = mouseposY
Nope, it does just not work atall. Do u think u cudpost me some code, i excpect ill see it better then.
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
There is no reason for JSoftware''s code not to work.Except that sin,cos takes radians as arguments.Maybe the problem is there.If you use degrees,convert them to radians first and then pass them to sin() or cos().
I tried this but it dosnt work. Im sure im doing something wrong, here is my code:
CPlayer::CPlayer(){    double PlayerX = 0;    double PlayerY = 0;    double PlayerZ = 0;        double PlayerRX = 0;    double PlayerRY = 0;    double PlayerRZ = 0;        CVector3 vView = CVector3(0.0, 0.0, 1.0);    CVector3 vPos = CVector3(0, 0, 0);        float AngleX = 0;}//Set positionvoid CPlayer::SetPlayerPosition(double X, double Y, double Z){    vPos = CVector3(X, Y, Z);}//Move Playervoid CPlayer::MovePlayer(float speed){    vPos.x += vView.x*speed;    vPos.z -= vView.z*speed;    }//Set View Vectorvoid CPlayer::SetViewVector(){    POINT mouse;    GetCursorPos(&mouse);    float AngleX = mouse.x*(PI/180);    float AngleY = mouse.y*(PI/180);        vView.x = cos(AngleY);    vView.z = sin(AngleY);    //vView.z = sin(AngleX);}//Draw Playervoid CPlayer::DrawPlayer(){    glPushMatrix();     glTranslated(vPos.x,vPos.y,vPos.z);    glRotatef(PlayerRX,1,0,0);    glRotatef(PlayerRY,0,1,0);    glRotatef(PlayerRZ,0,0,1);    TieFighter();    glPopMatrix(); }


My Player does not turn, but merley strafes and it does not listen properly to mouse commands, and does the opposite to hat the mouse says, or sometimes it dosnt (IE. random).

[edited by - Kris2456 on June 9, 2004 3:56:08 PM]
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
In the SetViewVector(),you get the mouse pos and build the view vector,but I don''t see anywhere to call RotatePlayer() to load
PlayerR* with the angle values.But you use PlayerR* to rotate the model.With this piece of code,PlayerR* are all zero all the time.Maybe that''s the problem.
I have an idea. Ignore all i said before, thisis what i want to know how to do this:

            C      |    /      |   /      |  /      | /------o------      |      |      |      |


i want my player "o" tomove along vector C, but i also want to change the direction of vector C so the player can rotate. This way theplayer can fly around,when i add Y.
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
am i the only one who uses xy for the forward side, and z as height?

This topic is closed to new replies.

Advertisement