Class Debug
public abstract class Debug
extends java.lang.Object
- You use the predefined debugs of this package.
- Debugs can be recursively interlaced. Each debug contains an (initially empty)
array of sub-debugs
debugs,
which can be filled with any desired debugs.
This generates a recursive tree of debug objects. A debug first plots
itself and then the array of its sub-debugs.
The color of the debug is inherited. Sub-debugs of a blue debug are blue as well, unless they define an individual color. The variable color allows you to select a color for your debug or to choose the transparent color
null
.You can thus simply define your debug as combination of known debugs. The following debug plots a blue triangle:
class Triangle extends Debug { Triangle (Vector a, Vector b, Vector c) { debugs = new Debug[] { new Line(a,b), new Line(b,c), new Line(c,a) }; color = Color.blue; } }
- You extend the class Debug and define your own debug by overwriting
the method
paint(...).
Debugs are stored relatively to the unit and transformed into
absolute coordinates only at the moment of plotting.
The following debug tags a point by a small circle:
class O extends Debug { private Vector o; // relative position to unit public O (Vector o) { this.o = vector(o); } // store relative position public void paint (Graphics g, Color color, Color globe, double scale, Sphere sphere, Matrix base, boolean front) { Vector p = Vector.mul(o,base); // calculate absolute position if (front ^ p.z > 0) return; // wrong side? return! Point P = scale(scale,p); // scale in AWT-coordinates g.setColor(color(color,globe,p.z)); // set color g.drawOval(P.x-6,P.y-6,12,12); // plot circle! } }
The color of the Debug is determined by the color specification in the unit's debug(...)-command, or by the unit color itself if it is called wihout color request.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Debug()
Empty constructor. -
Method Summary
Modifier and Type Method Description static java.awt.Color
color(java.awt.Color color, java.awt.Color globe, double z)
Detects the color for a certain depth.void
paint(java.awt.Graphics g, java.awt.Color color, java.awt.Color globe, double scale, Sphere sphere, Matrix base, boolean front)
Empty for the plotting of a debug on an AWT Graphics Context.static java.awt.Point
scale(double scale, Vector v)
Detects the AWT coordinates of a vector for a certain scaling.static Vector
vector(Vector v)
Reads and corrects a vector.
-
Field Details
-
Constructor Details
-
Debug
public Debug()Empty constructor.
-
-
Method Details
-
vector
Reads and corrects a vector.This method should be called in the constructor of a debug, when position vectors are to be transfered and saved. The passed vector is copied and normalized to length 1 - it is hence specific to the scaling of the paint(...)-method. If the vector is (0,0,0) or
null
, the method returns the "spherical null vector" (0,0,1).- Parameters:
v
- vector- Returns:
- rectified vector
-
scale
Detects the AWT coordinates of a vector for a certain scaling.The Hoverball screen is oriented in such a way that the x-axis points upward, the y-axis left and the z-axis forward ("out of the screen"). This method projects the 3D coordinate system of the sphere onto the 2D coordinate system of an AWT Graphics Context. You have to indicate how many pixels represent the unit length. The coordinate origin is never displaced.
- Parameters:
scale
- scaling (in pixels)v
- vector- Returns:
- the AWT coordinates
-
color
public static java.awt.Color color(java.awt.Color color, java.awt.Color globe, double z)Detects the color for a certain depth.In order to obtain a perspective effect displaying the sphere, objects eclipse in the background. This method calculates the shadowed color of an input color dependent on a certain depth. The depth value ranges between -1 and 1 and should correspond to the z-coordinate of the normalized position vector.
- Parameters:
color
- color of the debugglobe
- color of the spherez
- depth- Returns:
- the shadowed color
-
paint
public void paint(java.awt.Graphics g, java.awt.Color color, java.awt.Color globe, double scale, Sphere sphere, Matrix base, boolean front)Empty for the plotting of a debug on an AWT Graphics Context.This method is responsible for the display of a debug with correct perspective and color. Use the methods scale(...) and color(...) as well as the classes of the package hoverball.math. Please note:
- The coordinate system of the Graphics Contexts is already shifted so that
the point (0,0) lies in the middle of the sphere.
- The scaling measure is chosen in a way that it indicates the
sphere radius (instead of the Hoverball unit length). This means
that vectors of length 1 are scaled alike, independently of the size
of the sphere.
- A unit's perspective is passed to the method by the matrix
base
. To bring vectors from a unit's vision into the right perspective, you only need a simple multiplication by the matrixbase
. - Front and back of the sphere are painted separately in order to effectuate
a neat overlapping of the foreground in front of the background.
The method paint(...) is called twice at each case. It demands a
parameter
front
specifying which side is about to be painted.
- Parameters:
g
- Graphics Contextcolor
- color of the debugglobe
- color of the spherescale
- scaling (sphere radius in pixels)sphere
- game spherebase
- perspective matrixfront
- front or back?
- The coordinate system of the Graphics Contexts is already shifted so that
the point (0,0) lies in the middle of the sphere.
-