|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectProGAL.geom3d.viewer.J3DScene
public class J3DScene
A graphics class for viewing scenes using Java3D.
All the Shape
-subclasses specified in the edu.geom3D
package can be added to a J3DScene
object and are automatically
painted on a Canvas3D
object. For
instance the following code creates a scene with a cylinder and a red
transparent box and adds the canvas to a frame.
J3DScene scene = new J3DScene(); scene.addShape( new Cylinder(new Vector(1,0,0), new Vector(0.5,0.5, 0.3), 0.1f) ); Vector boxCorner = new Vector(-1,0,0); Vector[] boxBases = {new Vector(1,0,0), new Vector(0,1,0), new Vector(0,0,1)}; float[] boxExtents = {0.8f, 1, 2}; Box box = new Box( boxCorner, boxBases, boxExtents ); scene.addShape( box, new Color(200,0,0,100) ); Canvas3D canvas = scene.getCanvas(); JFrame frame = new JFrame(); frame.setSize(400,400); frame.getContentPane().add( canvas ); frame.setVisible(true);Text can be added to the scene as well and will always face the camera. The
repaint()
method must be called every time the position of
shapes has changed and the canvas should be updated. The pointers
to added shapes are stored, so subsequent changes in the box
object in the above code will be visible on the canvas when repaint()
is called. The following example shows how to animate a sphere rotating around origo.
J3DScene scene = new J3DScene(); Sphere sphere = new Sphere( new Vector(1,0,0), 0.1f); scene.addShape(sphere); float t = 0; while(true){ t+=0.01f; sphere.center = new Vector(Math.cos(t), Math.sin(t), 0); scene.repaint(); try{ Thread.sleep(30); }catch(InterruptedException exc){} }A static method is supplied for conveniently creating a frame containing a scene-viewer. The following example shows how to quickly create a
J3DScene
object
that is shown in a frame and ready for use:
J3DScene scene = J3DScene.createJ3DSceneInFrame(); scene.setAxisEnabled(true); scene.addShape( new Cylinder(new Vector(1,0,0), new Vector0,1,0), 0.1f) );
Field Summary | |
---|---|
javax.swing.JFrame |
frame
|
Constructor Summary | |
---|---|
J3DScene()
|
Method Summary | |
---|---|
void |
addClickListener(ClickListener cl)
Add a click-listener that gets called every time an object or the background is clicked |
void |
addShape(Shape v)
Add a volume object. |
void |
addShape(Shape v,
java.awt.Color c)
Add a volume object with a specified color |
void |
addShape(Shape v,
java.awt.Color c,
int divisions)
Add a volume object with a specified color and detail-level |
void |
addSurface(ParametricSurface surface)
|
void |
addSurface(ParametricSurface surface,
java.awt.Color col)
|
void |
addSurface(ParametricSurface surface,
java.awt.Color col,
double uMin,
double uMax,
int uDivs,
double vMin,
double vMax,
int vDivs)
|
void |
addText(java.lang.String t,
Point pos)
Add a text-object at the specified position. |
void |
addText(java.lang.String t,
Point pos,
double height)
|
void |
addText(java.lang.String t,
Point pos,
double height,
java.awt.Color c)
|
void |
autoZoom()
Zooms such that the maximal distance between two objects is within the view |
void |
centerCamera()
Sets the location that the camera looks at to the center of all the shapes added to the scene. |
void |
centerCamera(Point newCenter)
|
static J3DScene |
createJ3DSceneInFrame()
Create a frame containing a canvas, display it and return the J3DScene object shown in the frame. |
Camera |
getCamera()
|
javax.media.j3d.Canvas3D |
getCanvas()
Get the canvas that displays the scene. |
java.util.List<ClickListener> |
getClickListeners()
|
static void |
main(java.lang.String[] args)
|
void |
removeAllShapes()
Remove all volumes from the scene. |
void |
removeShape(Shape v)
Removes one volume from the scene. |
void |
repaint()
Repaint the canvas. |
void |
repaintRepeatedly(long millisecondDelay)
Repaint the canvas repeatedly every millisecondDelay milliseconds. |
void |
setAntialiasing(boolean enabled)
|
void |
setAxisEnabled(boolean axisEnabled)
Enables or disables xyz-axis from the origo |
void |
setBackgroundColor(java.awt.Color c)
Set color of background. |
void |
setParallelProjection(boolean enabled)
Enables and disables parallel projection (as opposed to perspective projection). |
void |
toggleRotation()
Toggles rotation |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public javax.swing.JFrame frame
Constructor Detail |
---|
public J3DScene()
Method Detail |
---|
public void setBackgroundColor(java.awt.Color c)
public void removeShape(Shape v)
public void removeAllShapes()
public void addShape(Shape v)
public void addShape(Shape v, java.awt.Color c)
public void addShape(Shape v, java.awt.Color c, int divisions)
public void addText(java.lang.String t, Point pos)
public void addText(java.lang.String t, Point pos, double height)
public void addText(java.lang.String t, Point pos, double height, java.awt.Color c)
public void addSurface(ParametricSurface surface)
public void addSurface(ParametricSurface surface, java.awt.Color col)
public void addSurface(ParametricSurface surface, java.awt.Color col, double uMin, double uMax, int uDivs, double vMin, double vMax, int vDivs)
public void centerCamera()
public void centerCamera(Point newCenter)
public void autoZoom()
public void setParallelProjection(boolean enabled)
public void setAntialiasing(boolean enabled)
public void toggleRotation()
public void addClickListener(ClickListener cl)
cl
- public java.util.List<ClickListener> getClickListeners()
public void setAxisEnabled(boolean axisEnabled)
public Camera getCamera()
public javax.media.j3d.Canvas3D getCanvas()
Canvas3D
object will be returned
every time.
public void repaint()
repaint()
is called
and no sooner. If the scene is repeatedly changed, and repaint repeatedly
called the viewer will show an animation.
public void repaintRepeatedly(long millisecondDelay)
millisecondDelay
milliseconds.
public static J3DScene createJ3DSceneInFrame()
J3DScene.frame
field.
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |