View Javadoc

1   /*
2    * @(#) BallAnimation3D.java May 10, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.tutorial.section44;
11  
12  import java.awt.Color;
13  import java.util.Enumeration;
14  
15  import javax.media.j3d.Appearance;
16  import javax.media.j3d.Material;
17  import javax.media.j3d.Node;
18  import javax.media.j3d.TransformGroup;
19  import javax.vecmath.Color3f;
20  
21  import nl.tudelft.simulation.dsol.animation.LocatableInterface;
22  import nl.tudelft.simulation.dsol.animation.D3.Renderable3D;
23  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
24  
25  import com.sun.j3d.utils.geometry.Sphere;
26  
27  /***
28   * BallAnimation3D, animation of a ball in 3D <br>
29   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
30   * University of Technology </a>, the Netherlands. <br>
31   * See for project information <a
32   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
33   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
34   * License (GPL) </a>, no warranty <br>
35   * 
36   * @version 1.0 10.05.2004 <br>
37   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
38   *         </a>
39   */
40  public class BallAnimation3D extends Renderable3D
41  {
42  	/***
43  	 * constructs a new BallAnimation3D
44  	 * 
45  	 * @param source the source
46  	 * @param simulator the simulator
47  	 */
48  	public BallAnimation3D(final LocatableInterface source,
49  			final SimulatorInterface simulator)
50  	{
51  		super(source, simulator);
52  	}
53  
54  	/***
55  	 * provides the model for the animationObject
56  	 * 
57  	 * @param locationGroup
58  	 */
59  	public void provideModel(final TransformGroup locationGroup)
60  	{
61  		this.setScale(0.1d);
62  
63  		// ----------------
64  		// The shape itself
65  		Appearance app = new Appearance();
66  
67  		// Create colors for the material
68  		Color3f ambientColor = new Color3f(Color.ORANGE);
69  		Color3f diffuseColor = new Color3f(Color.ORANGE);
70  
71  		Color3f specularColor = new Color3f(Color.WHITE);
72  		Color3f emissiveColor = new Color3f(Color.orange);
73  
74  		// Define shininess
75  		float shininess = 10.0f;
76  		// Set material
77  		app.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor,
78  				specularColor, shininess));
79  		// Create a ball
80  		Node model = new Sphere(5f * (float) this.scale, app);
81  
82  		//Node model = new ColorCube(0.4);
83  
84  		// ---------------
85  		// Put it together
86  		locationGroup.addChild(model);
87  	}
88  
89  	/***
90  	 * updates the animation of this object
91  	 * 
92  	 * @param children the children to update
93  	 */
94  	protected void update(Enumeration children)
95  	{
96  		// Do nothing
97  	}
98  }