Advertisement

Why does this happen?

Started by January 06, 2002 10:51 AM
26 comments, last by SonShadowCat 23 years, 1 month ago
What I need to know is why this code causes the triangles to act like a tornado(kinda) and not move together in a straight line here is the code
  

int DrawGLScene(GLvoid)								// Here''s Where We Do All The Drawing

{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear The Screen And The Depth Buffer

  glLoadIdentity();  // Reset The Current Modelview Matrix

  glTranslatef( xpos, ypos, zpos);  // Move 1.5 left and 8.0 out=


  glBindTexture(GL_TEXTURE_2D, texture[0]);  // Select a texture to use


    for (GLfloat x=1.0f; x<=2.0f; x+=1.0f)
    {
      for (GLfloat y=1.0f; y<=2.0f; y+=1.0f)
      {
        for (GLfloat z=1.0f; z<=2.0f; z+=1.0f)
        {
          glTranslatef( (x+2.0f), (y+2.0f), (z+2.0f));  // Move the screen          

          glRotatef( xrot, -1.0f, 0.0f, 0.0f);
          glRotatef( yrot, 0.0f, 1.0f, 0.0f);

          glBegin(GL_TRIANGLES);
            triangle.DrawTriangle();  // Draw a triangle

          glEnd();
        }
      }
    }

  xrot+=0.4f;
  yrot+=0.4f;

  return TRUE;  // Everything Went OK

}


I beg of you, plz help me

thx 

P.S. To see the effect that is does so you can better understand and explain, you can d/l the thing at www.geocities.com/sonshadowcat2000/tornado.zip
  
"Those who serve no purpose, have no purpose. SSC the Super Saiyan Cat"
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
If you''ll look into the documentation of the glRotate* and glTranslate* functions you''ll see that they multiply the current matrix with the according transformation matrix. This results in a concatenation of your transformations (until you load the identity matrix).
So what you''re doing is applying the first transformation, drawing the first triangle, the you "add" the new transformation to the current one and draw the next.
If you would only have translation, the following would happen (translation is a, position of the first tri is x)
1. Draw the triangle at x
2. translate by a, thus drawing at x+a
3. translate by a, thus drawing at x+2*a
...
Advertisement
say what?

uhh its gonna take me a while to decipher all the words you said

"Those who serve no purpose, have no purpose. SSC the Super Saiyan Cat"
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
is there any way you make ure explination simpler since im a newb and not sure what you mean

"Those who serve no purpose, have no purpose. SSC the Super Saiyan Cat"
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
Look at it like this.

  this is X axis before rotation (.=center)---.---now you translate 3 to the right------.now rotate\ \  \   .now if you translate again, it translates using the rotation! for example, let''s now translate -1 on the X axis\ \  .   \  


Get it? So everything you do adds up. To have this NOT happen, you would rotate, draw something, then you can call glLoadIdentity() to start from scratch.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Simple-Worded Form


Which means that if you translate, then rotate the x axis, which is

  ---and after rotation\ \  \  


and then you translate again, you are translating along a rotated x axis.

------------------------------Put THAT in your smoke and pipe it
Advertisement
So SonShadowCat, do you get it then?

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
oh dawg, I get it now

but i have tried putting glLoadIdentity() after i draw but then all the triangles are drawn in the exact same place not in a mine field manner i was looking for

"Those who serve no purpose, have no purpose. SSC the Super Saiyan Cat"
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday
Well, if your only problem is the rotations then I suppose you could just rotate the reverse of what you had rotated to keep your translations. Maybe I''m not thinking here... maybe.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
have you d/l the project?
i dont get how simple rotations turned a weird mine field into a freaking tornado

"Those who serve no purpose, have no purpose. SSC the Super Saiyan Cat"
--------------------------------- "Those who serve no purpose, have no purpose."- SSC Oh the possibilities!!Edited By - SonShadowCat on Your Girlfriends Birthday

This topic is closed to new replies.

Advertisement