Download description

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Celtic 3D world study
Luís Manuel Borges Gouveia
A first prototype for Celtic information visualisation part I support, is showed in the
following pictures. The 3D world, with four spheres was implemented with a Java 3D
program and demonstrate:

the spheres rendering, its materials and apearance;

the objects position into the 3D space;

the use of light souces

the use of transformations;

the use of sensors;

the use of behaviours and interpolators;

the use of this Java API to control the user point of view in the world, using the
mouse.
The source code is given at the end of this document. Four screenshots of a four spheres
world are given. Note that the differencies between these images result from mouse
movements.
initial position
using mouse zoom (middle button)
later after some mouse moves…
a move with the first mouse bottom…
/*
* Adapted from Sun program SpinMouse.java 1.6 98/04/13 14:29:24
* LMBG April 99 - Use of mouse to control user position on a 3D
* scene with four spheres
*
*/
import
import
import
import
import
import
import
import
import
import
//
//
//
java.applet.Applet;
java.awt.BorderLayout;
java.awt.Frame;
java.awt.event.*;
com.sun.j3d.utils.applet.MainFrame;
com.sun.j3d.utils.geometry.*;
com.sun.j3d.utils.universe.*;
com.sun.j3d.utils.behaviors.mouse.*;
javax.media.j3d.*;
javax.vecmath.*;
MouseRotate, MouseZoom, and MouseTranslate objects
(Convenience library) turn possible to use the mouse
to interactively control the transformations in the scene
public class SpinMouse extends Applet {
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
createLights (objRoot);
Appearance[] materials = new Appearance[4];
createMaterials (materials);
Transform3D moveAway = new Transform3D();
moveAway.setTranslation (new Vector3f(0.0f, 0.0f, -1.2f));
TransformGroup moveAwayGroup = new TransformGroup(moveAway);
//
Transform node for mouse controlled transformations
TransformGroup mouseGroup = new TransformGroup();
mouseGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
mouseGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
//
//
//
Spin, zoom, and translate behavior nodes
actions are hardwired in the Convenience library
to the first, second, and third mouse buttons.
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
MouseRotate behavior1 = new MouseRotate(mouseGroup);
mouseGroup.addChild(behavior1);
behavior1.setSchedulingBounds(bounds);
MouseZoom behavior2 = new MouseZoom(mouseGroup);
mouseGroup.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
MouseTranslate behavior3 = new MouseTranslate(mouseGroup);
mouseGroup.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);
addShape (mouseGroup, new Vector3f(-0.5f, -0.5f, 0.0f),
new Sphere(0.6f, materials[0]));
addShape (mouseGroup, new Vector3f(-0.5f, 0.5f, 0.0f),
new Sphere(0.75f, materials[1]));
addShape (mouseGroup, new Vector3f(0.5f, 0.5f, 0.0f),
new Sphere(0.45f, materials[2]));
addShape (mouseGroup, new Vector3f(0.5f, -0.5f, 0.0f),
new Sphere(0.5f, materials[3]));
// Add mouse behavior subgraph to entire scene graph
objRoot.addChild(moveAwayGroup);
moveAwayGroup.addChild(mouseGroup);
// Java 3D optimization on the scene graph.
objRoot.compile();
return objRoot;
}
private void
createLights(BranchGroup graphRoot) {
// Create a bounds for the light source influence
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
// Set up the global, ambient light
Color3f alColor = new Color3f(0.6f, 0.6f, 0.6f);
AmbientLight aLgt = new AmbientLight(alColor);
aLgt.setInfluencingBounds(bounds);
graphRoot.addChild(aLgt);
// Set up the directional (infinite) light source
Color3f lColor1 = new Color3f(0.6f, 0.6f, 0.6f);
Vector3f lDir1 = new Vector3f(1.0f, 0.0f, 0.0f);
DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
lgt1.setInfluencingBounds(bounds);
// Automatically spin the light source.
TransformGroup spinTrans = new TransformGroup();
spinTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
spinTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Transform3D rAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(1, Alpha.INCREASING_ENABLE,
0, 0,
5000, 0, 0,
0, 0, 0);
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, spinTrans, rAxis,
0.0f, (float) Math.PI*2.0f);
rotator.setSchedulingBounds(bounds);
graphRoot.addChild(spinTrans);
spinTrans.addChild(rotator);
spinTrans.addChild(lgt1);
}
// Create four appearance objects, with different materials.
private void createMaterials(Appearance[] mats) {
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f deepRed = new Color3f(0.9f, 0.2f, 0.1f);
Color3f royalBlue = new Color3f(0.1f, 0.3f, 0.9f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
for (int i = 0; i < 4; i++) {
mats[i] = new Appearance();
}
mats[0].setMaterial(new Material(deepRed, black,
deepRed, black, 1.0f));
mats[1].setMaterial(new Material(royalBlue, black,
royalBlue, black, 1.0f));
mats[2].setMaterial(new Material(deepRed, black,
deepRed, white, 25.0f));
mats[3].setMaterial(new Material(royalBlue, black,
royalBlue, white, 25.0f));
}
//
The addShape() method puts a Shape3D node into the scene graph.
private void addShape(TransformGroup parent,
Vector3f tr, Primitive groupNode) {
Transform3D t = new Transform3D();
t.set (tr);
// Shrink the objects in order to the user see them all.
t.setScale(0.4);
TransformGroup newTrans = new TransformGroup(t);
parent.addChild(newTrans);
newTrans.addChild(groupNode);
}
public SpinMouse() {
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D(null);
add("Center", c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
// enable the java applet to be used also as an application
public static void main(String[] args) {
Frame frame = new MainFrame(new SpinMouse(), 256, 256);
}
}