|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
Modifier and Type | Method and Description |
---|---|
void |
clearRect(int left,
int top,
int width,
int height)
Clears (reinitialize) the rectangular area left≤x<left+width, top≤y<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 |
---|
void clearRect(int left, int top, int width, int height)
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.
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.void drawPoint(int x, int y, double z, double nx, double ny, double nz, java.awt.Color color)
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
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
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.
The alpha component of the passed color affects the transparency. It is guaranteed,
that if 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).
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.java.lang.NullPointerException
- if color argument is null.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |