Node:Declaring and Initializing Points, Next:Setting and Assigning to Points, Previous:Points, Up:Points
The most basic drawable object in 3DLDF is class Point
. It is
analogous to pair
in Metafont. For example, in Metafont one
can define a pair
using the "z" syntax as
follows:
z0 = (1cm, 1cm);
There are other ways of defining pairs
in Metafont (and
MetaPost), but this is the usual way.
In 3DLDF, a Point is declared and initialized as follows:
Point pt0(1, 2, 3);
This simple example demonstrates several differences between Metafont
and 3DLDF. First of all, there is no analog in 3DLDF to Metafont's
"z" syntax.
If I want to have Points
called "pt0
", "pt1
",
"pt2
", etc., then I must declare each of them to be a
Point
:
Point pt0(10, 15, 2); Point pt1(13, 41, 5.5); Point pt2(62.9, 7.02, 8);
Alternatively, I could declare an array of Points
:
Point pt[3];
Now I can refer to pt[0]
, pt[1]
, and pt[2]
.
In the Metafont example, the x and y-coordinates of the pair z0
are specified using the unit of measurement, in this case, centimeters.
This is currently not possible in 3DLDF. The current unit of
measurement is stored in the static variable Point::measurement_units
,
which is a string
. Its default value is "cm"
for
"centimeters".
At present, it is best to stick with one unit of measurement for a
drawing.
After I've defined an input routine, 3DLDF should handle
units of measurement in the same way that Metafont does.
Another difference is that the Points
pt0
, pt1
, and
pt2
have three coordinates, x, y, and z, whereas z0
has
only two, x and y. Actually, the difference goes deeper than this. In
Metafont, a pair
has two parts, xpart
and ypart
,
which can be examined by the user. In 3DLDF, a Point
contains
the following sets of coordinates:
world_coordinates user_coordinates view_coordinates projective_coordinates
These are sets of 3-dimensional homogeneous coordinates, which means that they contain four coordinates: x, y, z, and w. Homogeneous coordinates are used in the affine and perspective transformations (see Transforms).
Currently, only world_coordinates
and
projective_coordinates
are used in 3DLDF.
The world_coordinates
refer to the position of a Point
in
3DLDF's basic, unchanging coordinate system.
The projective_coordinates
are the coordinates of the
two-dimensional projection of the Point
onto a plane.
This projection is what is ultimately printed out or displayed on the
computer screen. Please note, that when the coordinates of a
Point
are referred to in this manual, the
world_coordinates
are meant, unless otherwise stated.
Points
can be declared and their values can be set in different
ways.
Point pt0; Point pt1(1); Point pt2(2.3, 52); Point pt3(4.5, 7, 13.205);
pt0
is declared without any arguments, i.e., using the default
constructor, so the values of its x, y, and
z-coordinates are all 0.
pt1
is declared and initialized with one argument for the x-coordinate,
so its y and z-coordinates are initialized with the values of
CURR_Y
and CURR_Z
respectively.
The latter are static constant data members
of class Point
, whose values are 0 by default. They can be reset
by the user, who should
make sure that they have sensible values.
pt2
is declared and initialized with two arguments for its x and
y-coordinates, so its z-coordinate is initialized to the value of
CURR_Z
. Finally, pt3
has an argument for each of its
coordinates.
Please note that pt0
is constructed using a the default
constructor, whereas the other Points
are constructed using a
constructor with one required argument (for the x-coordinate), and two
optional arguments (for the y and z-coordinates). The default
constructor always sets all the coordinates to 0, irrespective of the
values of CURR_Y
and CURR_Z
.