From 3c7f3b099198d4ea36d498c349cad80f2a6937de Mon Sep 17 00:00:00 2001 From: Phillip Date: Sun, 20 Feb 2011 22:57:16 +0000 Subject: Fixed some checkstyle errors (added java doc) Added new constructor to Ellipsoid.java to feed in a Mass, Radius and Position. --- src/tesseract/TesseractUI.java | 5 +- src/tesseract/forces/AirDrag.java | 55 ++++++++++-- .../menuitems/ParticleEmitterMenuItem.java | 6 +- src/tesseract/newmenu/NewChainLinkMenuItem.java | 100 +++++++++++++++++++++ src/tesseract/newmenu/NewEllipsoidMenuItem.java | 92 +++++++++++++++++++ src/tesseract/newmenu/NewToroidMenuItem.java | 2 +- src/tesseract/objects/ChainLink.java | 1 + src/tesseract/objects/Ellipsoid.java | 30 +++++++ 8 files changed, 278 insertions(+), 13 deletions(-) create mode 100644 src/tesseract/newmenu/NewChainLinkMenuItem.java create mode 100644 src/tesseract/newmenu/NewEllipsoidMenuItem.java diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java index 2ad997d..79bb8e6 100644 --- a/src/tesseract/TesseractUI.java +++ b/src/tesseract/TesseractUI.java @@ -401,9 +401,10 @@ public class TesseractUI extends JFrame { float scale = 0.001f; int xdiff = e.getX() - lastDragEvent.getX(); - int ydiff = - e.getY() + lastDragEvent.getY(); + int ydiff = -e.getY() + lastDragEvent.getY(); - Point3f p = new Point3f(scale * xdiff, scale * ydiff, 0); + Point3f p = new Point3f(scale * xdiff, scale + * ydiff, 0); Transform3D t3d = new Transform3D(); t3d.rotX(cameraXRotation); Transform3D tmp = new Transform3D(); diff --git a/src/tesseract/forces/AirDrag.java b/src/tesseract/forces/AirDrag.java index 356de7a..43cbfe5 100644 --- a/src/tesseract/forces/AirDrag.java +++ b/src/tesseract/forces/AirDrag.java @@ -115,6 +115,11 @@ public class AirDrag extends Force { System.out.println(ad.areaOfHull(newPoints)); } + /** + * + * @param hull vector list. + * @return area + */ private float areaOfHull(final List hull) { float area = 0; Vector2f p = hull.get(0); @@ -124,7 +129,7 @@ public class AirDrag extends Force { Vector2f ab = new Vector2f(); Vector2f ac = new Vector2f(); - ab.sub(hull.get(i-1), p); + ab.sub(hull.get(i - 1), p); ac.sub(hull.get(i), p); area += 0.5f * (ab.x * ac.y - ac.x * ab.y); @@ -133,15 +138,21 @@ public class AirDrag extends Force { return area; } + /** + * + * @param points point list. + * @return point list. + */ private List convexHull(final ArrayList points) { Collections.sort(points, new Vector2fAngleCompare(points.get(0))); points.set(0, points.get(points.size() - 1)); int m = 2; - for (int i = 3; i < points.size(); i++) { + for (int i = m + 1; i < points.size(); i++) { try { - while (i < points.size() - 1 && ccw(points.get(m - 1), points.get(m), points.get(i)) <= 0) { + while (i < points.size() - 1 && ccw(points.get(m - 1), + points.get(m), points.get(i)) <= 0) { if (m == 2) { final Vector2f vec = points.get(m); points.set(m, points.get(i)); @@ -163,26 +174,54 @@ public class AirDrag extends Force { points.set(i, vec); } - return points.subList(0, m+1); + return points.subList(0, m + 1); } + /** + * + * @param v1 vector. + * @param v2 vector. + * @param v3 vector. + * @return result + */ private float ccw(final Vector2f v1, final Vector2f v2, final Vector2f v3) { - return (v2.x - v1.x) * (v3.y - v1.y)- (v2.y - v1.y) * (v3.x - v1.x); + return (v2.x - v1.x) * (v3.y - v1.y) - (v2.y - v1.y) * (v3.x - v1.x); } - + + /** + * + * + * + */ private class Vector2fAngleCompare implements Comparator { + /** + * Base vector. + */ Vector2f base; + /** + * constructor. + * @param theBase the base. + */ public Vector2fAngleCompare(final Vector2f theBase) { base = theBase; } - - public int compare(Vector2f o1, Vector2f o2) { + /** + * @param o1 vector to compare + * @param o2 vector2 to compare + * @return comparison + */ + public int compare(final Vector2f o1, final Vector2f o2) { return (int) Math.signum(vecAngle(o1) - vecAngle(o2)); } + /** + * + * @param vector to look at. + * @return result + */ private float vecAngle(final Vector2f vector) { final Vector2f v = new Vector2f(); v.sub(vector, base); diff --git a/src/tesseract/menuitems/ParticleEmitterMenuItem.java b/src/tesseract/menuitems/ParticleEmitterMenuItem.java index 404f806..05b0d7a 100644 --- a/src/tesseract/menuitems/ParticleEmitterMenuItem.java +++ b/src/tesseract/menuitems/ParticleEmitterMenuItem.java @@ -55,7 +55,8 @@ public class ParticleEmitterMenuItem extends TesseractMenuItem { defaultButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { if (defaultButton.isSelected()) { - myWorld.addObject(new ParticleEmitter(new Vector3f(0f,.49f, 0f), + myWorld.addObject(new ParticleEmitter( + new Vector3f(0f,.49f, 0f), .5f, new Color3f(1f,0f,0f))); params.dispose(); } @@ -77,7 +78,8 @@ public class ParticleEmitterMenuItem extends TesseractMenuItem { setMass(mass); if (event.getSource() == enterButton) { - myWorld.addObject(new ParticleEmitter(getPosition(), .5f, new Color3f(1f,0f,0f))); + myWorld.addObject(new ParticleEmitter(getPosition(), + .5f, new Color3f(1f,0f,0f))); params.dispose(); } } diff --git a/src/tesseract/newmenu/NewChainLinkMenuItem.java b/src/tesseract/newmenu/NewChainLinkMenuItem.java new file mode 100644 index 0000000..59d0f53 --- /dev/null +++ b/src/tesseract/newmenu/NewChainLinkMenuItem.java @@ -0,0 +1,100 @@ +package tesseract.newmenu; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Set; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.vecmath.Vector3f; + +import tesseract.World; +import tesseract.objects.ChainLink2; +import tesseract.objects.Icosahedron; + +/** + * NewIcosahedronMenutItem + * + * Defines a menu item to add an ChainLink to the world. + * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan + * + * @author Phillip Cardon + */ +public class NewChainLinkMenuItem extends MenuItem { + + /** + * + */ + private static final long serialVersionUID = 1936364496102891064L; + //private static Map myParams; + + /** + * Constructor. + * @param theWorld to add objects to. + */ + public NewChainLinkMenuItem(final World theWorld) { + super(theWorld, "ChainLink(NEW)"); + buildParams(); + } + + /** + * Adds Parameters for user input. + * Sets default text box text. + */ + private void buildParams() { + myParameters.put("Diameter", new Float(0f)); + myParameters.put("Length", new Float(0f)); + myParameters.put("Width", new Float(0f)); + this.makePanel(); + myReadData.get("Diameter").setText(((Float) + ChainLink2.DEFAULT_DIAMETER_RATIO).toString()); + myReadData.get("Length").setText(((Float) + ChainLink2.DEFAULT_LENGTH).toString()); + myReadData.get("Width").setText(((Float) + ChainLink2.DEFAULT_WIDTH_RATIO).toString()); + } + + @Override + public void actionPerformed(final ActionEvent e) { + createParameterMenu(); + final JCheckBox defaultButton = getDefaultButton(); + final JFrame params = getParamFrame(); + final JButton enterButton = getEnterButton(); + + defaultButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + if (defaultButton.isSelected()) { + myWorld.addObject(new ChainLink2(MenuItem.DEFAULT_POSITION, + MenuItem.DEFAULT_MASS)); + params.dispose(); + } + } + }); + enterButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + Set itr = myParameters.keySet(); + for (String s : itr) { + Object o = myParameters.get(s); + String p = myReadData.get(s).getText(); + if (o.getClass().equals(new Float(0f).getClass())) { + myParameters.put(s, new Float(Float.parseFloat(p))); + } else if (o.getClass().equals(new Vector3f().getClass())) { + myParameters.put(s, parseVector(p)); + } + + } + if (event.getSource() == enterButton) { + myWorld.addObject( + new ChainLink2((Vector3f) myParameters.get("Position"), + ((Float) myParameters.get("Mass")).floatValue(), + ((Float) myParameters.get("Diameter")).floatValue(), + ((Float) myParameters.get("Length")).floatValue(), + ((Float) myParameters.get("Width")).floatValue())); + params.dispose(); + } + } + }); + + } +} diff --git a/src/tesseract/newmenu/NewEllipsoidMenuItem.java b/src/tesseract/newmenu/NewEllipsoidMenuItem.java new file mode 100644 index 0000000..dddf3d6 --- /dev/null +++ b/src/tesseract/newmenu/NewEllipsoidMenuItem.java @@ -0,0 +1,92 @@ +package tesseract.newmenu; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Set; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.vecmath.Vector3f; + +import tesseract.World; +import tesseract.objects.Ellipsoid; + +/** + * NewIcosahedronMenutItem + * + * Defines a menu item to add an Ellipsoid to the world. + * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan + * + * @author Phillip Cardon + */ +public class NewEllipsoidMenuItem extends MenuItem { + + /** + * + */ + private static final long serialVersionUID = 1936364496102891064L; + + /** + * A Default radius. + */ + private static final float DEFAULT_RADIUS = 0.1f; + + /** + * Constructor. + * @param theWorld to add objects to. + */ + public NewEllipsoidMenuItem(final World theWorld) { + super(theWorld, "Ellipsoid(NEW)"); + buildParams(); + } + + /** + * Adds Parameters for user input. + * Sets default text box text. + */ + private void buildParams() { + myParameters.put("Radius", new Float(0f)); + this.makePanel(); + myReadData.get("Radius").setText(((Float) + DEFAULT_RADIUS).toString()); + } + + @Override + public void actionPerformed(final ActionEvent e) { + createParameterMenu(); + final JCheckBox defaultButton = getDefaultButton(); + final JFrame params = getParamFrame(); + final JButton enterButton = getEnterButton(); + + defaultButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + if (defaultButton.isSelected()) { + myWorld.addObject(new Ellipsoid(getPosition(), + DEFAULT_RADIUS)); + params.dispose(); + } + } + }); + enterButton.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent event) { + Set itr = myParameters.keySet(); + for (String s : itr) { + Object o = myParameters.get(s); + String p = myReadData.get(s).getText(); + if (o.getClass().equals(new Float(0f).getClass())) { + myParameters.put(s, new Float(Float.parseFloat(p))); + } else if (o.getClass().equals(new Vector3f().getClass())) { + myParameters.put(s, parseVector(p)); + } + + } + if (event.getSource() == enterButton) { + myWorld.addObject(new Ellipsoid(getPosition(), getMass(), + ((Float) myParameters.get("Radius")).floatValue())); + params.dispose(); + } + } + }); + } +} diff --git a/src/tesseract/newmenu/NewToroidMenuItem.java b/src/tesseract/newmenu/NewToroidMenuItem.java index 89b5000..8d98595 100644 --- a/src/tesseract/newmenu/NewToroidMenuItem.java +++ b/src/tesseract/newmenu/NewToroidMenuItem.java @@ -16,7 +16,7 @@ import tesseract.objects.Toroid; /** * NewToroidMenuItem * - * Defines a menu item to add an Icosahedron to the world. + * Defines a menu item to add an Toroid to the world. * Code recycled from TesseractMenuItem by Steve Bradshaw and Jessie Morgan * * @author Phillip Cardon diff --git a/src/tesseract/objects/ChainLink.java b/src/tesseract/objects/ChainLink.java index a68b2e2..ceb0139 100644 --- a/src/tesseract/objects/ChainLink.java +++ b/src/tesseract/objects/ChainLink.java @@ -24,6 +24,7 @@ import com.sun.j3d.utils.geometry.NormalGenerator; * CHAINLINK LENGHT NOT YET IMPLEMENTED * @author Phillip Cardon * @version 0.1a + * @deprecated */ public class ChainLink extends PhysicalObject { //CONSTANTS diff --git a/src/tesseract/objects/Ellipsoid.java b/src/tesseract/objects/Ellipsoid.java index 593e228..3a617c0 100644 --- a/src/tesseract/objects/Ellipsoid.java +++ b/src/tesseract/objects/Ellipsoid.java @@ -74,6 +74,36 @@ public class Ellipsoid extends PhysicalObject { } updateTransformGroup(); } + + /** + * Create a new Ellipsoid. + * @author Phillip Cardon + * @param position Initial position. + * @param mass mass of ellipsoid + * @param radius a float for the size of the base sphere. + */ + public Ellipsoid(final Vector3f position, final float mass, + final float radius) { + super(position, mass); + + my_radius = radius; + + final float rSq = radius * radius; + final float a = 1.0f; + final float b = 1.0f; + final float c = 1.5f; + + + setShape(createDefaultEllipsoid(radius, a, b, c)); + + if (inverseMass != 0) { + inverseInertiaTensor.m00 = 1f / 5 / inverseMass * (b * rSq + c * rSq); + inverseInertiaTensor.m11 = 1f / 5 / inverseMass * (a * rSq + c * rSq); + inverseInertiaTensor.m22 = 1f / 5 / inverseMass * (a * rSq + b * rSq); + inverseInertiaTensor.invert(); + } + updateTransformGroup(); + } /** * Create a new Ellipsoid. -- cgit v1.2.3