PDA

View Full Version : glTranslatef lost values



KekseKekse
03-30-2012, 03:50 PM
Some Code For you


void SceneManager::DrawRenderList(void)
{
std::list<Mesh *>::iterator i = MeshList.begin();

glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);


while (i != MeshList.end())
{
glTranslatef(0.0f,2.0f, -5.0f);
glPushMatrix();
(*i)->PositionForDraw();
(*i)->Draw();
glPopMatrix();
i++;
}
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

}


void Mesh::PositionForDraw()
{
glTranslatef(modelPosition[0],modelPosition[1], modelPosition[2]);
glRotatef(rotqube,0.0f,1.0f,0.0f);
glRotatef(rotqube,1.0f,1.0f,1.0f);
}

void Mesh::Draw()
{
glNormalPointer(GL_FLOAT, 0, &amp;normals[0]);
glColorPointer(3, GL_FLOAT, 0, &amp;colors[0]);
glVertexPointer(3, GL_FLOAT, 0, &amp;vertices[0]);
glTranslatef(3.0f,0.0f, 0.0f);
glDrawArrays(GL_QUADS, 0, 24);
glTranslatef(3.0f,0.0f,0.0f);
glDrawArrays(GL_QUADS, 0, 24);
glTranslatef(3.0f,0.0f,0.0f);
glDrawArrays(GL_QUADS, 0, 24);

rotqube +=0.9f;
}


in the Mesh.h

private:
GLfloat modelPosition[3];
GLfloat modelAngle[3];

Dosent Work
with



void Mesh::PositionForDraw()
{
GLfloat x=0.0f, y=0.0f, z=-10.0f;
glTranslatef(x,y,z);
glRotatef(rotqube,0.0f,1.0f,0.0f);
glRotatef(rotqube,1.0f,1.0f,1.0f);
}

works fine


GLfloat x=modelPosition[0], y=fmodelPosition[1],
z=modelPosition[2];

//a cout x,y,z gives here right values
glTranslatef(x,y,z);
glRotatef(rotqube,0.0f,1.0f,0.0f);
glRotatef(rotqube,1.0f,1.0f,1.0f);
}

dosent work.



Well looks like the values get f*****up
Can some one help me?

swethasharma
03-31-2012, 03:26 AM
Does modelPosition[0],modelPosition[1] and modelPosition[2] have values?

KekseKekse
03-31-2012, 04:55 AM
Yes, when i cout them just bevor there are the right Values.
They are set in the Construktor.

swethasharma
03-31-2012, 07:04 AM
You mean this does not work




void Mesh::PositionForDraw()
{
GLfloat x=0.0f, y=0.0f, z=-10.0f;
glTranslatef(x,y,z);
glRotatef(rotqube,0.0f,1.0f,0.0f);
glRotatef(rotqube,1.0f,1.0f,1.0f);
}



but other one works?

KekseKekse
03-31-2012, 07:20 AM
if it works or not stands after the code.

So that one works

KekseKekse
03-31-2012, 07:48 AM
Problem Found, its not show up in this part of code.
I cast down to Mesh an there went some think wrong wiht the class variabels