[marble~source:1] First check in

  • From: kirillg@kenai.com
  • To: commits@marble.kenai.com
  • Subject: [marble~source:1] First check in
  • Date: Fri, 3 Jul 2009 04:11:55 +0000

Project:    marble
Repository: source
Revision:   1
Author:     kirillg
Date:       2009-07-03 04:11:53 UTC
Link:       http://kenai.com/projects/marble/sources/source/revision/1

Log Message:
------------
First check in


Added Paths:
------------
src
src/org/pushingpixels/marble/MarbleFireworks3D.java
src/org
src/org/pushingpixels/marble/Explosion3D.java
src/org/pushingpixels/marble
src/org/pushingpixels


Diffs:
------
Index: src/org/pushingpixels/marble/MarbleFireworks3D.java
===================================================================
--- src/org/pushingpixels/marble/MarbleFireworks3D.java (revision 0)
+++ src/org/pushingpixels/marble/MarbleFireworks3D.java (revision 1)
@@ -0,0 +1,253 @@
+package org.pushingpixels.marble;
+
+import java.awt.*;
+import java.util.*;
+
+import javax.media.j3d.*;
+import javax.media.j3d.Locale;
+import javax.swing.JFrame;
+import javax.vecmath.Vector3d;
+
+import jp.nyatla.nyartoolkit.core.NyARCode;
+import jp.nyatla.nyartoolkit.java3d.utils.*;
+
+import org.pushingpixels.trident.Timeline;
+import org.pushingpixels.trident.TimelineScenario;
+import org.pushingpixels.trident.Timeline.TimelineState;
+import org.pushingpixels.trident.callback.TimelineCallbackAdapter;
+import org.pushingpixels.trident.callback.TimelineScenarioCallback;
+
+import com.sun.j3d.utils.geometry.*;
+import com.sun.j3d.utils.universe.SimpleUniverse;
+
+public class MarbleFireworks3D extends JFrame implements
+               NyARSingleMarkerBehaviorListener {
+       private static final float SCALE = 0.005f;
+
+       private static final int HEIGHT = 480;
+
+       private static final int WIDTH = 640;
+
+       private static final long serialVersionUID = -8472866262481865377L;
+
+       private final String CARCODE_FILE = 
"C:/jprojects/marble/Data/patt.hiro";
+
+       private final String PARAM_FILE = 
"C:/jprojects/marble/Data/camera_para.dat";
+
+       private NyARSingleMarkerBehaviorHolder nya_behavior;
+
+       private J3dNyARParam ar_param;
+
+       private Canvas3D canvas;
+
+       private Locale locale;
+
+       private VirtualUniverse universe;
+
+       private TransformGroup mainSceneGroup;
+
+       private Map<TimelineScenario, Set<Explosion3D>> explosions;
+
+       public static void main(String[] args) {
+               try {
+                       MarbleFireworks3D frame = new MarbleFireworks3D();
+                       frame.setVisible(true);
+                       Insets ins = frame.getInsets();
+                       frame.setSize(WIDTH + ins.left + ins.right, HEIGHT + 
ins.top
+                                       + ins.bottom);
+                       frame.setLocationRelativeTo(null);
+                       frame.startCapture();
+                       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       public void onUpdate(boolean i_is_marker_exist, Transform3D 
i_transform3d) {
+       }
+
+       public void startCapture() throws Exception {
+               nya_behavior.start();
+       }
+
+       public MarbleFireworks3D() throws Exception {
+               super("Java3D Example NyARToolkit");
+
+               NyARCode ar_code = new NyARCode(16, 16);
+               ar_code.loadARPattFromFile(CARCODE_FILE);
+               ar_param = new J3dNyARParam();
+               ar_param.loadARParamFromFile(PARAM_FILE);
+               ar_param.changeScreenSize(WIDTH, HEIGHT);
+
+               universe = new VirtualUniverse();
+               locale = new Locale(universe);
+               canvas = new 
Canvas3D(SimpleUniverse.getPreferredConfiguration());
+               View view = new View();
+               ViewPlatform viewPlatform = new ViewPlatform();
+               view.attachViewPlatform(viewPlatform);
+               view.addCanvas3D(canvas);
+               view.setPhysicalBody(new PhysicalBody());
+               view.setPhysicalEnvironment(new PhysicalEnvironment());
+               // view.setSceneAntialiasingEnable(true);
+
+               Transform3D camera_3d = ar_param.getCameraTransform();
+               view.setCompatibilityModeEnable(true);
+               view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
+               view.setLeftProjection(camera_3d);
+
+               TransformGroup viewGroup = new TransformGroup();
+               Transform3D viewTransform = new Transform3D();
+               viewTransform.rotY(Math.PI);
+               viewTransform.setTranslation(new Vector3d(0.0, 0.0, 0.0));
+               viewGroup.setTransform(viewTransform);
+               viewGroup.addChild(viewPlatform);
+               BranchGroup viewRoot = new BranchGroup();
+               viewRoot.addChild(viewGroup);
+               locale.addBranchGraph(viewRoot);
+
+               Background background = new Background();
+               BoundingSphere bounds = new BoundingSphere();
+               bounds.setRadius(10.0);
+               background.setApplicationBounds(bounds);
+               background.setImageScaleMode(Background.SCALE_FIT_ALL);
+               background.setCapability(Background.ALLOW_IMAGE_WRITE);
+               BranchGroup root = new BranchGroup();
+               root.addChild(background);
+
+               // TransformGroup transform = new TransformGroup();
+               // 
transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+               // transform.addChild(createSceneGraph());
+               // root.addChild(transform);
+
+               TransformGroup boxGroup = new TransformGroup();
+               boxGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+               Transform3D boxTransform = new Transform3D();
+               boxTransform.setTranslation(new Vector3d(-0.006f, -0.006f, 
-0.01f));
+               boxGroup.setTransform(boxTransform);
+               Appearance boxAppearance = new Appearance();
+               boxAppearance.setColoringAttributes(new ColoringAttributes(0, 
0, 0,
+                               ColoringAttributes.SHADE_FLAT));
+               Box box = new Box(0.035f, 0.035f, 0.0001f, boxAppearance);
+               boxGroup.addChild(box);
+               // root.addChild(boxGroup);
+
+               mainSceneGroup = new TransformGroup();
+               
mainSceneGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+               mainSceneGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
+               mainSceneGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
+               // mainSceneGroup.addChild(boxGroup);
+               root.addChild(mainSceneGroup);
+
+               nya_behavior = new NyARSingleMarkerBehaviorHolder(ar_param, 
30f,
+                               ar_code, 0.08);
+               nya_behavior.setTransformGroup(mainSceneGroup);
+               nya_behavior.setBackGround(background);
+
+               root.addChild(nya_behavior.getBehavior());
+               nya_behavior.setUpdateListener(this);
+
+               locale.addBranchGraph(root);
+
+               setLayout(new BorderLayout());
+               add(canvas, BorderLayout.CENTER);
+
+               this.explosions = new HashMap<TimelineScenario, 
Set<Explosion3D>>();
+
+               // start adding random explosions
+               new Thread() {
+                       @Override
+                       public void run() {
+                               while (true) {
+                                       try {
+                                               Thread.sleep(500 + (int) 
(Math.random() * 1000));
+                                               float x = -1.0f + 2.0f * 
(float) Math.random();
+                                               float y = -1.0f + 2.0f * 
(float) Math.random();
+                                               float z = (float) 
Math.random();
+                                               addFireworkNew(x * 5.0f, y * 
5.0f, 5.0f + z * 12.0f);
+                                       } catch (Exception exc) {
+                                       }
+                               }
+                       }
+               }.start();
+       }
+
+       private void addFireworkNew(float x, final float y, final float z) {
+               final TimelineScenario scenario = new 
TimelineScenario.Parallel();
+               Set<Explosion3D> scenarioExplosions = new 
HashSet<Explosion3D>();
+
+               float R = 6;
+               int NUMBER = 20;
+               int r = (int) (255 * Math.random());
+               int g = (int) (100 + 155 * Math.random());
+               int b = (int) (50 + 205 * Math.random());
+               Color color = new Color(r, g, b);
+               for (double alpha = -Math.PI / 2; alpha <= Math.PI / 2; alpha 
+= 2
+                               * Math.PI / NUMBER) {
+                       final float dy = (float) (R * Math.sin(alpha));
+                       final float yFinal = y + dy;
+                       float rSection = (float) Math.abs(R * 
Math.cos(alpha));
+                       int expCount = Math.max(0, (int) (NUMBER * rSection / 
R));
+                       for (int i = 0; i < expCount; i++) {
+                               float xFinal = (float) (x + rSection
+                                               * Math.cos(i * 2.0 * Math.PI 
/ expCount));
+                               final float dz = (float)(rSection
+                               * Math.sin(i * 2.0 * Math.PI / expCount));
+                               float zFinal = z + dz;
+
+                               final Explosion3D explosion = new 
Explosion3D(x * SCALE, y * SCALE,
+                                               z * SCALE, color);
+                               scenarioExplosions.add(explosion);
+
+                               final Timeline expTimeline = new 
Timeline(explosion);
+                               expTimeline.addPropertyToInterpolate("alpha", 
1.0f, 0.0f);
+                               expTimeline.addPropertyToInterpolate("x", x * 
SCALE, xFinal
+                                               * SCALE);
+                               expTimeline.addPropertyToInterpolate("y", y * 
SCALE, yFinal
+                                               * SCALE);
+//                             expTimeline.addPropertyToInterpolate("z", z * 
SCALE, zFinal
+//                                             * SCALE);
+                               expTimeline.addCallback(new 
TimelineCallbackAdapter() {
+                                       @Override
+                                       public void onTimelinePulse(float 
durationFraction,
+                                                       float 
timelinePosition) {
+                                               float t = 
expTimeline.getTimelinePosition();
+                                               float zCurr = (z + dz * t - 
10 * t * t) * SCALE;
+                                               explosion.setZ(zCurr);
+                                       }
+                               });
+                               expTimeline.setDuration(3000);
+
+                               expTimeline.addCallback(new 
TimelineCallbackAdapter() {
+                                       @Override
+                                       public void 
onTimelineStateChanged(TimelineState oldState,
+                                                       TimelineState 
newState, float durationFraction,
+                                                       float 
timelinePosition) {
+                                               if (newState == 
TimelineState.PLAYING_FORWARD) {
+                                                       
mainSceneGroup.addChild(explosion
+                                                                       
.getSphere3DBranchGroup());
+                                               }
+                                       }
+                               });
+
+                               scenario.addScenarioActor(expTimeline);
+                       }
+               }
+
+               synchronized (explosions) {
+                       explosions.put(scenario, scenarioExplosions);
+               }
+               scenario.addCallback(new TimelineScenarioCallback() {
+                       @Override
+                       public void onTimelineScenarioDone() {
+                               synchronized (explosions) {
+                                       Set<Explosion3D> ended = 
explosions.remove(scenario);
+                                       for (Explosion3D end : ended) {
+                                               mainSceneGroup
+                                                               
.removeChild(end.getSphere3DBranchGroup());
+                                       }
+                               }
+                       }
+               });
+               scenario.play();
+       }
+}
Index: src/org/pushingpixels/marble/Explosion3D.java
===================================================================
--- src/org/pushingpixels/marble/Explosion3D.java       (revision 0)
+++ src/org/pushingpixels/marble/Explosion3D.java       (revision 1)
@@ -0,0 +1,104 @@
+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;
+       }
+}
\ No newline at end of file





[marble~source:1] First check in

kirillg 07/03/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close