3D Primitive commands
3D Primitive commands:
(Listed in the order in which they should defined in a model string):
Commands are in curly brackets { }. Parameters are in parentheses ( ). Parameter values are floating point values (shown as # in descriptions below) separated by a comma.
{W}(#,#,#)
ie.
{W}(2,2,2)
This command describes the new world coordinate system. The three parameter values describe the scaling for each axis (X,Y,Z)
{P}1(#,#,#)2(#,#,#)3(#,#,#) ...
ie.
{P}1(-100,100,-100)2(100,100,-100)3(100,-100,-100)4(-100,-100,-100)
This command defines Points in your model. Points are not drawn. They are simply used to define the vertexes (ie. corners of a box) used later to define faces. A face is a Polygon. The order of the points is important. The first point coordinate defined is for Point 1. The second coordinate is for point 2 and so on. You can put reference numbers before each point definition to make it easier for you when writing the command strings. They will simply be ignored, since all parameters must be between the ( ) characters. Points are defined with 3 parameter values for the X,Y and Z coordinates of the point. You can define a maximum of 50 points at a time. The next {P} command will delete the previous points and define new ones.
{M}(#)
ie.
{M}(1)
This command defines the current material offset. All 3D objects must use at least one material. This is called the primary material (offset 1). You can though define your model to use more materials. The objects when drawn will use whatever is the current material offset last called before the command. It is best to have no more than 255 material offsets, but you can use more if need be for 3D primitives. As a rule it is best to use a minimal number of materials for your 3D object. This command can be dispersed among different drawing sections of the 3D Primitive command string to change the material for different parts of the object.
The following commands actually draw parts of your 3D primitive.
It is important to note, that when you draw polygons, etc. there has to be a way to determine which side of the polygon is the front and which is the back. This is critical for lighting and the calculating of normals (for lighting). OpenGL does it this way:
The front side of a Polygon has its vertexes (points) defined in a counter-clockwise order. The back side of a Polygon has it vertexes (points) defined in a clockwise order. So the order in which you define the vertexes (points) of the Faces in your model are important and effect how the object appears in light.
The two primary Polygons provided are Triangles (3 vertexes) and Quads (4 vertexes). Quads are tricky because the quads (ie. rectangle) drawn must always be within a single plane (no twisty stuff). They need not be parallel to any of the primary axis (X,Y,Z), they just need to be on a single place (imagine a sheet of paper running through the four points, if the paper can lay flat, you are fine, if the paper must bend, then that is an invalid quad).
Quads need not be rectangular though (the corner angles need not be 90 degrees).
Here is the Quad drawing command:
{Q}(#,#,#,#)(#,#,#,#)(#,#,#,#) ...
ie.
{Q}(1,2,3,4)
The four parameter values for each Quad, are not coordinates. They are the index to the points you defined in the {P} command. To define a quad you simply use the indexes to four of those points. Now remember the counter clockwise rule for defining which side is the front.
You can define multiple quads with one command like this:
{Q}(1,2,3,4)(4,5,6,7)(7,8,9,10)
The next polygon is the triangle.
The command is:
{T}(#,#,#)(#,#,#)(#,#,#) ...
ie.
{T}(1,2,3)(3,4,5)(5,6,7)
This command works just like the Quad command, except you define just 3 points for each triangle. You can define multiple triangles with each command as well. Since triangles can never be bent (always on one plane), you don't have to worry about whether your triangle fits on one plane, like with quads. Remember the counter clockwise rule for determining which side is the front. The parameter for each triangle contains the three indexes to the points as previously defined with the {P} command, just like you do with quads/
The next drawing commands are complex objects, rather than simple polygons.
To draw a Sphere the command is:
{S}(#,#,#,#)(#,#,#,#)(#,#,#,#) ...
You can draw multiple spheres with this command.
The four parameter values for each sphere are as follows:
(in this order)
Radius - Radius of the Sphere
Slices - number of divisions horizontally
Stacks - number of divisions vertically
Center - index to point which will act as the center of the sphere
(0 means use world origin)
The next complex object is the Cylinder.
The command is:
{C}(#,#,#,#,#,#)(#,#,#,#,#,#)(#,#,#,#,#,#) ...
This command can draw multiple cylinders.
A Cylinder is always drawn in parallel to the Z axis. The top is forward (+Z) and the bottom is back (-Z). The center of a cylinder will be on the origin, unless you define a new origin point. You will be able to rotate a Cylinder with another command which is the {X} command which can be called before this command , but first let's create the cylinder.
The six parameter values for each cylinder are as follows:
TRadius - Radius of top end of cylinder
BRadius - Radius of bottom end of cylinder
Slices - number of divisions around cylinder
Stacks - number of divisions in length of cylinder
Length - length of cylinder
Center - index to point which will act as the center of the cylinder
(0 means use world origin)
If you make the radius of one end zero, you will get a cone.
Cylinders are not drawn with end caps (called disks). You will have to draw those end caps using the {D} command, if you want your cylinder to appear as if it is a solid cylinder when it is rotated.
Like quads you can draw multiple cylinders with one command.
The command to draw those end caps (called Disks) is:
{D}(#,#,#,#,#)(#,#,#,#,#)(#,#,#,#,#) ...
The five parameter values for each Disk are as follows:
ORadius - Radius of Outside of Disk
IRadius - Radius of index of a Disk (can be zero) which allows
you to draw a ring shaped disk
Slices - number of divisions on outside radius
Stacks - number of divisions on inside radius
Center - index to point which will act as the center of the cylinder
(0 means use world origin)
If you use a non-zero radius for IRadius you will get a Ring shaped object (a Disk with round hole in the center)
This command can draw multiple disks.
Now we need a way to rotate cylinders or disks into their proper position (or orientation). To do this we use the {X} command.
The command is looks like this:
{X}(#)
The parameter has one value which means the following:
0 - Cylinder or Disk aligned with Z axis (default) and points to +Z
1 - Cylinder or Disk aligned with Z axis and points to -Z
2 - Cylinder or Disk aligned with X axis and points to +X
3 - Cylinder or Disk aligned with X axis and points to -X
4 - Cylinder or Disk aligned with Y axis and points to +Y
5 - Cylinder or Disk aligned with Y axis and points to -Y
By using the {X} command before the {C} or {D} commands you can orient your cylinders or disks in the right direction.