Jump to content
  • Advertisement
Sign in to follow this  
Dunge

Creating a cylinder with texture coordinates

This topic is 5011 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've been trying to create a simple cylinder and add a texture on it but couldn't manage to do it. I though I could use D3DXCreateCylinder and that would do it but when I set a texture on it, it just take the first pixel (0,0) of the texture and put his color everywhere on the cylinder. After asking a bit on IRC I've got told you can't specify the texture coordinates for a cylinder created with D3DXCreateCylinder. So now I'm asking for a place where to find a code who create a cylinder specifying every points and texture coordinates using code (loops, sin/cos). I've already stydied something similar for a sphere but it's not exactly the same and it's been a while..

Share this post


Link to post
Share on other sites
Advertisement
Tutorial 5 in the SDK creates a cylinder manually, with texture coordinates. Here is the geometry algorithm they use:


for( DWORD i=0; i<50; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(50-1);

pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
pVertices[2*i+0].color = 0xffffffff;
#ifndef SHOW_HOW_TO_USE_TCI
pVertices[2*i+0].tu = ((FLOAT)i)/(50-1);
pVertices[2*i+0].tv = 1.0f;
#endif

pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
pVertices[2*i+1].color = 0xff808080;
#ifndef SHOW_HOW_TO_USE_TCI
pVertices[2*i+1].tu = ((FLOAT)i)/(50-1);
pVertices[2*i+1].tv = 0.0f;
#endif
}

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!