nl.kun.Engine3D
Class Viewport

java.lang.Object
  |
  +--nl.kun.Engine3D.Viewport

public class Viewport
extends java.lang.Object

This class can be used to draw on a canvas using physical coordinates, while the viewport translates these to screen coordinates.


Field Summary
 java.awt.Dimension CanvasSize
          The size of the canvas in screen coordinates
 double zoom
          zoom parameter.
 
Constructor Summary
  Viewport()
          Empty constructor.
(package private) Viewport(java.awt.Dimension _d, double _xmi, double _ymi, double _xma, double _yma, boolean _corrFlag, java.awt.Graphics g)
          Constructor
 
Method Summary
 void ArcDraw(double _centerX, double _centerY, double _radius, double _beginAngle, double _endAngle, java.awt.Color _color)
          Draws an arc on screen.
 void Line(double _x1, double _y1, double _x2, double _y2, java.awt.Color _color)
          Draws a line on screen.
 void LineArr(double[] Xpoints, double[] Ypoints, java.awt.Color _color)
          Draws a set of lines between points in an array.
 boolean OnScreen(double _x, double _y)
          Boolean function to determine if a point (_x,_y) in physical coordinates is within the screen limits
 void Plane(double[] _Xpoints, double[] _Ypoints, java.awt.Color _color)
          Draw a filled polygon on screen.
 int ScaleCanvasX(double _R)
          Scales an x value in physical coordinates to screen coordinates (needed when determining distances for circle drawing)
 int ScaleCanvasY(double _R)
          Scales an y value in physical coordinates to screen coordinates (needed when determining distances for circle drawing)
 void Sphere(double _x, double _y, double _R, java.awt.Color _color)
          Draws a sphere on screen
 void StringDraw(double _string, int _x, int _y)
          Draws a string on screen in screen coordinates
 void StringDraw(java.lang.String _string, double _x, double _y, java.awt.Color _color)
          Draws a string on screen in physical coordinates
 void UpdateGr(java.awt.Graphics g)
          Update the graphics object.
 int Xcanvas(double _x)
          Translates x position in physical coordinates to screen coordinates
 int Ycanvas(double _y)
          Translates y position in physical coordinates to screen coordinates
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CanvasSize

public java.awt.Dimension CanvasSize
The size of the canvas in screen coordinates

zoom

public double zoom
zoom parameter. Determines the amount of perspective in the 3D engine
Constructor Detail

Viewport

Viewport(java.awt.Dimension _d,
         double _xmi,
         double _ymi,
         double _xma,
         double _yma,
         boolean _corrFlag,
         java.awt.Graphics g)
Constructor
Parameters:
_d - The dimension of the canvas on which the viewport works in screen coordinates
_xmi - minimum X position in physical coordinates.
_ymi - minimum Y position in physical coordinates.
_xma - maximum X position in physical coordinates.
_yma - maximum Y position in physical coordinates.
_corrFlag - boolean to determine if the physical limits of the viewport should be corrected to create rectangular pixels (true), or if they should obey the physical limits put in by the users (false).
g - The graphics object of the canvas (or any other drawable surface).

Viewport

public Viewport()
Empty constructor.
Method Detail

Xcanvas

public final int Xcanvas(double _x)
Translates x position in physical coordinates to screen coordinates
Parameters:
_x - x position in physical coordinates

Ycanvas

public final int Ycanvas(double _y)
Translates y position in physical coordinates to screen coordinates
Parameters:
_y - y position in physical coordinates

ScaleCanvasX

public int ScaleCanvasX(double _R)
Scales an x value in physical coordinates to screen coordinates (needed when determining distances for circle drawing)
Parameters:
_R - x value in physical coordinates

ScaleCanvasY

public int ScaleCanvasY(double _R)
Scales an y value in physical coordinates to screen coordinates (needed when determining distances for circle drawing)
Parameters:
_R - y value in physical coordinates

OnScreen

public boolean OnScreen(double _x,
                        double _y)
Boolean function to determine if a point (_x,_y) in physical coordinates is within the screen limits
Parameters:
_x - x coordinate of the point
_y - y coordinate of the point returns true if it is onscreen and false if not.

UpdateGr

public void UpdateGr(java.awt.Graphics g)
Update the graphics object. Done once per animation frame
Parameters:
g - Graphics object of the canvas (or other drawable surface)

Line

public void Line(double _x1,
                 double _y1,
                 double _x2,
                 double _y2,
                 java.awt.Color _color)
Draws a line on screen.
Parameters:
_x1 - x coordinate of first point of the line in physical coordinates
_y1 - y coordinate of first point of the line in physical coordinates
_x2 - x coordinate of second point of the line in physical coordinates
_y2 - y coordinate of second point of the line in physical coordinates
_color - Color of the line

LineArr

public void LineArr(double[] Xpoints,
                    double[] Ypoints,
                    java.awt.Color _color)
Draws a set of lines between points in an array.
Parameters:
Xpoints - array of x values
Ypoints - array of y values
_color - Color of the lines.

Plane

public void Plane(double[] _Xpoints,
                  double[] _Ypoints,
                  java.awt.Color _color)
Draw a filled polygon on screen.
Parameters:
_Xpoints[] - Array of X values of the polygon in physical coordinates
_Ypoints[] - Array of Y values of the polygon in physical coordinates
_color - color of the polygon

Sphere

public void Sphere(double _x,
                   double _y,
                   double _R,
                   java.awt.Color _color)
Draws a sphere on screen
Parameters:
_x - x coordinate of the center of the sphere in physical coordinates
_y - y coordinate of the center of the sphere in physical coordinates
_R - Radius of the sphere in physical coordinates

StringDraw

public void StringDraw(double _string,
                       int _x,
                       int _y)
Draws a string on screen in screen coordinates
Parameters:
_string - String with the text that is to be printed
_x - x coordinate of lower left corner of the text in screen coordinates
_y - y coordinate of lower left corner of the text in screen coordinates

StringDraw

public void StringDraw(java.lang.String _string,
                       double _x,
                       double _y,
                       java.awt.Color _color)
Draws a string on screen in physical coordinates
Parameters:
_string - String with the text that is to be printed
_x - x coordinate of lower left corner of the text in physical coordinates
_y - y coordinate of lower left corner of the text in physical coordinates
_color - Color of the text.

ArcDraw

public void ArcDraw(double _centerX,
                    double _centerY,
                    double _radius,
                    double _beginAngle,
                    double _endAngle,
                    java.awt.Color _color)
Draws an arc on screen.
Parameters:
_centerX - x coordinate of the center of the arc in physical coordinates
_centerY - y coordinate of the center of the arc in physical coordinates
_radius - Radius of the arc in physical coordinates
_beginAngle - starting angle of arc in radians
_beginAngle - ending angle of arc in radians