Purpose: A class that rasterizes three-dimensional objects
Details
Matrices:
draw()
method (see below) will be passed
a matrix in which each row corresponds to a point.
You may transpose this matrix or not, as you see fit.
Representation of 3D Objects:
draw()
method (see below) will be passed
two matrices, one of which will contain the coordinates of all
of the points in the object, the other of which will contain the
vertices of the faces in the object. For example, the following
cube:
has the following coordinates:
double[][] coords =
{
{ 0., 0., 0., 1.}, // 0
{ 0., 0., 50., 1.}, // 1
{ 0., 50., 50., 1.}, // 2
{ 0., 50., 0., 1.}, // 3
{ 50., 0., 0., 1.}, // 4
{ 50., 0., 50., 1.}, // 5
{ 50., 50., 50., 1.}, // 6
{ 50., 50., 0., 1.} // 7
};
and the following faces:
int[][] faces = {{1,5,6,2}, // Front
{1,2,3,0}, // Left
{3,2,6,7}, // Top
{7,4,0,3}, // Back
{7,6,5,4}, // Right
{5,1,0,4} // Bottom
};
Attributes:
private double[][] perspective, rotationX, rotationY, translation; private Rasterizer2D rasterizer2D;
The matrices must be used to transform the points as required by the
various views supported by the Rasterizer3D
. The
Rasterizer2D
must be used to draw the shapes after
they are projected to 2D.
The Explicit Value Constructor:
/** * Explicit Value Constructor * * @param fb The FrameBuffer containing the pixels */ public Rasterizer3D(FrameBuffer fb)
The clear() Method:
/** * Fill the entire FrameBuffer with the given color */ public void clear(Color c)
The scaleAndTranslate() Method:
/** * Scales and translates the given points so that they * fit within the FrameBuffer and are centered at 0,0 * * @param p The points to scale and translate * @return The scaled and trnslated points */ public double[][] scaleAndTranslate(double[]... p)
This method must use the GeometryND.boundingRectangle()
method to get the bounds of p
and it must use matrix
multiplication (i.e., the MMath.times()
method)
to perform the scaling and translation.
This method should assume that the frame buffer is 501x501, with (0,0) at the center.
The draw() Method:
/** * Draw the given object * * Note: This method assumes that the point, p, are in row-major * order. That is, each ROW corresponds to a point. * * @param colors The color to use for each face * @param vertices The vertices for each face * @param p The coordinates of the vertices */ public void draw(Color[] colors, int[][] vertices, double[][] p)
This method must:
drawFace()
method to draw the individual
faces.
The drawFace() Method:
/** * Draw a single face * * Note: This method assumes that the point, p, are in row-major * order. That is, each ROW corresponds to a point. * * @param color The color to use * @param vertices The vertices for this face * @param p The coordinates of the vertices */ public void drawFace(Color color, int[] vertices, double[][] p)
This method must use the Raserizer2D
to draw the lines
in the face.
The useDimetricView() Method:
/** * Instructs the rasterizer to use a dimetric view. * Specifically, this method updates the two rotation matrices * so that they are appropriate for a dimetric view. * * @param phi The rotation around the x-axis (in degrees) */ public void useDimetricView(double phi)
The useIsometricView() Method:
/** * Instructs the rasterizer to use an isometric view. * Specifically, this method updates the two rotation matrices * so that they are appropriate for an isometric view. */ public void useIsometricView()
The useThreePointPerspectiveView() Method:
/** * Instructs the rasterizer to use a three-point perspective view. * Specifically, this method updates the rotation * and translation matrices so that they are appropriate * for a three-point perspective view. * * @param d The COP * @param tx Translation along the x-axis * @param ty Translation along the y-axis * @param tz Translation along the z-axis * @param phi Rotation around the x-axis (in degrees) * @param theta Rotation around the y-axis (in degrees) */ public void useThreePointPerspectiveView(double d, double tx, double ty, double tz, double phi, double theta)
The useTrimetricView() Method:
/** * Instructs the rasterizer to use a trimetric view. * Specifically, this method updates the two rotation matrices * so that they are appropriate for a trimetric view. * * @param phi Rotation around the x-axis (in degrees) * @param theta Rotation around the y-axis (in degrees) */ public void useTrimetricView(double phi, double theta)
The useTwoPointPerspectiveView() Method:
/** * Instructs the rasterizer to use a two-point perspective view. * Specifically, this method updates the rotation * and translation matrices so that they are appropriate * for a two-point perspective view. * * @param d The COP * @param ty Translation along the y-axis * @param tz Translation along the z-axis * @param theta Rotation around the y-axis (in degrees) */ public void useTwoPointPerspectiveView(double d, double ty, double tz, double theta)
Copyright 2007