Skip to main content
gamedev.net
🔒 Locked

how to make objects behave different

Started by justinxnitsuj Apr 1, 2007 at 8:34 AM 3 replies 900+ views
Original Post
justinxnitsuj
justinxnitsuj
hey i have two instances of a robot. what i want is from them to behave different. but they behave same. for example if there is a glRotatef(...) up there, both rotates. how can i prevent that. thanks
Ezbez
Ezbez
Push a new matrix onto the stack before each robot, and pop it off again after the robot. In psuedo code:

Push
Rotate
Translate
DrawFirstRobot
Pop

Push
Rotate
Translate
DrawSecondRobot
Pop

This explains the functions for pushing and poping matrices. The RedBook also has great information about all of this stuff. Google it.
justinxnitsuj
justinxnitsuj
thank you very much :)
then let me ask a new question (don't want to start a new thread for a basic question) now my two robots rotate differently. the first rotates around itself, but the second one rotates according to coordinate axis (because first one is at (0.0f,0.0f,0.0f). i want the second one to rotate about itself. how can i implement this

......

ok i solved that :) just added a translatef(10.0f,0.0f,10.0f) then put the second robot at (0.0f,0.0f,0.0f) again. but i don't want to do this like that. because i have a function like DrawRobot(float xPoz,float yPoz,float zPoz). if i use the method that i found, the DrawRobot function will be totally useless :( how can i solve this without putting all the robots at (0.0f,0.0f,0.0f)

[Edited by - justinxnitsuj on April 1, 2007 9:01:42 AM]
Scorpie
Scorpie
Just make your render function like this (remove parameters/functions you dont need):

void Robot::Render(float xPoz,float yPoz,float zPoz, float angle, float xRot, float yRot, float zRot, float xScale, float yScale, float zScale){

glPushMatrix();
glTranslatef(xPoz, yPoz, zPoz);
glRotatef(angle, xRot, yRot, zRot);
glScalef(xScale, yScale, zScale);

//Render robot

glPopMatrix();
}

Although this works i would suggest that you make the position etc private members of the robot class.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.