diff options
author | Steve <steveb9@u.washington.edu> | 2011-02-12 09:15:58 +0000 |
---|---|---|
committer | Steve <steveb9@u.washington.edu> | 2011-02-12 09:15:58 +0000 |
commit | 5659cdbb139a1820b5739553fc331505852a3740 (patch) | |
tree | 37fc9d05ff59ea14c8b0a0bc0549453c7cff7995 /src | |
parent | d1df88907d55240e79ee8597f6032a4c0de6b957 (diff) |
ChainLink added but not collidible because it looks like it uses a IndexedQuadArray and Alden's code only supports the triangles.
Also added normals to planar poly
Diffstat (limited to 'src')
-rw-r--r-- | src/tesseract/TesseractUI.java | 6 | ||||
-rw-r--r-- | src/tesseract/menuitems/ChainLinkMenuItem.java | 73 | ||||
-rw-r--r-- | src/tesseract/menuitems/EllipsoidMenuItem.java | 1 | ||||
-rw-r--r-- | src/tesseract/objects/PlanarPolygon.java | 48 |
4 files changed, 93 insertions, 35 deletions
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java index 7b1a180..99b2fa4 100644 --- a/src/tesseract/TesseractUI.java +++ b/src/tesseract/TesseractUI.java @@ -26,6 +26,7 @@ import javax.vecmath.Vector3f; import tesseract.forces.Force; import tesseract.forces.Gravity; +import tesseract.menuitems.ChainLinkMenuItem; import tesseract.menuitems.EllipsoidMenuItem; import tesseract.menuitems.GravityMenuItem; import tesseract.menuitems.IcosahedronMenuItem; @@ -105,7 +106,7 @@ public class TesseractUI extends JFrame { public TesseractUI() { super("Tesseract Project"); - my_gravity = new Gravity(-.5f); + my_gravity = new Gravity(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -118,7 +119,8 @@ public class TesseractUI extends JFrame { new ParticleMenuItem(myWorld), new PlanarPolygonMenuItem(myWorld), new EllipsoidMenuItem(myWorld), - new IcosahedronMenuItem(myWorld) + new IcosahedronMenuItem(myWorld), + new ChainLinkMenuItem(myWorld) }; createMenu(); setupCanvas(); diff --git a/src/tesseract/menuitems/ChainLinkMenuItem.java b/src/tesseract/menuitems/ChainLinkMenuItem.java index 4f99645..e015b42 100644 --- a/src/tesseract/menuitems/ChainLinkMenuItem.java +++ b/src/tesseract/menuitems/ChainLinkMenuItem.java @@ -1,5 +1,76 @@ package tesseract.menuitems;
-public class ChainLinkMenuItem {
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.JCheckBox;
+import javax.swing.JColorChooser;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import tesseract.World;
+import tesseract.objects.ChainLink;
+import tesseract.objects.Icosahedron;
+import tesseract.objects.PlanarPolygon;
+
+/**
+ * Icosahedron Menu Item.
+ *
+ * @author Steve Bradshaw
+ */
+public class ChainLinkMenuItem extends TesseractMenuItem {
+
+ /**
+ * Serial ID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor for the menu item.
+ *
+ * @param theWorld The world into which we add.
+ */
+ public ChainLinkMenuItem(final World theWorld) {
+ super(theWorld, "ChainLink");
+ }
+
+ /**
+ * Action handler.
+ *
+ * @param arg0 Unused event info.
+ */
+ public void actionPerformed(final ActionEvent arg0) {
+ createParameterMenu();
+
+ final float scale = 1f;
+ final float sliceRadius = .06f; //inside whole
+ final int sliceDivisions = 50;
+ final float arcRadius = .08f; //outside whole
+ final int arcDivisions = 30;
+
+ //If the default button is checked, the frame will close.
+ final JCheckBox defaultButton = getDefaultButton();
+ final JFrame params = getParamFrame();
+
+ defaultButton.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent e) {
+ if (defaultButton.isSelected()) {
+ myWorld.addObject(new ChainLink(getDefaultPosition(), 1, scale,
+ sliceRadius, sliceDivisions, arcRadius, arcDivisions));
+ params.dispose();
+ }
+ }
+ });
+ /*Vector3f pos =
+ parseVector(JOptionPane.showInputDialog("Enter the position"));
+ float radius =
+ Float.parseFloat(JOptionPane.showInputDialog("Enter the radius"));
+
+ myWorld.addObject(new Icosahedron(pos, radius));*/
+ }
}
+
+
diff --git a/src/tesseract/menuitems/EllipsoidMenuItem.java b/src/tesseract/menuitems/EllipsoidMenuItem.java index 6aefa3e..71b302f 100644 --- a/src/tesseract/menuitems/EllipsoidMenuItem.java +++ b/src/tesseract/menuitems/EllipsoidMenuItem.java @@ -60,6 +60,7 @@ public class EllipsoidMenuItem extends TesseractMenuItem { +
/*Vector3f pos =
parseVector(JOptionPane.showInputDialog("Enter the position"));
float radius =
diff --git a/src/tesseract/objects/PlanarPolygon.java b/src/tesseract/objects/PlanarPolygon.java index 5782fa7..edc56b2 100644 --- a/src/tesseract/objects/PlanarPolygon.java +++ b/src/tesseract/objects/PlanarPolygon.java @@ -10,6 +10,7 @@ import javax.media.j3d.Appearance; import javax.media.j3d.Geometry;
import javax.media.j3d.Group;
import javax.media.j3d.ImageComponent2D;
+import javax.media.j3d.Material;
import javax.media.j3d.Node;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.Shape3D;
@@ -22,6 +23,8 @@ import javax.vecmath.Point3f; import javax.vecmath.TexCoord2f;
import javax.vecmath.Vector3f;
+import com.sun.j3d.utils.geometry.GeometryInfo;
+import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.image.TextureLoader;
@@ -76,27 +79,12 @@ public class PlanarPolygon extends PhysicalObject { public PlanarPolygon(final Vector3f position, final float radius) {
super(position, DEFAULT_MASS);
- //getTransformGroup().addChild(createShape(radius, DEFAULT_DIVISIONS));
setShape(createShape(radius, DEFAULT_DIVISIONS));
}
-
- /**
- * This creates a default Ellipsoid for the 2 argument constructor.
- * @param radius the siz of the ellipsoid
- */
- /*private void createDefaultPlanarPolygon(final float radius) {
-
- Sphere sphere = new Sphere(radius, new Sphere().getPrimitiveFlags(),
- DEFAULT_DIVISIONS);
- Transform3D tmp = new Transform3D();
- tmp.set(new Matrix3f(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.5f));
- getTransformGroup().setTransform(tmp);
- getTransformGroup().addChild(sphere);
- }*/
-
+
/**
- * This method creates a planar polygon shape.
+ * This method creates a planar polygon shape with lava texture.
*
* @param radius a float for the size of the base polygon
* @param divisions an int for the number of divisons
@@ -112,6 +100,12 @@ public class PlanarPolygon extends PhysicalObject { geometry.setCoordinate(i, new Point3f(radius * baseX, 0, radius * baseZ));
geometry.setTextureCoordinate(0, i, new TexCoord2f((baseX + 1) / 2, (-baseZ + 1) / 2));
}
+
+ GeometryInfo gInfo = new GeometryInfo(geometry);
+ new NormalGenerator().generateNormals(gInfo);
+ gInfo.convertToIndexedTriangles();
+ Shape3D polygon = new Shape3D(gInfo.getGeometryArray());
+
TextureLoader tl = new TextureLoader("lava.jpg", null);
ImageComponent2D image = tl.getImage();
int width = image.getWidth();
@@ -128,26 +122,16 @@ public class PlanarPolygon extends PhysicalObject { }
texture.setMagFilter(Texture2D.NICEST);
texture.setMinFilter(Texture2D.NICEST);
-
+ Material mat = new Material();
+ mat.setDiffuseColor(1, 0, 0);
+
Appearance appearance = new Appearance();
appearance.setTexture(texture);
+ appearance.setMaterial(mat);
PolygonAttributes polyAttr = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
appearance.setPolygonAttributes(polyAttr);
geometry.setCapability(Geometry.ALLOW_INTERSECT);
- Shape3D polygon = new Shape3D(geometry, appearance);
+ polygon = new Shape3D(geometry, appearance);
return polygon;
- //getTransformGroup().addChild(polygon);
- //return getTransformGroup();
}
-
- /*private void createShape(final float radius, final int primflags,
- final Appearance appearance, final int divisions, final float b,
- final float c) {
-
- Sphere sphere = new Sphere(radius, primflags, divisions, appearance);
- Transform3D tmp = new Transform3D();
- tmp.set(new Matrix3f(1.0f, 0.0f, 0.0f, 0.0f, b, 0.0f, 0.0f, 0.0f, c));
- getTransformGroup().setTransform(tmp);
- getTransformGroup().addChild(sphere);
- }*/
}
|