Source code file content

Revision: 1

First check in
» Project Revision History

» Checkout URL

source / src / org / pushingpixels / marble / Explosion3D.java

Size: 2930 bytes, 1 line
package org.pushingpixels.marble;

import java.awt.Color;

import javax.media.j3d.*;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.geometry.Sphere;

public class Explosion3D {
	float x;

	float y;

	float z;

	Color color;

	float alpha;

	Sphere sphere3D;

	private Appearance appearance3D;

	private TransformGroup sphere3DTransformGroup;

	private BranchGroup sphere3DBranchGroup;

	public Explosion3D(float x, float y, float z, Color color) {
		this.x = x;
		this.y = y;
		this.z = z;
		this.color = color;
		this.alpha = 1.0f;

		this.sphere3DTransformGroup = new TransformGroup();
		this.sphere3DTransformGroup
				.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		Transform3D mt = new Transform3D();
		mt.setTranslation(new Vector3d(this.x, this.y, this.z));
		this.sphere3DTransformGroup.setTransform(mt);
		this.appearance3D = new Appearance();
		this.appearance3D
				.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
		this.appearance3D
				.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
		this.appearance3D.setColoringAttributes(new ColoringAttributes(color
				.getRed() / 255.0f, color.getGreen() / 255.0f,
				color.getBlue() / 255.0f, ColoringAttributes.SHADE_FLAT));
		this.appearance3D.setTransparencyAttributes(new TransparencyAttributes(
				TransparencyAttributes.BLENDED, 0.0f));
		this.sphere3D = new Sphere(0.002f, appearance3D);
		this.sphere3DTransformGroup.addChild(this.sphere3D);

		this.sphere3DBranchGroup = new BranchGroup();
		this.sphere3DBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);

		this.sphere3DBranchGroup.addChild(this.sphere3DTransformGroup);
	}

	public void setAlpha(float alpha) {
		this.alpha = alpha;

		this.appearance3D.setTransparencyAttributes(new TransparencyAttributes(
				TransparencyAttributes.BLENDED, 1.0f - alpha));
	}

	public void setX(float x) {
		this.x = x;

		Transform3D mt = new Transform3D();
		mt.setTranslation(new Vector3d(this.x, this.y, this.z));
		this.sphere3DTransformGroup.setTransform(mt);
	}

	public void setY(float y) {
		this.y = y;
		Transform3D mt = new Transform3D();
		mt.setTranslation(new Vector3d(this.x, this.y, this.z));
		this.sphere3DTransformGroup.setTransform(mt);
	}

	public void setZ(float z) {
		this.z = z;
		Transform3D mt = new Transform3D();
		mt.setTranslation(new Vector3d(this.x, this.y, this.z));
		this.sphere3DTransformGroup.setTransform(mt);
	}

	public void setColor(Color color) {
		this.color = color;
		this.appearance3D.setColoringAttributes(new ColoringAttributes(color
				.getRed() / 255.0f, color.getGreen() / 255.0f,
				color.getBlue() / 255.0f, ColoringAttributes.SHADE_FLAT));
	}

	public TransformGroup getSphere3DTransformGroup() {
		return sphere3DTransformGroup;
	}

	public BranchGroup getSphere3DBranchGroup() {
		return sphere3DBranchGroup;
	}
}
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20100521.d19488a)
 
 
loading
Please Confirm