For version 0.7.0.
To top.  Up: User's guide index

3d graphics


This guide presents basic ideas and tools for 3d graphics in Shapes. A primary design goal has been to make a tight integration of 3d with 2d. With the ability to define surfaces in 3d comes a need to use light models to enhance the 3d experience, and we will look briefly at this towards the end of the guide.
Sections:    Geometry    Coordinates and paths    Basic drawing    Stereo images    Light modeling

Geometry

As was said above, tight integration of 3d with 2d has been a main design goal. The model used is that the 2d world is the image plane of a pin-hole camera, and coincides with the plane z = 0. When the 3d world is projected onto the image plane of the camera, the position of the eye (that is, the pin-hole of the camera) is ( 0, 0, zeye ), which the user can affect by binding ..Shapes..Geometry3D..@eyez, see the figure below.
Geometry of the view projection
Angry
The relation between the 3d scene and the 2d image plane where the 3d scene is projected by ..Shapes..Geometry3D..view. The source is not meant to be instructive.

Source: show/hide visit
The projection is performed by applying the function ..Shapes..Geometry3D..view. The reverse, to take an object in the 2d world and equip it with a z = 0 coordinate, is performed by the function ..Shapes..Geometry3D..immerse.
An alternative to ..Shapes..Geometry3D..immerse is ..Shapes..Graphics3D..facing, which is useful to position things as labels in a 3d scene.
One very important tool for the interaction between 3d and 2d is the use of tags. When tags in a 3d scene are viewed, they will be converted to 2d tags and reference the viewed version of the tagged objects. It is particularly useful to tag points in a 3d scene.

Coordinates and paths

Coordinates in 3d are entered according to coords-3D, for instance ( 3mm, 7mm, 1cm ).
At the time of writing, path construction in 3d is very limited compared to 2d, as there are no automatic choices of angles or distances to interpolation points. One can use both absolute and relative coordinates, though. An example of a path in 3d can be found in the straight stereo projection example below.
Fortunately many of the paths used in 3d lie in a plane, and can be constructed by creating them in 2d first, and then immerse and transform to get it in the right position.

Basic drawing

The functions ..Shapes..Graphics..stroke, ..Shapes..Graphics..fill, and ..Shapes..Graphics..fillstroke are applicable to paths in 3d. The operations are defined to generate objects that, when viewed, the corresponding 2d operations are applied to the view of the path. This means that filling and fill-stroking paths which are not contained in a plane may not be entirely wise. Surfaces that can be painted in the light model, described below, are basically limited to be flat and are not created by ..Shapes..Graphics..fill.
Arrowheads in 3d can be tricky to get right. See ..Shapes..Graphics / arrowheads for details. Also note the approach illustrated under ..Shapes..Graphics3D..facing.

Stereo images

Sometimes the pin-hole view of a 3d scene fails to give a good impression of a 3d scene, and then it may help to draw a the image in stereo. This means that one draws one picture for each human eye, and put the images side by side so that one can see both at the same time, and this often greatly enhance the illusion of a 3d scene if done correctly. There is no special support for drawing images in stereo in Shapes, but this section shows that there is no need for that; it is merely a question about applying the right transforms.
There are two approaches to stereo projections; to put the left eye's image to the left of the right eye's image, or vice versa. In the first case, one must look towards a point at infinity (or very far away, or beyond infinity…), and in the second case one must look towards a point between the image plane and the eyes. It is both a matter of personal comfort and taste, and technical reasons, which approach to choose. Since it is extremely difficult to look towards a point beyond infinity the first approach is limited to objects of smaller width than the distance between the eyes. This limitation is not present in the other approach, but at least for me it is very difficult to get the eyes to focus in this case (the brain thinks the object is much closer than the distance to the paper, and apparently this is more disturbing than when the brain thinks the object is at infinity even though the paper much closer than so.). The first approach is referred to as a straight stereo projection, while the other is referred to as a cross stereo projection.
To make a straight stereo projection, for the distance eyew between the eyes we shall make two projections of the scene, differing by a x shift of this length. Note that the scene is shifted to the left for the right eye, and vice versa, and hence the images have to be swapped before drawn. The following example shows this technique.
Straight stereo projection
Angry
A straight stereo projection, that is, the left eye's view to the left of the right eye's view. The simple geometry behind this is described in the text.

Source: show/hide visit
The next example shows the same application, but with a cross stereo projection.
Cross stereo projection
Angry
A cross stereo projection, that is, the left eye's view to the right of the right eye's view. The simple geometry behind this is not described in the text.

Source: show/hide visit

Light modeling

Surfaces whose color is affected by the light model are created using ..Shapes..Graphics3D..facet. Light sources are created using any of ambient_light, specular_light, or distant_light. When surfaces and light sources are combined in a §•ZBuf (see ..Shapes..Graphics3D..newZBuf) or a §•ZSorter (see ..Shapes..Graphics3D..newZSorter), the light computations will be executed when ..Shapes..Geometry3D..view is applied. The rest of this section will be devoted to discussing the many options that exist for these objects.
Get Shapes at SourceForge.net. Fast, secure and Free Open Source software downloads