Skip to main content
gamedev.net
🔒 Locked

Translate problem

Started by Chuffy_345 Mar 8, 2004 at 8:46 AM 1 replies 500+ views
Original Post
Chuffy_345
Chuffy_345
Hi guys I’ve got a translation problem in my OpenGL code. Basically I’ve created a sphere in a method called renderScene doing the usual pushMatrix create sphere object translate create sphere pop matrix. In another method called move which is called on a key stoke I’ve setup a while loop which for example is from 0.0001 to 1 do with an increment of 0.0001. After each pass I want to translate my sphere by these small increases. The problem is I can’t just update the x,y,z co-ordinates I used in the glTranslate because I have to call renderScene to make this happen. The problem with calling renderScene is that it will create a new sphere on top of the current sphere(snake effect), where as I want to just move the old sphere. What I really need is to be able to get a handle on my sphere object which will then allow me to call glTranslate from my move method. The problem is I don’t know if you can or how to get a handle on a sphere object. It’s hard to explain the problem so if anything’s not clear let me know. Cheers and I hope someone can help.
rafalp
rafalp
well try to do it in this way

class sphere
{
private:
float trans[3];

...

public:
sphere():trans[0]=0.0f,trans[1]=0.0f,trans[2]=0.0f{}
// other constructors if any

void moveSphere()
{
// as I know this procedure waits for a keystroke
// so modify this->trans table by yourself
}

void renderSphere()
{
glPushMatrix();
glTranslatef(this->trans[0],this->trans[1],this->trans[2]);
// your code goes here: eg. draw(); ...
glPopMatrix();
}
}:

class scene
{
private:
sphere Sph;
public:

void Init()
{
....
}
void renderScene( ... );
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
Sph.renderSphere();
}
}


Topic Locked

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

Sign in to reply to this topic.