PDA

View Full Version : OpenGL SolidTeapot() how to place it in 3d world



ctrlvee
08-18-2011, 09:12 AM
ok,

so i have a teapot in my 3d world.

however, from my only ever experiences of using the teapot, when drawn it only ever appears at the centre of the world.

is there any code to move it to my desired location in the 3d world?

thanks

AleaIactaEst
08-18-2011, 10:14 AM
Using glTranslate*() and glRotate*() is the easiest way to change an objects position and orientation in 3d space. You can also scale an object using glScale*().

How that works is explained in detail in the red book, v1.1 is available at http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html

ctrlvee
08-18-2011, 10:51 AM
yeah, i am familair with glTranslate()

but when i tried doing that with the teapot it didnt respond. the code i used is below:

void teapot()
{
glPushMatrix();
glBegin();
glutSolidTeapot(2.0f);
glTranslate(10,5.0,10.0);
glPopMatrix();
glEnd();
}

Kampos
08-18-2011, 11:37 AM
try to change the glTranslate...
change the 10.0 to -10.0...
when you move the objects from screen to forward you use negative values....

ctrlvee
08-18-2011, 12:03 PM
Ok i am having a few problems with this code
1) glBegin(THIS PART NEEDS FILLING!) <- any idea what to put for the teapot? cause it cant be gl_quads for example... or can it?
2)even if i remove glBegin, the teapot is still at the centre :(

Alfonse Reinheart
08-18-2011, 12:21 PM
First, glutSolidTeapot renders a teapot. Calling glBegin/End around it will not work; it does the equivalent of this internally.

Second, glTranslate and glPopMatrix cannot be called within glBegin/End.

Third, calling glTranslate after rendering does nothing. All calls are executed in the order given. Changing the translation after you've rendered the thing is unhelpful.

ctrlvee
08-18-2011, 01:53 PM
Ok, got it, so how would i place (translate) the teapot before i call it?

BionicBytes
08-18-2011, 01:57 PM
By issuing glTranslatef before the gludSolidTeapot command.

ctrlvee
08-18-2011, 02:52 PM
wow, that works, can't believe I didnt think of that.

thanks mate :)