OpenGL Library for Delphi,
maintained by Eric Grange,
based on Mike Lischke's GLScene.

 

User Tutorials - Control Objects


So we know how to move thing around in 3D space but we still need to learn how to manage their orientation. This topic will explain the do's and don't of Object orientation.

Object orientation is basically the art of rotating an object around it's X, Y and Z axis.

So far we have explained every step in detail. Before we continue we will list knowledge we assume from now on. We assume you know how to:

* Open the scene editor
* Add objects to the scene
* How to select objects
* How to access the objects properties.


Now we have a 3D cube in a viewer we can start messing around with the cubes position. The coordinate system in GLScene uses three axis that are perpendicular to each other. The manage placement in X, Y and Z direction.

Let’s illustrate this by turning on the “Show Axis property of the cube.

* Select the cube in the object inspector and set the “Show axis” property to True


A 3 colored axis system is now shown.

image
 

The three axis you see here are the X, Y and Z axis.

X axis is Red
Y axis is Green
Z axis is Blue

The intersection of these three axis is coordinate X=0.0, Y=0.0 and Z=0.0 which is where the cube is currently placed. We call this system of coordinates a coordinate system. Now here is where things may become confusing:

Every object has it’s own coordinate system!

For now just accept this as a fact. Later you will find out the incredible power that can be gained from having this feature.

By default objects created in GLScene have a size of 1 unit. Therefore the cube is 1 unit wide, 1 unit height and 1 unit deep. You may wonder how large a unit is but in our 3D world a unit is whatever you want it to be as long as you are consistent. A unit can be an inch, a furlong, a centimeter or the length of your little pinky.

Let’s move the cube along the x axis by changing the position.x property of the cube from 0 to 1. This should move the cube along the red X axis by exactly the width of the cube.

image
 

The result won’t be what you expected:
image
 


What happened? Well the cube moved along the X axis as intended but the camera is programmed to keep looking at GLCube1. So the camera turned to follow GLCube1 and the above image is the result.

We need to give the camera a fixed reference that does not move. A quick and easy way is to use another object that stays in place while the cube moves around.

Introducing the “Dummy cube”. This cube can be seen during design-time as a wireframe cube but is not rendered during run-time. The cube however is still very much part of the object structure. Let’s try this



Have a look at the form now.
image
 

The camera orientation has gone back to what it was before we changed the GLCube1 position.X coordinate. The white dashed wireframe shows the position of the GLDummyCube1. That is where the GLCube1 used to be.

Now play with the coordinates of GLCube1 a little. Change Position.X Y and Z and see if you can place the cube in the lower left corner of the viewer.
Coordinates in GLScene are of type Single. You can therefore enter fractions such as 0.43 and so on. Try both positive values and negative values.

Need to know:
The default values for a camera define a “NearPlaneBias” with a value of 1. When object come close to the camera they get clipped by this plane. This is the reason that the Cube in the above picture has a corner missing.

You can make this clipping go away by decreasing the “NearPlaneBias” from 1 to say 0.1


image
 

Once you feel familiar with the position coordinates you can go-ahead and move the cube to it’s final position:


We are now going to do some more work with coordinates. This time we will use a TGLLines object. TGLLines can draw a polyline in 3D space. The final line drawn can be made up of straight line segments or a spline can be drawn through its points.


The form will look like this:
image
 

As you can see the GLCube1 has moved down half a unit but there is no line anywhere in sight. This makes sense because we have yet to define the points that make up the line.

We are going to create the outline of a simple house shape. The points of a TGLLines object are called nodes. Let’s add a few nodes and keep an eye on the form to see where they end up.

To make identification of the node points easier we will set a few properties first.

image
 

We have now told GLLines1 to draw it’s lines in aqua marine color 4 pixels wide and mark every node in the polyline with a cube with a size of 0.1 units wide, high and deep.

Let’s get to work and add some nodes.

image
 

Click on the familiar “Add” button to add a node. Each node can be given a color and an X,Y,Z coordinate. Lets start with the top of the roof of our house shape:

image
 

Add nodes until you have the following collection:
image
 

Try not to look and figure out the coordinates for yourself to obtain this shape:
image
 


Need to know:
Note how all Y values have been left to 0. In GLScene the Y axis is going “up”. The above GLLines1 object is flat with all it’s Y coordinates set to zero.

 

Can you create a set of nodes that allows the house to stand upright? I bet you are bored with coordinates. Same here, let’s see if we achieve this upright house in a different way.

There are two things that define an object in space. Position and Orientation. We know about position now. The next tutorial will teach you how to manage an objects orientation through rotation. Make sure you save the work you have done so far because the next tutorial is based on it.
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.1126 seconds