Animation....

Animation....

Post by [j0k3r » Mon, 30 Jun 2003 19:07:51



Hi,

i've done a little ogl application: there are a triangle and a square
centered on the screen (both are white).

Before of render them i setup the camera ( using gluLookAt() and making the
camera face the 2 objects ).

I can also animate one of them (e.g.: i make the triangle rotate on his
z-axe CCW), but i can't animate BOTH !!!

I'll explain....

In my framework render() method i setup the camera that executes a simple
gluLookAt(), then i call the Render() method of all the objects that are in
my world (in this test only 2),like this:

Framework::Render
glColor3f(1,1,1);
 glClearColor(.0f,.0f,.0f,0.f);
 glClear( GL_COLOR_BUFFER_BIT );

_camera->Render()            // gluLookAt

_objects[0]->Render();            // Square
_objects[1]->Render();            // Triangle

Each object inherits from a virtual base class called BaseObject.

The main code of the Render() of the objects is :

calculation of deg (rotation degrees)

// Pivot is a private member that represent the rotation pivot
glTranslatef( _pivot.X(), _pivot.Y(), _pivot.Z() );
 glRotatef(- deg, 0, 0, 1);

 glBegin(GL_QUADS/GL_TRIANGLE);
    glVertex of each vertex
glEnd()

glLoadIdentity()

I can see only the first object that calls Render method (in this example
the square) and i see it in the right way (eg: rotating), but i can't see
the second one !

If i swap the 2 object[i]->Render calls i see only the triangle, not the
square...why ??

Thanks a lot !!!

 
 
 

Animation....

Post by - aartii » Mon, 30 Jun 2003 20:23:08


I can see only the first object that calls Render method (in this example

Quote:> the square) and i see it in the right way (eg: rotating), but i can't see
> the second one !

Let's see what your program do:

1. in camera->Render() you set up camera by calling "gluLookAt()"
2. in object[0]->Render() you draw the object (everything is ok)
   but then you call "glLoadIdentity()" - which reset camera position!
   You lost settings you made by gluLookAt(). That's why you can't
   see the second object.

Instead of using glLoadIdentity() i object render function, try this:

glPushMatrix();    // save actual matrix
    glTranslatef( _pivot.X(), _pivot.Y(), _pivot.Z() );
    glRotatef(- deg, 0, 0, 1);
    glBegin(GL_QUADS/GL_TRIANGLE);
        glVertex of each vertex
    glEnd();
glPopMatrix();    // restore saved matrix

- arti -

 
 
 

Animation....

Post by Jakob Bielin » Mon, 30 Jun 2003 20:26:47



Quote:> Hi,

> i've done a little ogl application: there are a triangle and a square
> centered on the screen (both are white).

> Before of render them i setup the camera ( using gluLookAt() and making
the
> camera face the 2 objects ).

> I can also animate one of them (e.g.: i make the triangle rotate on his
> z-axe CCW), but i can't animate BOTH !!!

> I'll explain....

> In my framework render() method i setup the camera that executes a simple
> gluLookAt(), then i call the Render() method of all the objects that are
in
> my world (in this test only 2),like this:

> Framework::Render
> glColor3f(1,1,1);
>  glClearColor(.0f,.0f,.0f,0.f);
>  glClear( GL_COLOR_BUFFER_BIT );

> _camera->Render()            // gluLookAt

> _objects[0]->Render();            // Square
> _objects[1]->Render();            // Triangle

> Each object inherits from a virtual base class called BaseObject.

> The main code of the Render() of the objects is :

> calculation of deg (rotation degrees)

> // Pivot is a private member that represent the rotation pivot
> glTranslatef( _pivot.X(), _pivot.Y(), _pivot.Z() );
>  glRotatef(- deg, 0, 0, 1);

>  glBegin(GL_QUADS/GL_TRIANGLE);
>     glVertex of each vertex
> glEnd()

> glLoadIdentity()

> I can see only the first object that calls Render method (in this example
> the square) and i see it in the right way (eg: rotating), but i can't see
> the second one !

> If i swap the 2 object[i]->Render calls i see only the triangle, not the
> square...why ??

    Try replacing the glLoadIdentity (which will 'reset' the matrix!) with
glPush- and glPopMatrix. First you save the current matrix, then you do the
transformations and then you restore the matrix. Like this:

glPushMatrix ();

glTranslatef( _pivot.X(), _pivot.Y(), _pivot.Z() );
 glRotatef(- deg, 0, 0, 1);

 glBegin(GL_QUADS/GL_TRIANGLE);
    //    glVertex of each vertex
glEnd()

glPopMatrix ();

hth
--
jb

(replace y with x if you want to reply by e-mail)

 
 
 

Animation....

Post by [j0k3r » Mon, 30 Jun 2003 20:49:26


Thx it works.....





> > Hi,

> > i've done a little ogl application: there are a triangle and a square
> > centered on the screen (both are white).

> > Before of render them i setup the camera ( using gluLookAt() and making
> the
> > camera face the 2 objects ).

> > I can also animate one of them (e.g.: i make the triangle rotate on his
> > z-axe CCW), but i can't animate BOTH !!!

> > I'll explain....

> > In my framework render() method i setup the camera that executes a
simple
> > gluLookAt(), then i call the Render() method of all the objects that are
> in
> > my world (in this test only 2),like this:

> > Framework::Render
> > glColor3f(1,1,1);
> >  glClearColor(.0f,.0f,.0f,0.f);
> >  glClear( GL_COLOR_BUFFER_BIT );

> > _camera->Render()            // gluLookAt

> > _objects[0]->Render();            // Square
> > _objects[1]->Render();            // Triangle

> > Each object inherits from a virtual base class called BaseObject.

> > The main code of the Render() of the objects is :

> > calculation of deg (rotation degrees)

> > // Pivot is a private member that represent the rotation pivot
> > glTranslatef( _pivot.X(), _pivot.Y(), _pivot.Z() );
> >  glRotatef(- deg, 0, 0, 1);

> >  glBegin(GL_QUADS/GL_TRIANGLE);
> >     glVertex of each vertex
> > glEnd()

> > glLoadIdentity()

> > I can see only the first object that calls Render method (in this
example
> > the square) and i see it in the right way (eg: rotating), but i can't
see
> > the second one !

> > If i swap the 2 object[i]->Render calls i see only the triangle, not the
> > square...why ??

>     Try replacing the glLoadIdentity (which will 'reset' the matrix!) with
> glPush- and glPopMatrix. First you save the current matrix, then you do th
e
> transformations and then you restore the matrix. Like this:

> glPushMatrix ();

> glTranslatef( _pivot.X(), _pivot.Y(), _pivot.Z() );
>  glRotatef(- deg, 0, 0, 1);

>  glBegin(GL_QUADS/GL_TRIANGLE);
>     //    glVertex of each vertex
> glEnd()

> glPopMatrix ();

> hth
> --
> jb

> (replace y with x if you want to reply by e-mail)

 
 
 

Animation....

Post by Alex Mizrah » Mon, 30 Jun 2003 20:57:21


Hello, [j0k3r]!
You wrote  on Sun, 29 Jun 2003 10:07:51 GMT:

 j> glLoadIdentity()

 j> I can see only the first object that calls Render method (in this
 j> example the square) and i see it in the right way (eg: rotating), but
 j> i can't see the second one !

 j> If i swap the 2 object[i]->Render calls i see only the triangle, not
 j> the square...why ??

i think you should preserve matrix by using glPushMatrix/glPopMatrix
like

Object::Render() {
    glPushMatrix();
    apply_transformation();
    perform_rendering();
    glPopMatrix();

Quote:}

With best regards, Alex Mizrahi aka killer_storm.