
| Lua OpenGL Surface Iso-surface 3D plot Sub-plots |
OpenGL BasicsAt least you should understand the mechanism of shape construction of OpenGL, i.e., vertex, normal, and color of shapes, to use zeGraph. To enhance the 3D effect of a plot, a minimal knowledge of OpenGL light is necessary, i.e., the concept of ambient color and the amount of light on a object determined by vertex normal. The shape of an object consisting of points, lines, or polygon is determined by its vertex coordinates; in other words, a sequence of coordinate data may be rendered as points, lines, or polygon depending on the attribute (shown in the following figure) assigned to the data sequence.
Points are independent dots. A line is made up of line segments, a line strip, or a lineloop. And there are six ways to construct a polygon. A vertex of this three types of shapes may have a normal that determines the extent that a light may have on it. Assigning normals to vertices of a point or line object is rare, but necessary for some special effects. A 3D object consisted of polygons generally need normals for its vertices and a light object in the scene in order to make it looks like 3D on the 2D screen. Vertex normal is also very important to make a discrete surface looks smooth. The trick is to calculate normal properly. The following hints and the normal2() function in the zeMake package will solve most mormal calculation problems. 1. Line NormalCalculating normal for a 3D line is the same as that for a 3D surface and will be discussed later. For a 2D line on the x-y plane that is intended to be used for making a surface by extruding, sweeping, or tweening, a normal can be calculated by the cross product of the vector [0, 0, 1] and the derivative of y = y(x), yielding the normal as [-dy, dx, 0] For parametric curve equations x = x(t)
y = y(t)
The normal is [-dy/dt, dx/dt, 0] 2. Surface NormalFor surface parametric equations x = x(u, v)
y = y(u, v)
z = z(u, v)
Assuming xu, yu, and zu are the partial derivatives on u; and xv, yv, and zv are the partial derivatives on v; then the normal is the cross product of [xu, yu, zu] and [xv, yv, zv]. The resulted normal could point toward or off the origin. If the surface is dark with a light on, you may reverse the product order or the sign of the normal to get the expected effect. For an implicit surface function f(x, y, z) = 0 The surface enclosing higher volume values can be found using the iso-surface function of zeMake. You may need to reverse the resulted normals when the volume density is high on the same side as the light object. The surface normal is the normalized vector of [f'|x, f'|y, f'|z] 3. Normal and ScalingA scaling factor applied to an shape or node object affects not only the object size but also vertex normals. If the scaling factor differs significanlly from 1, the light effect on an object may not shown as you expected because OpenGL expect a normal vector to have the property of sqrt(x^2 + y^2 + z^2) = 1. This is a OpenGL pitfall. A solution to this problem is to enable OpenGL normalization for vertex normal. zeGraph disables the normalization by default because of its performance penalty. When an object has to be scaled many times, it is better to scale its vertices or apply a reverse scaling factor to the vertex normal. Of course you can enable the normalization option when performance does not matter. |