Page 8/36
Basic things you should know about 3D graphics
GLScene is a very powerful tool but you still need to know at least something about 3D
computer graphics. Skip this chapter if you are familiar with this topic. There is a lot of theory about
3D graphics. I only want to point out some basics and things specific to GLScene and OpenGL.
Coordinate system
A three dimensional world is described with three axes: X, Y, Z. They intersect in the origin
point at position [0,0,0] with 90° angle. The orientation of these axes can be a bit confusing. Math
conventions anticipate that the up and down axis is Y, left and right axis is X and the depth is
described by Z. But OpenGL standard says that Z is up and down and Y is the depth. X axis remains
the same. So you should remember that OpenGL coordinate system is different then for example the
one other 3D editing applications use. You can display objects axes by setting ShowAxes:=true.
They will be represented by red, green and blue dotted lines both design and run time. To make
things even more complicated some objects use the conventional coordinate system like TGLGraph
and TGLTerrainRenderer.
In the end which direction is up will depend on the camera rotation. You can position your
object in the scene in whichever orientation you like. By default a new object will be placed in the
direction facing positive Y axis and top of the object pointing to positive Z axis.
It is important to understand the difference between global and local coordinate system.
Every child object exists in its own local coordinate system. If parent changes its position or
rotation the child will move with the parent but its local position will remain the same although it
changed global position. This may look a bit complicated at the beginning but it is an important
feature that allows keeping the scene hierarchy well organized.
Floating point numbers
OpenGL uses single precision system. What does it mean? It means that every decimal
number is 8 bits long. Let's explain this more. Decimal numbers can have unlimited number of
digits after the decimal separator. The p constant is a good example. Computer can calculate the p
constant for as many digits as it's memory is capable of. But that is not very practical. So where do
we set the limit? Everyone can understand the difference between 3.14 and 3.1415926535. Delphi
has strong support for types. In Delphi we have single, double and extended types for decimal
numbers. Single is 8 bit long so it means the program allocates 8 bits of memory for it. The number
of digits is limited. The p constant would be 3.1415926 in single type format. But what happens if
we add 1000 ? The result should be 3000.1415926. But there are too many digits in this decimal
number for the single type format. What happens is that the last digits are trimmed and we get the
right length : 3000.1415. This model is simplified because the whole math is happening on binary
level but you get the picture.
Remember that single precision is not accurate enough when working with high numbers or
when you need extra precision. If you are doing some scientific calculations you can use extended
type to get more exact results. But if there is an OpenGL graphical output like a graph all extended
numbers will be down sampled to single precision.
It is not recommended to use Delphi's native Math unit with GLScene because the functions
in this unit are too slow for real time rendering. Avoid using Math unit if you can.
Vectors
Now when we know what floating point numbers are we can explain what they are used for.
GLScene beginner's guide, Jan Zizka, 2005