Jump to content
  • Advertisement
Sign in to follow this  
VitaliBR

OpenGL Capsule "Primitive"

This topic is 2950 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

I need draw a capsule, but dont know how.

In the example I'm using.
he uses the following information to draw, but is in opengl

static float gCylinderData[]={
1.0f,0.0f,1.0f,1.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f,
0.866025f,0.500000f,1.0f,0.866025f,0.500000f,1.0f,0.866025f,0.500000f,0.0f,0.866025f,0.500000f,0.0f,
0.500000f,0.866025f,1.0f,0.500000f,0.866025f,1.0f,0.500000f,0.866025f,0.0f,0.500000f,0.866025f,0.0f,
-0.0f,1.0f,1.0f,-0.0f,1.0f,1.0f,-0.0f,1.0f,0.0f,-0.0f,1.0f,0.0f,
-0.500000f,0.866025f,1.0f,-0.500000f,0.866025f,1.0f,-0.500000f,0.866025f,0.0f,-0.500000f,0.866025f,0.0f,
-0.866025f,0.500000f,1.0f,-0.866025f,0.500000f,1.0f,-0.866025f,0.500000f,0.0f,-0.866025f,0.500000f,0.0f,
-1.0f,-0.0f,1.0f,-1.0f,-0.0f,1.0f,-1.0f,-0.0f,0.0f,-1.0f,-0.0f,0.0f,
-0.866025f,-0.500000f,1.0f,-0.866025f,-0.500000f,1.0f,-0.866025f,-0.500000f,0.0f,-0.866025f,-0.500000f,0.0f,
-0.500000f,-0.866025f,1.0f,-0.500000f,-0.866025f,1.0f,-0.500000f,-0.866025f,0.0f,-0.500000f,-0.866025f,0.0f,
0.0f,-1.0f,1.0f,0.0f,-1.0f,1.0f,0.0f,-1.0f,0.0f,0.0f,-1.0f,0.0f,
0.500000f,-0.866025f,1.0f,0.500000f,-0.866025f,1.0f,0.500000f,-0.866025f,0.0f,0.500000f,-0.866025f,0.0f,
0.866026f,-0.500000f,1.0f,0.866026f,-0.500000f,1.0f,0.866026f,-0.500000f,0.0f,0.866026f,-0.500000f,0.0f,
1.0f,0.0f,1.0f,1.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f
};

static float gCylinderDataCapsTop[]={
0.866026f,-0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.500000f,-0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
0.500000f,-0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,-1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,-1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.500000f,-0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.500000f,-0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.866025f,-0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.866025f,-0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-1.000000f,-0.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-1.000000f,-0.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.866025f,0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.866025f,0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.500000f,0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.500000f,0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
-0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.500000f,0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
0.500000f,0.866025f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.866025f,0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.866025f,0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
1.000000f,0.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
1.000000f,0.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.000000f,1.000000f,1.000000f,0.000000f,1.000000f,1.000000f,
0.866026f,-0.500000f,1.000000f,0.000000f,1.000000f,1.000000f,
};

static float gCylinderDataCapsBottom[]={
1.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.866025f,0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.866025f,0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.500000f,0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.500000f,0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.000000f,1.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.000000f,1.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.866025f,0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.866025f,0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-1.000000f,-0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-1.000000f,-0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.866025f,-0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.866025f,-0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,-0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
-0.500000f,-0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,-1.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,-1.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.500000f,-0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.500000f,-0.866025f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.866026f,-0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.866026f,-0.500000f,0.000000f,0.000000f,-1.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
1.000000f,0.000000f,0.000000f,0.000000f,-1.000000f,0.000000f,
};

Share this post


Link to post
Share on other sites
Advertisement
It may be easier to create a cylinder mesh and a sphere mesh (D3DXCreateCylinder and D3DXCreatesSphere) and draw the sphere twice, once at each end of the cylinder.

Otherwise, you'll have to figure out how that data is organized (it's not obvious to me), and either create a verterxbuffer or mesh to load the data into.

Share this post


Link to post
Share on other sites
Quote:
Original post by VitaliBR
he uses the following information to draw, but is in opengl
I'm not quite sure what that data represents, but raw mesh data can't really be 'in OpenGL'. Mesh data is mesh data.

As for rendering a capsule, you could draw a cylinder and two spheres as previously suggested. Or, you could generate an 'actual' capsule mesh procedurally, which isn't *too* hard (although it's more involved than making a cylinder mesh).

Or, maybe there's an existing capsule mesh floating around online somewhere.

Share this post


Link to post
Share on other sites
I was thinking about doing with cylinder mesh and a two sphere meshs

the height of the capsule would be:
(radius/2 of sphere1) + (Length of cylinder) + (radius/2 of sphere1)


and radius of the capsule would be the radius of sphere mesh and cylinder mesh

right?

Share this post


Link to post
Share on other sites
Quote:
the height of the capsule would be: (radius/2 of sphere1) + (Length of cylinder) + (radius/2 of sphere1)

Not sure why you have the '/2' in there.

Length = sphere-radius + cylinder-length + sphere-radius

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
Quote:
the height of the capsule would be: (radius/2 of sphere1) + (Length of cylinder) + (radius/2 of sphere1)

Not sure why you have the '/2' in there.

Length = sphere-radius + cylinder-length + sphere-radius



me too

lol

thanks guy

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!