Thread: FAQ: Graphics Math

  1. #16
    Registered User crepincdotcom's Avatar
    Join Date
    Oct 2003
    Posts
    94
    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.
    -Jack C
    jack {at} crepinc.com
    http://www.crepinc.com

  2. #17
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    To further illustrate here is a shot from my project in texture mode.

  3. #18
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.
    Last edited by VirtualAce; 10-04-2004 at 11:45 AM.

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.

  5. #20
    Registered User crepincdotcom's Avatar
    Join Date
    Oct 2003
    Posts
    94
    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,
    -Jack C
    jack {at} crepinc.com
    http://www.crepinc.com

  6. #21
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Another example.

  7. #22
    Registered User crepincdotcom's Avatar
    Join Date
    Oct 2003
    Posts
    94
    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.
    -Jack C
    jack {at} crepinc.com
    http://www.crepinc.com

  8. #23
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.
    Last edited by VirtualAce; 10-04-2004 at 12:19 PM.

  9. #24
    Registered User crepincdotcom's Avatar
    Join Date
    Oct 2003
    Posts
    94
    Aha, thanks.
    Last edited by crepincdotcom; 10-04-2004 at 12:22 PM.
    -Jack C
    jack {at} crepinc.com
    http://www.crepinc.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 01:17 PM
  2. an easy, portable, python accessible graphics math library
    By ichijoji in forum Game Programming
    Replies: 2
    Last Post: 12-07-2006, 12:10 AM
  3. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  4. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  5. Min Math level req for 3d graphics?
    By EvBladeRunnervE in forum Game Programming
    Replies: 12
    Last Post: 02-24-2003, 10:32 PM