-
Thank you VERY much for the informative post! btw: in terms of using the API to finish a triangle, the reason I'm asking all these questions is that I'm not using an API. If I did, even though I would have a nice app, I wouldn't understand the math as well.
Again, thank you. :)
-
To further illustrate here is a shot from my project in texture mode.
-
Here is a shot from nearly the same location in wireframe mode. Notice that the texture's are still applied to the lines (if you can see that in the screen shot) so this is not pure wireframe mode, but it's close.
I had to ramp the RGBs to get this to display right. Hope you can see it.
You can see that my sphere's are made up of a bunch of flat faces. The flat faces are then divided into 2 triangles. So you can see the triangles in this pic quite well.
Also the lighting is turned on in this pic and the light source is directly behind the camera. I softened the image a bit so you can see the lines better.
The big blue lines behind the sphere (they are behind it, but you can see through the sphere now so they show up) are from the backdrop sphere. Notice in the texture picture that there is a big space backdrop texture. This is simply a huge textured sphere that is always centered around the camera. In the wireframe mode pic you can see the background sphere as well as the planet sphere.
To visualize the square faces in your mind, mentally take out all the diagonal lines in the wireframe pic. Now put em back in and you have the triangles. They were created exactly the same way I explained and illustrated in my post.
-
Just in case you are having probs picking out the tris - I have color highlighted the tris according to the example picture I showed you above.
Red corresponds to triangle 1, and yellow corresponds to triangle 2.
-
OH MY GOD! You are like a god! That's absolutly the coolest thing I've ever seen! I can't even make a spinning wireframe box, and you not only made a wireframe sphere, but also textured!
Just thought I'd say, I worship you man!
Thanks again,
-
-
Hold on, I think I just understood something after re-reading your posts. So, that entire wireframe sphere is simply squares, rotated and skewed to fit the surface of the sphere, then cut in half as triangles?
Wow, that's really cool.
-
Yes it is. Every model is composed of triangles. Now not all models decompose neatly into squares, but a lot of them do. Mine does because the sphere is created mathematically into quads or squares and then the squares are made into 2 triangles...or they are triangulated.
The rotation and all of that in my later pics are just a result of all the transformations the vertexes undergo as a result of the rendering pipeline or the method used to get the graphics from 3D to 2D.
Terrains also usually decompose neatly into triangulated quads or squares.
Here is the order for the render I showed you.
1. Model is created in model space centered at 0,0,0.
2 Model is created using mathematical equation of a sphere.
3. Vertexes are created from spherical coordinates resulting from equation.
4. Vertex normals are calculated by simply using the normalized or unit vertexes (basically where the vertexes would be if the radius of the sphere was 1.0f or 1 unit).
5. Formula:
These axes have been altered somewhat to fit my system.
-180<beta<180
0<alpha<360
alpha_increment=number of slices (longitude)/360.0f
beta_increment=number of stacks (lattitude)/360.0f
x=sin(beta)*cos(alpha)
y=sin(beta)*sin(alpha)
z=cos(beta)
normal.x=x
normal.y=y
normal.z=z
x=x*radius
y=y*radius
z=z*radius
vertex.x=x
vertex.y=y
vertex.z=z
alpha+=alpha_increment;
if (alpha>360.0f) beta+=beta_increment;
6. Spherical texture coords are generated along with vertex data.
7. Indexes into the vertex array are created - thus triangulating each four sided square into two triangles.
8. Model is assigned D3DMATERIAL9 material for lighting.
9. Model texture is loaded.
Rendering:
10. Model is rotated in model/local space.
11. Model is translated to world location.
12. Model is rotated in world space.
13. Model is transformed to world space. world=(model_rot)*(world_loc)*(world_rot)
14. Model is transformed to view space based on camera rotation, translation/position, etc. - too complex to list here. view=world*camera
15. Model is transformed to clip space by Direct3D. clip=view*clip_matrix
16. Model is lit by Direct3D.
17. Model is transformed to screen space by Direct3D.
18. Model is culled and textured by Direct3D using video card driver.
The first 9 steps are only performed at load time. The rest are done every frame.
-