Pure Rb Code 3D – Tetrahedron

A short entry today. I’ve created a new plg text file that defines a tetrahedron. I found some files on the net that defined this shape and adapted them to the plg format; easily done actually. A tetrahedron is a four vertex, four triangle faced geometric model. Be sure and watch for the winding order of the defined polygon list. If they are not left-handed, counterclockwise like our engine is designed for, you may have to switch around the order of the defined face, vertex order. Why? The back face routine will not work properly, review the RemoveBackface Method if this is not clear. I just used it as I found it, ran it through this demo app and observed if the back faces are properly rendered, if not, switch them.

Here’s an example line from our text file defines a polygon list,

0xd0f0 3 0 2 1

The first hex digit is a color, in this case, green. The 3 means this is a three vertex polygon, a triangle and the 0, 2, 1 defines the vertex order. If this were a clockwise designed model, all you do is switch the last two to give you a winding order of, 0, 1, 2.

The example project is just like the previous project, substituting the tetrahedron.plg file that our program loads up during initialization. If you run it right after changing the model file, the model will be barely visible because of the way the model is defined, scale wise that is. So, I just scaled it up 50 units and was good to go.

Download Projects Here …..

**************************************************************************************************
This is this installments link. It’s an online book (free) that’s for the iPhone, but it has a lot of very cool chapters on OpenGL that may help you understand some concepts, I know it helps me.

iPhone 3D Programming

One thing that Chapter 4 discusses is using a simple file format called ‘.obj’. I’m thinking I might write a parser to use this file format too. As I’ve mentioned, parsers and me don’t have much fun together, but it doesn’t look too hard and there are some nice .obj files in the public domain we could use.

About bigdaddytom

Hobbyist programmer, self taught, started with Rb in 1999. Xcode, Objective-C iPhone coder too. I have been blessed being able to live in Hawaii for over three decades. Proud father of two. Business owner. The above image is from atop Mauna Kea looking towards Mauna Loa on the big Island of Hawaii.
This entry was posted in Code. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>