LWJGL Forum

Programming => OpenGL => Topic started by: beyhude on February 26, 2008, 20:32:45

Title: Centering model at origin
Post by: beyhude on February 26, 2008, 20:32:45
Hi everyone,

I have a vehicle and when I rotate it, it doesn't rotate at the origin.  I checked some forum posts but it didn't help (glTranslatef(-x,-y,-z) before and normal after the render...).

My code:


GL11.glPushMatrix();
{
GL11.glTranslatef(x, y, z);
GL11.glRotatef(90, 1, 0, 0);

GL11.glRotatef(radius-90, 0, 1, 0);

GL11.glTranslatef(-x, -y, -z);

head.render();

}
GL11.glPopMatrix();


And I must also say that the texture of the models I downloaded from Turbo Squid (.3DS) didn't load, just a color. GL11.glEnable(GL11.GL_TEXTURE_2D); is done.

Thanks by advance.
Title: Re: Centering model at origin
Post by: elias4444 on February 27, 2008, 02:26:59
SO much of this depends on how you're loading the model and how the model is formatted, that it makes your question almost impossible to answer.

Personally, I track the highest and lowest vertices for each axis upon loading the model, and then, once finished, I shift each vertex coordinate to position the whole model around a central origin. Of course, in my loader I also add the option to not center the model, because you don't always want to do that.

Title: Re: Centering model at origin
Post by: beyhude on February 27, 2008, 10:42:58
Ok, I understand. Thanks ;)