/** * @file SolidObjectPoint.java * @author Robert S Laramee * @version 1.0 * Start Date Thursday, 17 November 1998 * "Finish" Date Thursday, 03 December 1998 * * Description This class contains the methods and data necessary for * creating user defined solid object points */ import java.awt.*; // for Point class import java.util.*; // for Vector class //import matrix.*; // the cs770 matrix package public class SolidObjectPoint { /** * A solid object point has 2 sets of points associated with it: * 1 The set of definition points from the user and * 2 That same set mapped to 3D space */ private NDCpoint definition; // the definition point (in NDC) private Point4 pointIn3D; // the same point in 3D /** * constructor * A new solid object point is created when the user causes a * mouseClicked event in Solid Object Drawing Mode. * * Solid Object Mode (2D) Maps To Normal Drawing Mode (3D) * ----------------- ------ ------------------- * -Z ^ Y ^ * | | * | | * | | * ----------> X ---------> X * / * Z / * / * @param x -x coordinate in canvas window * @param z -y coordinate in canvas window * @param y -(zBack-zFront) from scroll bars */ public SolidObjectPoint(int x, int y) { definition = View.toNDC(new Point(x,y)); pointIn3D = new Point4(definition.x, 0.0, -definition.y); } /** * return the definition point * return the point in 3D */ public NDCpoint getDefinition() { return definition; } public Point4 getPointIn3D() { return pointIn3D; } public void setPointIn3D(NDCpoint ndc) { pointIn3D.x = ndc.x; pointIn3D.y = 0.0; pointIn3D.z = -ndc.y; } /** * This method tests to see if the new point drawn by the use is close * enough to the first point so as to define a new solid object * @param SOpoints -the list of this solid object's points * @return TRUE if the new point is very close to the first one */ public boolean onTopOfFirst(Vector SOpoints) { /* IF there are less than 3 points, return false */ if (SOpoints.size() < 3) { return false; } SolidObjectPoint first = (SolidObjectPoint)SOpoints.elementAt(0); if ( (Math.abs(this.definition.x - first.definition.x) < 0.03) && (Math.abs(this.definition.y - first.definition.y) < 0.03) ) { return true; } else { return false; } } /** * This method draws the point in definition mode * @param graphicsObject -a reference to the current graphics object */ public void drawDefinition(Graphics g) { Point point = View.toCanvas(definition); g.drawOval(point.x, point.y, 7, 7); g.fillOval(point.x, point.y, 3, 3); } /** * This method draws a line between the calling point solid object point * and the passed point * @param graphicsObject -a reference to the current graphics object * @param SOpoint2 -the second solid object point */ public void drawLine(Graphics g, SolidObjectPoint SOpoint2) { Point point1 = View.toCanvas(this.definition); Point point2 = View.toCanvas(SOpoint2.definition); g.drawLine(point1.x, point1.y, point2.x, point2.y); } /** * toString() */ public String toString() { return new String("definition = " + definition + "\n" + "pointIn3D = " + pointIn3D); } }