Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool Protract.java, NONE, 1.1 Protractor.j
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2009-12-22 14:54:45
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8680/src/net/sourceforge/bprocessor/gl/tool Modified Files: Protractor.java Added Files: Protract.java Log Message: --- NEW FILE: Protract.java --- //--------------------------------------------------------------------------------- // $Id: Protract.java,v 1.1 2009/12/22 14:54:34 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.util.LinkedList; import java.util.List; import javax.media.opengl.GL; import net.sourceforge.bprocessor.gl.model.GlObject; import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Camera; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Vertex; /** * Protract */ public class Protract implements GlObject { private Vertex origin; private Vertex u; private Vertex v; private boolean hitable; /** * Constructs a Protract * @param origin Vertex * @param i Vertex * @param j Vertex * @param hitable hitable */ public Protract(Vertex origin, Vertex i, Vertex j, boolean hitable) { this.origin = origin; this.u = i; this.v = j; this.hitable = hitable; } /** * * @param radius double * @param angle double * @return Vertex */ public Vertex radian(double radius, double angle) { double x = Math.cos(angle) * radius; double y = Math.sin(angle) * radius; Vertex p = origin.add(u.scale(x).add(v.scale(y))); return p; } /** {@inheritDoc} */ public void draw(GL gl) { drawNormal(gl); } /** {@inheritDoc} */ public Intersection intersection(Edge e) { Vertex n = u.cross(v); Plane plane = new Plane(n, origin); Vertex vertex = plane.intersection(e); return new Intersection(vertex, Intersection.PLANE_INTERSECTION, plane); } private void drawNormal(GL gl) { Camera camera = Project.getInstance().getCurrentCamera(); double distance = camera.distance(origin); double radius = 3 * distance; double n = 36; gl.glLineWidth(1.5f); gl.glColor3fv(View.CONSTRUCTOR_COLOR, 0); { gl.glBegin(GL.GL_LINE_LOOP); for (int i = 0; i < n; i++) { double angle = 2 * Math.PI * i / n; Vertex p = radian(radius, angle); gl.glVertex3d(p.getX(), p.getY(), p.getZ()); } gl.glEnd(); gl.glBegin(GL.GL_LINE_LOOP); for (int i = 0; i < n; i++) { double angle = 2 * Math.PI * i / n; Vertex p = radian(radius * 0.6, angle); gl.glVertex3d(p.getX(), p.getY(), p.getZ()); } gl.glEnd(); } { Vertex a = radian(radius, 0.1); Vertex b = radian(radius * 0.85, 0); Vertex c = radian(radius, -0.1); gl.glBegin(GL.GL_TRIANGLES); gl.glVertex3d(a.getX(), a.getY(), a.getZ()); gl.glVertex3d(b.getX(), b.getY(), b.getZ()); gl.glVertex3d(c.getX(), c.getY(), c.getZ()); gl.glEnd(); } { gl.glBegin(GL.GL_LINES); for (int i = 0; i < 24; i++) { double angle = 2 * Math.PI * i / 24; Vertex p = radian(radius, angle); Vertex q = radian(radius * 0.95, angle); gl.glVertex3d(p.getX(), p.getY(), p.getZ()); gl.glVertex3d(q.getX(), q.getY(), q.getZ()); } gl.glEnd(); } } private void drawSelect(GL gl) { Camera camera = Project.getInstance().getCurrentCamera(); double distance = camera.distance(origin); double radius = 3 * distance; double n = 36; gl.glBegin(GL.GL_POLYGON); for (int i = 0; i < n; i++) { double angle = 2 * Math.PI * i / n; Vertex p = radian(radius, angle); gl.glVertex3d(p.getX(), p.getY(), p.getZ()); } gl.glEnd(); } /** {@inheritDoc} */ public void select(GL gl) { if (hitable) { drawSelect(gl); } } /** {@inheritDoc} */ public List<Vertex> handles() { List<Vertex> handles = new LinkedList(); Camera camera = Project.getInstance().getCurrentCamera(); double distance = camera.distance(origin); double radius = 3 * distance; double n = 24; for (int i = 0; i < n; i++) { double angle = 2 * Math.PI * i / n; Vertex p = radian(radius * 0.97, angle); handles.add(p); } return handles; } } Index: Protractor.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Protractor.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Protractor.java 22 Dec 2009 14:33:34 -0000 1.22 --- Protractor.java 22 Dec 2009 14:54:34 -0000 1.23 *************** *** 13,25 **** import java.util.List; - import javax.media.opengl.GL; import net.sourceforge.bprocessor.gl.Editor; - import net.sourceforge.bprocessor.gl.model.GlObject; import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.gl.view.View; - import net.sourceforge.bprocessor.model.Camera; import net.sourceforge.bprocessor.model.CoordinateSystem; - import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Line; --- 13,21 ---- *************** *** 270,396 **** } ! /** ! * Protract ! */ ! public static class Protract implements GlObject { ! private Vertex origin; ! private Vertex u; ! private Vertex v; ! private boolean hitable; ! ! /** ! * Constructs a Protract ! * @param origin Vertex ! * @param i Vertex ! * @param j Vertex ! * @param hitable hitable ! */ ! public Protract(Vertex origin, Vertex i, Vertex j, boolean hitable) { ! this.origin = origin; ! this.u = i; ! this.v = j; ! this.hitable = hitable; ! } ! ! private Vertex radian(double radius, double angle) { ! double x = Math.cos(angle) * radius; ! double y = Math.sin(angle) * radius; ! Vertex p = origin.add(u.scale(x).add(v.scale(y))); ! return p; ! } ! ! /** {@inheritDoc} */ ! public void draw(GL gl) { ! drawNormal(gl); ! } ! ! /** {@inheritDoc} */ ! public Intersection intersection(Edge e) { ! Vertex n = u.cross(v); ! Plane plane = new Plane(n, origin); ! Vertex vertex = plane.intersection(e); ! return new Intersection(vertex, Intersection.PLANE_INTERSECTION, plane); ! } ! ! private void drawNormal(GL gl) { ! Camera camera = Project.getInstance().getCurrentCamera(); ! double distance = camera.distance(origin); ! double radius = 3 * distance; ! double n = 36; ! gl.glLineWidth(1.5f); ! gl.glColor3fv(View.CONSTRUCTOR_COLOR, 0); ! { ! gl.glBegin(GL.GL_LINE_LOOP); ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! Vertex p = radian(radius, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! } ! gl.glEnd(); ! gl.glBegin(GL.GL_LINE_LOOP); ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! Vertex p = radian(radius * 0.6, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! } ! gl.glEnd(); ! } ! { ! Vertex a = radian(radius, 0.1); ! Vertex b = radian(radius * 0.85, 0); ! Vertex c = radian(radius, -0.1); ! gl.glBegin(GL.GL_TRIANGLES); ! gl.glVertex3d(a.getX(), a.getY(), a.getZ()); ! gl.glVertex3d(b.getX(), b.getY(), b.getZ()); ! gl.glVertex3d(c.getX(), c.getY(), c.getZ()); ! gl.glEnd(); ! } ! { ! gl.glBegin(GL.GL_LINES); ! for (int i = 0; i < 24; i++) { ! double angle = 2 * Math.PI * i / 24; ! Vertex p = radian(radius, angle); ! Vertex q = radian(radius * 0.95, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! gl.glVertex3d(q.getX(), q.getY(), q.getZ()); ! } ! gl.glEnd(); ! } ! } ! private void drawSelect(GL gl) { ! Camera camera = Project.getInstance().getCurrentCamera(); ! double distance = camera.distance(origin); ! double radius = 3 * distance; ! double n = 36; ! gl.glBegin(GL.GL_POLYGON); ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! Vertex p = radian(radius, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! } ! gl.glEnd(); ! } ! ! /** {@inheritDoc} */ ! public void select(GL gl) { ! if (hitable) { ! drawSelect(gl); ! } ! } ! ! /** {@inheritDoc} */ ! public List<Vertex> handles() { ! List<Vertex> handles = new LinkedList(); ! Camera camera = Project.getInstance().getCurrentCamera(); ! double distance = camera.distance(origin); ! double radius = 3 * distance; ! double n = 24; ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! Vertex p = radian(radius * 0.97, angle); ! handles.add(p); ! } ! return handles; ! } ! } } --- 266,269 ---- } ! } |