net.algart.drawing3d
Interface Pixel3DDrawer

All Known Implementing Classes:
Drawer3D, SimpleDrawer3D

public interface Pixel3DDrawer

Low-level tool for drawing one 3D pixel, used by DrawingRule.

This interface solves only the simplest task of drawing 1 pixel of some 3D surface. Together with a set of implementations of DrawingRule, "knowing" how to draw specific types of 3D figures (Shape3D), this interface provides complete solution of the problem of drawing 3D figures. This package offers some simple implementation of this interface, which can be created by SimpleDrawer3D.getSimpleDrawer3D method.

This interface works in the coordinates of the computer screen: see comments to DrawingRule.

AlgART Laboratory 2010

Since:
JDK 1.5
Version:
1.0
Author:
Daniel Alievsky

Method Summary
Modifier and Type Method and Description
 void clearRect(int left, int top, int width, int height)
          Clears (reinitialize) the rectangular area leftx<left+width, topy<top+height.
 void drawPoint(int x, int y, double z, double nx, double ny, double nz, java.awt.Color color)
          Draws 1 pixel (point) of the surface of some 3D figure.
 

Method Detail

clearRect

void clearRect(int left,
               int top,
               int width,
               int height)
Clears (reinitialize) the rectangular area leftx<left+width, topy<top+height. After this call, this object will be in the same state, as when drawPoint was never called for integer pairs (x,y) in this area, and this area is filled by some default background color.

The implementation, provided by SimpleDrawer3D.getSimpleDrawer3D method, initializes Z-buffer for this area by default −∞ values.

If the specified area is out of ranges of the screen (i.e. some coordinates are <0 or ≥width/height of the image, which should be built as a result), the extra pixels are ignored. In particular, you can specify left=top=0, width=height=MAX_VALUE to reinitialize all drawable area. If width≤0 or height≤0, this method does nothing.

Parameters:
left - the minimal x-coordinate of the cleared area.
top - the minimal y-coordinate of the cleared area.
width - the width of the cleared area.
height - the height of the cleared area.

drawPoint

void drawPoint(int x,
               int y,
               double z,
               double nx,
               double ny,
               double nz,
               java.awt.Color color)
Draws 1 pixel (point) of the surface of some 3D figure. It is the basic primitive, on the base of which DrawingRule.draw method is implemented.

The coordinates of the pixel are specified in the coordinate system of the computer screen: the x-axis is directed to the right (in the screen plane), the y-axis is directed downwards (in the screen plane) and the z-axis is directed from the screen to the user. The top left corner of the screen image, which should be built as a result, has coordinates x=0, y=0, z=+∞.

x and y coordinates, passed to this method, specify the pixel of the resulting image, which should be built (from 0 to the image width−1 or height−1). The resulting color of the pixel (x,y) of that image depends on the full series of calls of this method, in which these x, y coordinates were passed.

z-coordinate, passed to this method, is compared with z-coordinates of other points, which were probably drawn by this method at the same (x,y) coordinates. The simplest implementation can just overwrite the color of this pixel, if the passed z is greater than z-coordinates of all previous calls with same (x,y), or preserve the previous color if not — it is the known "Z-buffer" algorithm. But other implementations are also possible: for example, the new color can be combined with the previous color at (x,y) position, to provide an effect of translucency. The implementation, provided by SimpleDrawer3D.getSimpleDrawer3D method, uses the described simple Z-buffer algorithm.

The color argument specifies the color of the drawn point of the 3D surface. But this color is used directly only in a case, when the surface is perpendicular to the rays of the light. In other case, the color should be made darker. To provide this behavior, this method has additional arguments nx, ny, nz, equal to the components of the unit normal vector n=(nx,ny,nz) of the drawn surface. An implementation can use this information to reduce the brightness according to some lighting model. The implementation, provided by SimpleDrawer3D.getSimpleDrawer3D method, multiplies all R, G, B components of the color by Math.abs(nz) — it corresponds to the light rays, falling along z axis from the side of the user (observer). Note: the normal vector is supposed to be unit, i.e. nx²+ny²+nz²=1.0.

The alpha component of the passed color affects the transparency. It is guaranteed, that if color.getAlpha()==0, then this pixel is not drawn (the method does nothing), and if color.getAlpha()==0, then it means normal drawing. Other values 1–254 can affect the transparency, but it is not guaranteed. The implementation, provided by SimpleDrawer3D.getSimpleDrawer3D method, uses 1–254 values for mixing the passed color with previously drawn color, which partially emulates translucency. But note that this feature does not really provide correct translucency, because that implementation is based on a simple Z-buffer algorithm and does nothing if z argument is less than z-coordinates of the previously drawn pixel.

If x or y arguments are out of ranges of the screen (i.e. <0 or ≥width/height of the image), this method does nothing. Besides this, the object can support some zcut limit and ignore calls with z>zcut: it allows creating "cut sets" of a complex 3D configuration (this limit is really supported by Drawer3D class).

Parameters:
x - x-coordinate of the point.
y - y-coordinate of the point.
z - z-coordinate of the point.
nx - x-component of the unit normal vector of the drawn surface at this point.
ny - y-component of the unit normal vector of the drawn surface at this point.
nz - z-component of the unit normal vector of the drawn surface at this point.
color - the color of drawn surface point.
Throws:
java.lang.NullPointerException - if color argument is null.