|
Direct X 8 Tutorial 04
I was going through the Direct X 8 tuts 04 which explains lights. I came upon a Function that I have a lot of questions and the DX docs dont really explain.
The first question I have is in the CreateVertexBuffer call the very first parameter is the sife of vertex structure times the number of vertices so what is the extra 2 there for? Is it because you have two varibles in the structure, but wouldnt those be taken care of in the sizeof(CUSTOMVERTEX).
Also I cant really understand how and why they are calculating their angle(theta) like that.
And the last question I have would be in the
pVertices(2*i+0).position
why not just do pVertices(i)? for the position and the normal?
Thanks
January 24, 2001 03:30 PM
Hehe, why dont you read DirecX8 tut1 and tut2 on what the vertex buffer is about.
The other stuff is just a formula to make a cylinder, I read these tutorials a couple weeks ago, they explain everything fairly decently.
Possibility
The other stuff is just a formula to make a cylinder, I read these tutorials a couple weeks ago, they explain everything fairly decently.
Possibility
Hi
your 1st question well, noone knows... god nkows what they are thinking at ms.
2nd:
well, they are doing i*2+1 / 0 because they are creating a cylinder, and that needs depth (y-axis)
but the cylinder isn''t really part of the turotial.. it''s just something with a few faces with different angles
your 1st question well, noone knows... god nkows what they are thinking at ms.
2nd:
well, they are doing i*2+1 / 0 because they are creating a cylinder, and that needs depth (y-axis)
but the cylinder isn''t really part of the turotial.. it''s just something with a few faces with different angles
sorry misread the question
well the *2 in the first part is related to the *2 in the second and the +1.. the cycilnder has 50 faces on each half.
well the *2 in the first part is related to the *2 in the second and the +1.. the cycilnder has 50 faces on each half.
OK, let's see. If you can't figure this out, you might sorta need to know some more math. 3D programming is not for the mathematically disabled
But anyways, I'll try to explain what I can.
The goal of this code is to generate a simple cylindre (with no end caps). The intent is obviously to have 50 vertical lines making up the border. That would mean a circle of 50 vertices for the top, and 50 vertices for the bottom, right? So you will need 50*2 vertices to make the cylindre. So the size in bytes needed to store these vertices is 2*50*sizeof(yourvertex). Makes sense?
The angle is calculated in radians, not degrees. That means there are 2*PI radians in a circle (so 2PI rad = 360 degrees). So, if we want to make a circle of vertices, we need to multiply the maximum angle (the one equal to a full turn, or 360 deg, or 2*PI radians) by the fraction of the circle already generated, right? The fraction is (the i-th vertex / total vertices to be plotted ), which is (i / 50-1). Minus one, because i goes from 0 to 49, so the last vertex, after you make a full round, should not be plotted, since it already exists as the first vertex. So you get: (2*PI) * (i / 50-1), or (2*PI*i) / (50-1). Makes sense?
Now the last question. In each iteration, you see two vertices being generated. One for the top circle, and the corresponding one for the bottom circle. Since i = 0 to 49, i counts pairs of vertices, not single vertices (remember, there are 100 lines, 50 vertices). Therefore, it has to do vertices 1 and 2 (top, bottom), then 3 and 4, then 5 and 6, ... , 2*i and 2*i+1, ... see? So it is pVertices[2*i] and pVertices[2*i+1]. The "+0" is only for alignment purposes. The compiler ignores it. Makes sense?
Now, in case you didn't catch why they plot the (x,z) of the vertices as (sinf(theta),cosf(theta)). This comes from the unit circle. Take a circle or radius r. Then define an angle "theta" from the line that goes through (0,0) and (1,0) to the like going through (0,0) and the current point on the circle. The angle, in radians, will also equal the arch displacement on the circle. And if you break up the vector from the origin to the point on the circle into a horizontal and vertical component, those will equal cos(theta) for the horizontal and sin(theta) for the vertical. Makes sense?
If any of those don't make sense, feel free to e-mail me, k? I'm pretty bad at explaining (especially when not in real time), and I'd like some practice
And by the way, these things are WAAAY basic, so if you have trouble here, perhaps 3D programming would be too hard for ya. You decide though.
My e-mail is: dusik2000@yahoo.com
Dusik
Edited by - dusik on January 24, 2001 5:17:00 PM
![](wink.gif)
The goal of this code is to generate a simple cylindre (with no end caps). The intent is obviously to have 50 vertical lines making up the border. That would mean a circle of 50 vertices for the top, and 50 vertices for the bottom, right? So you will need 50*2 vertices to make the cylindre. So the size in bytes needed to store these vertices is 2*50*sizeof(yourvertex). Makes sense?
The angle is calculated in radians, not degrees. That means there are 2*PI radians in a circle (so 2PI rad = 360 degrees). So, if we want to make a circle of vertices, we need to multiply the maximum angle (the one equal to a full turn, or 360 deg, or 2*PI radians) by the fraction of the circle already generated, right? The fraction is (the i-th vertex / total vertices to be plotted ), which is (i / 50-1). Minus one, because i goes from 0 to 49, so the last vertex, after you make a full round, should not be plotted, since it already exists as the first vertex. So you get: (2*PI) * (i / 50-1), or (2*PI*i) / (50-1). Makes sense?
Now the last question. In each iteration, you see two vertices being generated. One for the top circle, and the corresponding one for the bottom circle. Since i = 0 to 49, i counts pairs of vertices, not single vertices (remember, there are 100 lines, 50 vertices). Therefore, it has to do vertices 1 and 2 (top, bottom), then 3 and 4, then 5 and 6, ... , 2*i and 2*i+1, ... see? So it is pVertices[2*i] and pVertices[2*i+1]. The "+0" is only for alignment purposes. The compiler ignores it. Makes sense?
Now, in case you didn't catch why they plot the (x,z) of the vertices as (sinf(theta),cosf(theta)). This comes from the unit circle. Take a circle or radius r. Then define an angle "theta" from the line that goes through (0,0) and (1,0) to the like going through (0,0) and the current point on the circle. The angle, in radians, will also equal the arch displacement on the circle. And if you break up the vector from the origin to the point on the circle into a horizontal and vertical component, those will equal cos(theta) for the horizontal and sin(theta) for the vertical. Makes sense?
If any of those don't make sense, feel free to e-mail me, k? I'm pretty bad at explaining (especially when not in real time), and I'd like some practice
![](wink.gif)
My e-mail is: dusik2000@yahoo.com
Dusik
![](wink.gif)
Edited by - dusik on January 24, 2001 5:17:00 PM
------------------------CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);pCrazyDuSiK->WebSiteURL = "http://www.geocities.com/dusik2000";
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement