glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glPointSize(2.0);
glTranslatef(0.0f,-4.0f,-10.0f);
glRotatef(zrot,0.0f,1.0f,0.0f);
vector[1]=0.0f;
glBegin(GL_POINTS);
for (vector[2]=0.0f;vector[2]<2.0;vector[2]+=0.5) {
for(vector[0]=0.0f;vector[0]<2.0;vector[0]+=0.1) {
glVertex3f(cos(3.14*vector[0])*2.0f,vector[1],sin(3.14*vector[0])*2.0f);
vector[1] += 0.1f;
};
};
glEnd();
What this produces is a single helix rotating constantly on the y
axis, the global variables are
GLfloat vector[3];
GLfloat zrot; (which is incremented somewhere else in my sloppy unoptimized code)
Now here''s the Pepsi challenge for ya and this one''s had me stumped for days now. How EXACTLY (and I don''t mean: in theory you just plug in yada yada yada for your translatef and rotatef coord''s) would you change this code up so that the movement from the camera is the exact same but instead of points being displayed you''d have objects like say a sphere (within reasonable subdivisions to run fast on any computer with a decent vid card) where each point should be? Obviously you can''t
just change up the glVertex3f code to gluSphere because you can''t input in the x,y,z coords for that function you''d have to do a translatef, but upon doing that you have to change up the whole code basically.
Betch ya can't figure this one out!
Here goes with the source:
so what your asking is how to make it apear like the cammera (which in opengl doesn''t realy exsist) is rotating around the object?
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
in a sense yes, just like in that example source I showed, I want the camera to look like it''s still while the object is rotating on its y axis. (which I guess if I had a 3d scene in the background would be the camera rotating around the object, but in actuallity, since I AM going to be making a scene I want the object(s) to remain in one place but rotate.
An easy way to tackle this would be if you could specify x,y,z coords for an object like glusphere without using translatef.
you could cheet by doing a
glTranslate3f(x,y,z);
draw sphere
glTranslate3f(-x,-y,-z);
not the best way, but hey it works
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
glTranslate3f(x,y,z);
draw sphere
glTranslate3f(-x,-y,-z);
not the best way, but hey it works
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
glLoadIdentity(); glDisable(GL_TEXTURE_2D); // glPointSize(2.0); //glTranslatef(0.0f,-4.0f,-10.0f); vector[1]=0.0f; for (vector[2]=0.0f;vector[2]<2.0;vector[2]+=0.5) { for(vector[0]=0.0f;vector[0]<2.0;vector[0]+=0.1) { glPushMatrix(); glRotatef(zrot,0.0f,1.0f,0.0f); glTranslatef(cos(3.14*vector[0])*2.0f,-4.0f+vector[1],-20.0f+sin(3.14*vector[0])*2.0f); gluSphere(quadratic,0.2f,4,4); glPopMatrix(); //glBegin(GL_POINTS); //glVertex3f(cos(3.14*vector[0])*2.0f,vector[1],sin(3.14*vector[0])*2.0f); //glEnd(); vector[1] += 0.1f; }; };
This finally DRAWS the object right, but the whole helix rotates around 0,0,0 is there a way I can set that whole helix to rotate around 0,0,-20.0f?
I just tried your method btw of translating by the negative coords after drawing the object, didn''t quite work.
sure it does, try this
i just droped it into my code so i had to make the vars xx,yy,and zz, to keep conflicts down. anyway i used the glut function for a wire sphere and it draws the spheres right where the points were
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
glLoadIdentity();glDisable(GL_TEXTURE_2D);glPointSize(2.0);glTranslatef(0.0f,-4.0f,-10.0f);glRotatef(zrot,0.0f,1.0f,0.0f);vector[1]=0.0f;//glBegin(GL_POINTS);for (vector[2]=0.0f;vector[2]<2.0;vector[2]+=0.5){ for(vector[0]=0.0f;vector[0]<2.0;vector[0]+=0.1) { xx = cos(3.14*vector[0])*2.0f; yy = vector[1]; zz = sin(3.14*vector[0])*2.0f; glTranslatef(xx,yy,zz); glutWireSphere( .2, 12, 12); glTranslatef(-xx,-yy,-zz); vector[1] += 0.1f; };};//glEnd();
i just droped it into my code so i had to make the vars xx,yy,and zz, to keep conflicts down. anyway i used the glut function for a wire sphere and it draws the spheres right where the points were
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
I just found out a WAY better way, all you have to do is after the Pushmatrix you do a translate to 0,0,-20 and then take out the -20 in the z coords and now it''s doing EXACTLY what I want it to do! Odd but I guess it takes that first translate after a pushmatrix to store the pivot point for the object.
That's what glPushMatrix() is for...
your (pseudo)code should look something like this -
glLoadidentity();
// Draw rest of scene, world, etc here if you like
glPushMatrix();
glTranslate(xx, yy, zz);
glRotate(zrot, 0.0f, 1.0f, 0.0f);
// Draw sphere/helix here
glPopMatrix();
// Rest of code...
Remember that glRotate/glTranslate work in _reverse_ order. So here it will rotate your shape around <0,0,0> (all rotations are around <0,0,0>), _then_ translate the rotated model to the new coordinates. It seems a strange way to do things, but it is a side effect of the way that matrices work.
The code to draw your object doesn't need any extra code to move/rotate it. Just draw it at the origin, always facing the same direction, the push/translate/rotate/pop bits will sort out everything else for you.
You need the glPopMatrix as well otherwise anything that you draw afterwards will be rotated and translated as well. apologies if you knew this, but it was missing from the last code post, so I thought I'd better mention it.
I hope this helps.
Dan
Edited by - danbrown on September 28, 2000 1:56:42 PM
your (pseudo)code should look something like this -
glLoadidentity();
// Draw rest of scene, world, etc here if you like
glPushMatrix();
glTranslate(xx, yy, zz);
glRotate(zrot, 0.0f, 1.0f, 0.0f);
// Draw sphere/helix here
glPopMatrix();
// Rest of code...
Remember that glRotate/glTranslate work in _reverse_ order. So here it will rotate your shape around <0,0,0> (all rotations are around <0,0,0>), _then_ translate the rotated model to the new coordinates. It seems a strange way to do things, but it is a side effect of the way that matrices work.
The code to draw your object doesn't need any extra code to move/rotate it. Just draw it at the origin, always facing the same direction, the push/translate/rotate/pop bits will sort out everything else for you.
You need the glPopMatrix as well otherwise anything that you draw afterwards will be rotated and translated as well. apologies if you knew this, but it was missing from the last code post, so I thought I'd better mention it.
I hope this helps.
Dan
Edited by - danbrown on September 28, 2000 1:56:42 PM
Dan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement