Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kris2456

Player Class

This topic is 5218 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive recently made a class to draw my player on the screen. But wheni run it, all i get is my player in the middle, andmy camera spins around it when i move the mouse. Iknow im close but i really hate the camera, and the way the slightet thing screws it up, pleez help. Here is my code:
//Constructor

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);
}

//Get Functions

double CPlayer::GetPlayerX()
{
    return PlayerX;
}
double CPlayer::GetPlayerY()
{
    return PlayerY;
}
double CPlayer::GetPlayerZ()
{
    return PlayerZ;
}

//Set position

void CPlayer::SetPlayerPosition(double X, double Y, double Z)
{
    PlayerX = X;
    PlayerY = Y;
    PlayerZ = Z;
}

//Move Player

void CPlayer::MovePlayer(float speed)
{
    PlayerX += vView.x*speed;
    PlayerY += vView.y*speed;
    PlayerZ += vView.z*speed;
}

//Rotate Player

void CPlayer::RotatePlayer(float angleX, float angleY, float angleZ)
{
    PlayerRX = angleX;
    PlayerRY = angleY;
    PlayerRZ = angleZ;
}

//Set View Vector

void CPlayer::SetViewVector()
{
    POINT mouse;
    GetCursorPos(&mouse);
    vView.x = (float)(400 - mouse.x)/100;
    vView.y = (float)(300 - mouse.y)/100;
}

//Draw Player

void CPlayer::DrawPlayer()
{
    glTranslated(PlayerX,PlayerY,PlayerZ);
    glRotatef(PlayerRX,1,0,0);
    glRotatef(PlayerRY,0,1,0);
    glRotatef(PlayerRZ,0,0,1);
    TieFighter();
}

CPlayer::~CPlayer()
{
}

And my Main.cpp code:
   
case GAME:
glLoadIdentity();	  			  
   	gluLookAt(256, 30, 256, g_Player.GetPlayerX(),g_Player.GetPlayerY(), g_Player.GetPlayerZ(),	0, 1, 0);
			  
	 
 	g_Player.DrawPlayer();
 	g_Player.SetViewVector();
 	g_Player.MovePlayer(speed);

...
EDIT: plz dont flame me if this is a crap way of doing it, im not good with vectors as such, and this code is based of GameTutorials.com's Camera Class. ------------ "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) [edited by - Kris2456 on June 7, 2004 3:11:56 PM]

Share this post


Link to post
Share on other sites
Advertisement
If I''m not mistaken, I think your problem may be here:

//Draw Player
void CPlayer::DrawPlayer()
{
glTranslated(PlayerX,PlayerY,PlayerZ);
glRotatef(PlayerRX,1,0,0);
glRotatef(PlayerRY,0,1,0);
glRotatef(PlayerRZ,0,0,1);
TieFighter();
}

You say that the camera just spins around your player, I think that is because you rotate the camera (or scene, I''m not sure which ^_^ ) and then leave the rotation to apply to everything else being drawn. I think what you need to do is first push a copy of the current matrix onto the stack, do the rotation & drawing and then pop the original matrix back off the stack so that the original point of view is restored. Here''s what I mean:

//Draw Player
void CPlayer::DrawPlayer()
{
glPushMatrix(); // Save current point of view

glTranslated(PlayerX,PlayerY,PlayerZ);
glRotatef(PlayerRX,1,0,0);
glRotatef(PlayerRY,0,1,0);
glRotatef(PlayerRZ,0,0,1);
TieFighter();

glPopMatrix(); // Restore that point of view
}

Hope that helps!

-dade

Share this post


Link to post
Share on other sites
YES, thats it. Ity works now, altho it dosntmove forawrds for some reason, but i will fix that. Im really thankful 4 ur help. cheers

------------

"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)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!