Jump to content
  • Advertisement
Sign in to follow this  
ukdeveloper

OpenGL [SOLVED] Evenly spacing groups of GL_QUADS around edge of gluDisk

This topic is 3337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks, I'm working on something in OpenGL as part of one of my course modules and I've got stuck, I'm afraid. It's more of a general logical question as opposed to OpenGL specifically but I think it's relevant. I've got a group of gluDisks which represent the circular part of a peg cog, and the GL_QUADS represents a peg on the cog. What I'm trying to do is to evenly position the correct number of pegs around the edge of the cog, and I'm having a hard time figuring out the logic of getting it all to work. Each cog has its radius as a field (it's a small class) and the circumference is calculated in the class constructor and stored. I then go on to calculate the number of possible pegs given the cog's circumference, and divide it by 2 so that there's proper spacing between them and it's a sensible amount of pegs. Each peg on the cog is drawn in a local co-ordinate system as follows:
void Cog::drawTooth()
{
glBegin(GL_QUADS);

			V.x = 0.0 - 0.0;
			V.y = 0.0 - 0.0;
			V.z = 0.15 - 0.0;
			W.x = 0.05 - 0.0;
			W.y = 0.0 - 0.0;
			W.z = 0.15 - 0.0;
			result = vector_helper.calculate_cross_product(V, W);
			glNormal3f(result.x, result.y, result.z);
			glVertex3f(0.0, 0.0, 0.0); // A
			glVertex3f(0.0, 0.0, 0.15); // B
			glVertex3f(0.05, 0.0, 0.15); // C			
			glVertex3f(0.05, 0.0, 0.0); // D

			V.x = 0.0 - 0.0;
			V.y = 0.05 - 0.05;
			V.z = 0.15 - 0.0;
			W.x = 0.05 - 0.0;
			W.y = 0.05 - 0.05;
			W.z = 0.15 - 0.0;
			result = vector_helper.calculate_cross_product(V, W);
			glNormal3f(result.x, result.y, result.z);
			glVertex3f(0.0, 0.05, 0.0);
			glVertex3f(0.0, 0.05, 0.15);
			glVertex3f(0.05, 0.05, 0.15);
			glVertex3f(0.05, 0.05, 0.0);

			V.x = 0.0 - 0.0;
			V.y = 0.05 - 0.0;
			V.z = 0.0 - 0.0;
			W.x = 0.05 - 0.0;
			W.y = 0.05 - 0.0;
			W.z = 0.0 - 0.0;
			result = vector_helper.calculate_cross_product(V,W);
			glNormal3f(result.x, result.y, result.z);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(0.0, 0.05, 0.0);
			glVertex3f(0.05, 0.05, 0.0);
			glVertex3f(0.05, 0.0, 0.0);

			V.x = 0.0 - 0.0;
			V.y = 0.05 - 0.0;
			V.z = 0.15 - 0.15;
			W.x = 0.05 - 0.0;
			W.y = 0.05 - 0.0;
			W.z = 0.15 - 0.15;
			result = vector_helper.calculate_cross_product(V,W);
			glNormal3f(result.x, result.y, result.z);
			glVertex3f(0.0, 0.0, 0.15);
			glVertex3f(0.0, 0.05, 0.15);
			glVertex3f(0.05, 0.05, 0.15);
			glVertex3f(0.05, 0.0, 0.15);

			
			V.x = 0.0 - 0.0;
			V.y = 0.05 - 0.0;
			V.z = 0.0 - 0.0;
			W.x = 0.0 - 0.0;
			W.y = 0.05 - 0.0;
			W.z = 0.15 - 0.0;
			result = vector_helper.calculate_cross_product(V,W);
			glNormal3f(result.x, result.y, result.z);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(0.0, 0.05, 0.0);
			glVertex3f(0.0, 0.05, 0.15);
			glVertex3f(0.0, 0.0, 0.15);


			V.x = 0.05 - 0.05;
			V.y = 0.05 - 0.0;
			V.z = 0.0 - 0.0;
			W.x = 0.05 - 0.05;
			W.y = 0.05 - 0.0;
			W.z = 0.15 - 0.0;
			result = vector_helper.calculate_cross_product(V,W);
			glNormal3f(result.x, result.y, result.z);
			glVertex3f(0.05, 0.0, 0.0);
			glVertex3f(0.05, 0.05, 0.0);
			glVertex3f(0.05, 0.05, 0.15);
			glVertex3f(0.05, 0.0, 0.15);

			glEnd();
}


Feel free to ignore the code for calculating the normals because it's not relevant for this. I know I'm also using an older version of OpenGL but that's what we've been told to use. The translations are done by the calling code, so I currently have:
for (int i = 0; i <= (circumference/0.05)/2; i++) // Each peg is 0.05 wide
		{
			glTranslatef((radius + i)-0.05, 0.0, -0.15);
			drawTooth(); // The aforementioned function
		}


What I need is a generic way of doing the translations, or a generic translation, so that they're all evenly spaced around the edge of the cog pointing out the way. The translation I currently have there works fine for the first one (as you'd expect) but the rest are all translated wrongly based on that. As I'm using the local co-ordinate system I don't see how this should be terribly difficult, but I'm tied in knots. Any tips? I'm getting kind of confused here; I know what needs to be done and understand it conceptually but I'm having difficulty with figuring out the implementation. Thank you very much in advance for any help you might be able to offer, ukd. [Edited by - ukdeveloper on October 26, 2009 4:18:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!