Archived

This topic is now archived and is closed to further replies.

Sokol

Few DirectX Beginner's questions

Recommended Posts

Hi 1.I have just ended looking at Directx SDK tutorial 4 about lightning And I''m curious abot one thing about drawing cylinder. There was, said, that cylinder was created Algorithmically. So Is there general algorithm for creating Cylinder, and can someone paste it(this algorithm) here??(I dont know if U can understand me, because my Englisch is poor and I can''t say exactly what I want). 2.Also i would like to know Why in this line of code is (void**), shouldnt it be (void*)?? if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )

Share this post


Link to post
Share on other sites
1. well the alghoritm for a cylinder would be like this:
(create an indexed primitive so in DX u''ll have a VB and a IB)


Sides = Number of sides of the base
Rings = Number of rings in which the height of the cyl will be split
Height = height of the cyl
Radius;

float angle = 2 * PI / Sides; //this is the angle between 2 consecutive vertices
float ringsize = height / rings;
int count = 0; // number of vertices

for (h = 0; h < rings; h++)
{
for (i = 0; i < Sides; i++)
{
vertexbuffer[count].x = cos(i * angle) * radius;
vertexbuffer[count].y = h * ringsize;
vertexbuffer[count].z = sin(i * angle) * radius;
count++;
}
}

//to make the cylinder solid (add the top and bottom polys)

vertexbuffer[count].x = 0
vertexbuffer[count].y = 0;
vertexbuffer[count].z = 0

for (i = 0; i < Sides; i++)
{
vertexbuffer[count].x = cos(i * angle) * radius;
vertexbuffer[count].y = 0;
vertexbuffer[count].z = sin(i * angle) * radius;
count++;
}

// now just make the IBs for the cyls which should be quite simple and render the body of the cyl as tri strips and the top and bottom as tri fans (render the base twice - the second time translate it Height units up)


if u need reference about VBs, IBs, tri strips or tri fans look them up in MSDN





/*ilici*/

Share this post


Link to post
Share on other sites
oh. after the

quote:

vertexbuffer[count].x = 0
vertexbuffer[count].y = 0;
vertexbuffer[count].z = 0


add


count++;


and (void**) will mean that if u declare an array
float* vertices;

u''ll pass it like &vertices

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
2.Also i would like to know Why in this line of code is (void**), shouldnt it be (void*)??
if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )



No, it is correct. pVertices is a pointer. &pVertices is a pointer to a pointer.

Share this post


Link to post
Share on other sites