diff options
| author | Steve <steveb9@u.washington.edu> | 2011-03-15 22:16:17 +0000 | 
|---|---|---|
| committer | Steve <steveb9@u.washington.edu> | 2011-03-15 22:16:17 +0000 | 
| commit | ce4cfb6670eaba20e27f8c5f499980be59bf0853 (patch) | |
| tree | 217d1c4290ccbd55d2741b79f6b7b7d728089809 /src | |
| parent | e6538f3f532fdcd35d0c97c2bc45caa1c7af0f35 (diff) | |
Added blimp model
Remove gravity for the blimp in World line 224
Diffstat (limited to 'src')
| -rw-r--r-- | src/tesseract/TesseractUI.java | 3 | ||||
| -rw-r--r-- | src/tesseract/World.java | 5 | ||||
| -rw-r--r-- | src/tesseract/objects/blimp/Blimp.java | 175 | ||||
| -rw-r--r-- | src/tesseract/objects/blimp/BlimpBox.java | 81 | ||||
| -rw-r--r-- | src/tesseract/objects/blimp/BlimpFin.java | 111 | 
5 files changed, 354 insertions, 21 deletions
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java index b1d5335..b451303 100644 --- a/src/tesseract/TesseractUI.java +++ b/src/tesseract/TesseractUI.java @@ -52,6 +52,7 @@ import tesseract.newmenu.NewPlanarPolygonMenuItem;  import tesseract.newmenu.NewSurfBoardMenuItem;  import tesseract.newmenu.NewToroidMenuItem;  import tesseract.objects.PhysicalObject; +import tesseract.objects.blimp.Blimp;  import tesseract.objects.remote.RemoteObjectMenu;  import com.sun.j3d.utils.picking.PickCanvas; @@ -157,6 +158,8 @@ public class TesseractUI extends JFrame {  						new Point3d(UNIT / 2, UNIT / 2, UNIT / 2)),  				myPeer); +		Blimp blimp = new Blimp(new Vector3f(0,0,0), .5f); +		myWorld.addObject(blimp);  		myCurrentObject = null;  		myObjectMenuItems = new JMenuItem[] { diff --git a/src/tesseract/World.java b/src/tesseract/World.java index deb907c..b2ca82a 100644 --- a/src/tesseract/World.java +++ b/src/tesseract/World.java @@ -27,6 +27,7 @@ import tesseract.forces.Force;  import tesseract.objects.HalfSpace;  import tesseract.objects.Particle;  import tesseract.objects.PhysicalObject; +import tesseract.objects.blimp.Blimp;  import common.CollidableObject;  import common.CollisionDetector; @@ -220,7 +221,9 @@ public class World implements Observer {  			// Apply forces  			for (Force force : myForces) { -				force.applyForceTo((PhysicalObject) obj); +				if(!(obj instanceof Blimp)) { +					force.applyForceTo((PhysicalObject) obj); +				}  			}  			// Update the object's state. diff --git a/src/tesseract/objects/blimp/Blimp.java b/src/tesseract/objects/blimp/Blimp.java index a543e02..e81be38 100644 --- a/src/tesseract/objects/blimp/Blimp.java +++ b/src/tesseract/objects/blimp/Blimp.java @@ -5,7 +5,11 @@ import java.awt.Color;  import javax.media.j3d.Appearance;
  import javax.media.j3d.BranchGroup;
  import javax.media.j3d.ColoringAttributes;
 +import javax.media.j3d.Group;
 +import javax.media.j3d.ImageComponent2D;
  import javax.media.j3d.Material;
 +import javax.media.j3d.Texture;
 +import javax.media.j3d.Texture2D;
  import javax.media.j3d.Transform3D;
  import javax.media.j3d.TransformGroup;
  import javax.vecmath.Color3f;
 @@ -14,7 +18,11 @@ import javax.vecmath.Vector3f;  import tesseract.objects.PhysicalObject;
 +import com.sun.j3d.utils.geometry.Cone;
 +import com.sun.j3d.utils.geometry.Cylinder;
 +import com.sun.j3d.utils.geometry.Primitive;
  import com.sun.j3d.utils.geometry.Sphere;
 +import com.sun.j3d.utils.image.TextureLoader;
  public class Blimp extends PhysicalObject {
 @@ -24,22 +32,37 @@ public class Blimp extends PhysicalObject {  	 */
  	//private static final float DEFAULT_MASS = Float.POSITIVE_INFINITY;
  	private static final float DEFAULT_MASS = 10;
 +	
 +	/**
 +	 * Use to scale all object together
 +	 */
 +	private float my_scale;
 +	
 +	/**
 +	 * ellipsoid of blimp radius
 +	 */
 +	private float my_radius;
 +	
  	/**
  	 * Create a new Blimp.
  	 * 
  	 * @param position Initial position.
 -	 * @param radius a float for the size of the base sphere.
 +	 * @param scale determine the size of the blimp
  	 * @param theColor of object.
  	 */
 -	public Blimp(final Vector3f position, final float radius) {
 +	public Blimp(final Vector3f position, final float scale) {
  		super(position, DEFAULT_MASS);
 -		final float rSq = radius * radius;
 +		
 +		my_scale = scale;
 +		
 +		my_radius = .08f * my_scale;
 +		
 +		final float rSq = my_radius * my_radius;
  		final float a = 1.0f;
  		final float b = 1.0f;
 -		final float c = 2f;
 -		
 +		final float c = 2.8f;
 -		//setShape(createDefaultEllipsoid(radius, a, b, c));
 +		setShape(create(a, b, c));
  		if (inverseMass != 0) {
  			inverseInertiaTensor.m00 = 1f / 5 / inverseMass * (b * rSq + c * rSq);
 @@ -51,27 +74,51 @@ public class Blimp extends PhysicalObject {  	}
  	/**
 -	 * This creates a default Ellipsoid for the 2 argument constructor.
 -	 * @param radius the size of the ellipsoid
 +	 * creates the shapes in the blimp
  	 * @param a float in the ellipsoid formula.
  	 * @param b float in the ellipsoid formula.
  	 * @param c float in the ellipsoid formula.
  	 * @return TransformGroup with the shape.
  	 */
 -	/*private TransformGroup createDefaultEllipsoid(final float radius, final float a,
 +	private TransformGroup create( final float a,
  			final float b, final float c) {
 -		BranchGroup blimp = new BranchGroup();
 +		TransformGroup blimp = new TransformGroup();
 +		blimp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
 +		blimp.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
  		//blimp node
 -		Appearance meshApp = new Appearance();
 +		Appearance b_appearance = new Appearance();
  		Material surface = new Material();
 -		surface.setDiffuseColor(new Color3f(1f, 1f, 1f));
 -		meshApp.setMaterial(surface);
 -		meshApp.setColoringAttributes(new ColoringAttributes(new Color3f(1f, 1f, 1f),
 -				ColoringAttributes.NICEST));
 -		Sphere sphere = new Sphere(radius, new Sphere().getPrimitiveFlags() | Sphere.ENABLE_GEOMETRY_PICKING,
 -				30, meshApp);
 +		surface.setDiffuseColor(new Color3f(.5f, .6f, .6f));
 +		b_appearance.setMaterial(surface);
 +		
 +		/*TextureLoader t2 = new TextureLoader("lava.jpg", null);
 +		ImageComponent2D image2 = t2.getImage();
 +		int width2 = image2.getWidth();
 +		int height2 = image2.getHeight();
 +		Texture2D texture2 = new Texture2D(Texture.MULTI_LEVEL_MIPMAP, Texture.RGB, width2, height2);
 +		
 +		int imageLevel2 = 0;
 +		texture2.setImage(imageLevel2, image2);
 +		while (width2 > 1 || height2 > 1) {
 +			imageLevel2++;
 +			if (width2 > 1) width2 /= 2;
 +			if (height2 > 1) height2 /= 2;
 +			texture2.setImage(imageLevel2, t2.getScaledImage(width2, height2));
 +		}
 +		texture2.setMagFilter(Texture2D.NICEST);
 +		texture2.setMinFilter(Texture2D.NICEST);
 +		Material mat2 = new Material();
 +		mat2.setDiffuseColor(1, 0, 0);
 +		
 +		Appearance b_appearance = new Appearance();
 +		b_appearance.setTexture(texture2);
 +		b_appearance.setMaterial(mat2);*/
 +		
 +		Sphere sphere = new Sphere(my_radius,
 +				new Sphere().getPrimitiveFlags() | Sphere.ENABLE_GEOMETRY_PICKING,
 +				30, b_appearance );
  		Transform3D tmp = new Transform3D();
  		tmp.set(new Matrix3f(a, 0.0f, 0.0f, 0.0f, b, 0.0f, 0.0f, 0.0f, c));
  		TransformGroup tgBlimp = new TransformGroup(tmp);
 @@ -80,12 +127,100 @@ public class Blimp extends PhysicalObject {  		tgBlimp.addChild(sphere);
  		//box node
 -		//Box box = new Box(2f, .1f, .2f, .3f, new Vector3f(0f,-.05f, 0f), new Color3f(1f, 1f, 1f));
 +		Appearance boxApp = new Appearance();
 +		Material box_surface = new Material();
 +		box_surface.setDiffuseColor(new Color3f(.7f, .6f, .4f));
 +		boxApp.setMaterial(box_surface);
 +		BlimpBox box = new BlimpBox(100, .05f * my_scale, .03f * my_scale, .1f * my_scale,
 +				new Vector3f(0f * my_scale, -.08f * my_scale, 0f * my_scale), boxApp);
 +		TransformGroup tgBox = new TransformGroup();
 +		tgBox.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
 +		tgBox.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
 +		tgBox.addChild(box.getGroup());
 +		//fin1
 +		TextureLoader tl = new TextureLoader("lava.jpg", null);
 +		ImageComponent2D image = tl.getImage();
 +		int width = image.getWidth();
 +		int height = image.getHeight();
 +		Texture2D texture = new Texture2D(Texture.MULTI_LEVEL_MIPMAP, Texture.RGB, width, height);
 +		
 +		int imageLevel = 0;
 +		texture.setImage(imageLevel, image);
 +		while (width > 1 || height > 1) {
 +			imageLevel++;
 +			if (width > 1) width /= 2;
 +			if (height > 1) height /= 2;
 +			texture.setImage(imageLevel, tl.getScaledImage(width, height));
 +		}
 +		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);
 +		BlimpFin fin = new BlimpFin(1, new Vector3f(0f * my_scale, 0f * my_scale,
 +				-.165f  * my_scale), .08f * my_scale, appearance);
 +		Transform3D rotate = new Transform3D();
 +		rotate.rotZ(Math.PI / 2);
 +		TransformGroup tgFin = new TransformGroup(rotate);
 +		tgFin.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
 +		tgFin.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
 +		tgFin.addChild(fin.getGroup());
 -		//return tg;
 -	}*/
 +		//fin2
 +		BlimpFin fin2 = new BlimpFin(1, new Vector3f(0f * my_scale,
 +				0f * my_scale, -.165f * my_scale), .08f * my_scale, appearance);
 +		Transform3D rotate2 = new Transform3D();
 +		//rotate2.rotZ(Math.PI / 2);
 +		TransformGroup tgFin2 = new TransformGroup(rotate2);
 +		tgFin2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
 +		tgFin2.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
 +		tgFin2.addChild(fin2.getGroup());
 +		
 +		//pole spike in front
 +		TransformGroup tgPole = createPole(new Color3f(.7f, .6f, .4f));
 +		Transform3D rotate3 = new Transform3D();
 +		rotate3.rotX(Math.PI / 2);
 +		tgPole.setTransform(rotate3);
 +		
 +		blimp.addChild(tgBlimp);
 +		blimp.addChild(tgBox);
 +		blimp.addChild(tgFin);
 +		blimp.addChild(tgFin2);
 +		blimp.addChild(tgPole);
 +		return blimp;
 +	}
 +	
 +	private TransformGroup createPole(Color3f color) {
 +		// Node managing the cone.
 +		TransformGroup cone = new TransformGroup();
 +		Appearance axisApp = new Appearance();
 +		Material axisMat = new Material();
 +		axisMat.setDiffuseColor(color);
 +		axisApp.setMaterial(axisMat);
 +		axisApp.setColoringAttributes(new ColoringAttributes(0f, 0f, 0f, ColoringAttributes.SHADE_GOURAUD));
 +		cone.addChild(new Cone(0.02f * my_scale, 0.1f * my_scale, new Cone().getPrimitiveFlags(), 80, 20, axisApp));
 +		Transform3D tmp = new Transform3D();
 +		tmp.setTranslation(new Vector3f(0f, .23f * my_scale, 0f));
 +		cone.setTransform(tmp);
 +
 +		// Node managing the cylinder.
 +		TransformGroup cylinder = new TransformGroup();
 +		cylinder.addChild(new Cylinder(0.02f * my_scale, .3f * my_scale, new Cylinder().getPrimitiveFlags(), 80, 20, axisApp));
 +		tmp = new Transform3D();
 +		tmp.setTranslation(new Vector3f(0f, 0.075f * my_scale, 0f));
 +		cylinder.setTransform(tmp);
 +
 +		// Node managing the entire axis.
 +		TransformGroup axis = new TransformGroup();
 +		axis.addChild(cone);
 +		axis.addChild(cylinder);
 +		
 +		return axis;
 +	}
  }
 diff --git a/src/tesseract/objects/blimp/BlimpBox.java b/src/tesseract/objects/blimp/BlimpBox.java new file mode 100644 index 0000000..6d75777 --- /dev/null +++ b/src/tesseract/objects/blimp/BlimpBox.java @@ -0,0 +1,81 @@ +package tesseract.objects.blimp;
 +
 +import java.awt.Color;
 +
 +import javax.media.j3d.Appearance;
 +import javax.media.j3d.Geometry;
 +import javax.media.j3d.Material;
 +import javax.media.j3d.Node;
 +import javax.media.j3d.TransformGroup;
 +import javax.vecmath.Color3f;
 +import javax.vecmath.Vector3f;
 +
 +import tesseract.objects.PhysicalObject;
 +
 +import com.sun.j3d.utils.geometry.Box;
 +import com.sun.j3d.utils.geometry.Primitive;
 +
 +public class BlimpBox extends PhysicalObject {
 +	
 +	/**
 +	 * The appearance of this blimp box
 +	 */
 +	private Appearance my_appearance;
 +	
 +	/**
 +	 * The width.
 +	 */
 +	private float my_width;
 +	
 +	/**
 +	 * The height.
 +	 */
 +	private float my_height;
 +	
 +	/**
 +	 * The depth.
 +	 */
 +	private float my_depth;
 +	
 +	/**
 +	 * The tg for this object
 +	 */
 +	private TransformGroup my_tg;
 +	
 +
 +	
 +	public BlimpBox(float mass, float width, float height, float depth,
 +			Vector3f position, final Appearance app) {
 +		super(position, mass);
 +		
 +		my_width = width;
 +		my_height = height;
 +		my_depth = depth;
 +		my_appearance = app;
 +		
 +		
 +		setShape(createShape());
 +		
 +		previousPosition.set(position);
 +		if (inverseMass != 0) {
 +			inverseInertiaTensor.m00 = 1f / 12 / inverseMass * (height * height + depth * depth);
 +			inverseInertiaTensor.m11 = 1f / 12 / inverseMass * (width * width + depth * depth);
 +			inverseInertiaTensor.m22 = 1f / 12 / inverseMass * (width * width + height * height);
 +			inverseInertiaTensor.invert();
 +		}
 +		updateTransformGroup();
 +	}
 +
 +	public Node createShape() {
 +		return new com.sun.j3d.utils.geometry.Box(my_width / 2, my_height / 2, my_depth / 2, my_appearance);
 +
 +	}
 +	
 +	/**
 +	 * get the tg for this box
 +	 */
 +	public Node getTG() {
 +		return my_tg;
 +	}
 +}
 +
 diff --git a/src/tesseract/objects/blimp/BlimpFin.java b/src/tesseract/objects/blimp/BlimpFin.java new file mode 100644 index 0000000..f5883cd --- /dev/null +++ b/src/tesseract/objects/blimp/BlimpFin.java @@ -0,0 +1,111 @@ +package tesseract.objects.blimp;
 +
 +/*
 + * Class PlanarPolygon
 + * TCSS 491 Computational Worlds
 + * Steve Bradshaw
 + */
 +
 +
 +import javax.media.j3d.Appearance;
 +import javax.media.j3d.Geometry;
 +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;
 +import javax.media.j3d.Texture;
 +import javax.media.j3d.Texture2D;
 +import javax.media.j3d.Transform3D;
 +import javax.media.j3d.TransformGroup;
 +import javax.media.j3d.TriangleFanArray;
 +import javax.vecmath.Color3f;
 +import javax.vecmath.Point3f;
 +import javax.vecmath.TexCoord2f;
 +import javax.vecmath.Vector3f;
 +
 +import tesseract.objects.PhysicalObject;
 +
 +import com.sun.j3d.utils.geometry.GeometryInfo;
 +import com.sun.j3d.utils.geometry.NormalGenerator;
 +import com.sun.j3d.utils.image.TextureLoader;
 +
 +/**
 + * This class creates an planar polygon using Mathew Aldens design
 + * of a circle, but this adds lava texture and lower divisions
 + * 
 + * @author Steve Bradshaw & Mathew Alden
 + * @version 8 Feb 2011
 + */
 +public class BlimpFin extends PhysicalObject {
 +	
 +	/**
 +	 * Number of divisions in the sphere.
 +	 */
 +	public static final int DEFAULT_DIVISIONS = 4;
 +	
 +	/**
 +	 * The appearance of this fin
 +	 */
 +	private Appearance my_appearance;
 +	
 +	/**
 +	 * Create a new Ellipsoid.
 +	 * 
 +	 * @param position Initial position.
 +	 * @param mass Initial mass.
 +	 * @param radius the radius of the base sphere.
 +	 * @param divisions an in for the shape divisions.
 +	 */
 +	public BlimpFin( final float mass, final Vector3f position,
 +			final float radius, final Appearance appearance) {
 +		super(position, mass);
 +		
 +		my_appearance = appearance;
 +		
 +		setShape(createShape(radius, DEFAULT_DIVISIONS));
 +		
 +		if (inverseMass != 0) {
 +			inverseInertiaTensor.m00 = 1f / 4 / inverseMass * radius * radius;
 +			inverseInertiaTensor.m11 = 2 * inverseInertiaTensor.m00;
 +			inverseInertiaTensor.m22 = inverseInertiaTensor.m00;
 +			inverseInertiaTensor.invert();
 +		}
 +		updateTransformGroup();
 +	}
 +
 +	/**
 +	 * 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.
 +	 * @param appearance an Appearance object.
 +	 * @return Node a polygon.
 +	 */
 +	private Node createShape(final float radius, final int divisions) {
 +		TriangleFanArray geometry = new TriangleFanArray(divisions,
 +				TriangleFanArray.COORDINATES | TriangleFanArray.TEXTURE_COORDINATE_2, new int[] {divisions});
 +		for (int i = 0; i < divisions; i++) {
 +			float baseX = (float)Math.cos(2 * Math.PI * i / divisions);
 +			float baseZ = -(float)Math.sin(2 * Math.PI * i / divisions);
 +			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 fin = new Shape3D(gInfo.getGeometryArray());
 +
 +		PolygonAttributes polyAttr = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
 +		my_appearance.setPolygonAttributes(polyAttr);		
 +		geometry.setCapability(Geometry.ALLOW_INTERSECT);
 +		fin =  new Shape3D(geometry, my_appearance);
 +		Transform3D rotate = new Transform3D();
 +		rotate.rotY(Math.PI / 4);
 +		TransformGroup tg = new TransformGroup(rotate);
 +		tg.addChild(fin);
 +		return tg;
 +	}
 +}
 +
  | 
