Capsule "Primitive"

Started by
4 comments, last by VitaliBR 13 years, 7 months ago
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,};
http://mateusvitali.wordpress.com/
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.
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?
http://mateusvitali.wordpress.com/
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

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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
http://mateusvitali.wordpress.com/

This topic is closed to new replies.

Advertisement