Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
setting the view
I am using the SimpleUniverse and want to set the view to (0, 2, 2) such that the "eye position" is 2meters up the Y axis and 2 meters up the z axis. However, no matter what values I put in the vector, only the Z axis seems to be changed. Thus, I seem to only be able to move closer or farther away from the origin. Here is my code snipet:
mainScene = createSceneGraph();
u = new SimpleUniverse(c);
ViewingPlatform viewingPlatform = u.getViewingPlatform();
TransformGroup vpTrans = viewingPlatform.getViewPlatformTransform();
Transform3D transform = new Transform3D();
Vector3f translate = new Vector3f(0.0f, 2.0f, 2.0f);
transform.setTranslation(translate);
vpTrans.setTransform(transform);
The object I am viewing is a room, and right now my "eye level" is on the floor. Can anyone tell me what I am doing wrong?
mainScene = createSceneGraph();
u = new SimpleUniverse(c);
ViewingPlatform viewingPlatform = u.getViewingPlatform();
TransformGroup vpTrans = viewingPlatform.getViewPlatformTransform();
Transform3D transform = new Transform3D();
Vector3f translate = new Vector3f(0.0f, 2.0f, 2.0f);
transform.setTranslation(translate);
vpTrans.setTransform(transform);
The object I am viewing is a room, and right now my "eye level" is on the floor. Can anyone tell me what I am doing wrong?
Comments
-
Unfortunately you are one of the many people who needs help in understanding how the ViewPlatform works. As far as i can tell your code should work.
I am having similar problems.
Anyone know how to do collision detection with the boundary of the viewer?
Code would be most helpful. -
Three things.
(1) You HAVE to read the first few chapters of Sun's Java 3D API Tutorial before doing anything else.
http://java.sun.com/products/java-media/3D/collateral
(2) Start using VirtualUniverse, not SimpleUniverse, using Sun's simple recipe and first Scene Graph Illustation in the tutorial; it is not that much harder to use.
(3) Here is a program that uses VirtualUniverse, moves the view back from 0,0,0 along the Z axis so more of a large object can be seen, and enables the scene to be rotated and moved along the Z axis with the mouse (hold the left button to rotate or Alt+Left Mouse Button to zoom.
HelloVirtualUniverse.java
-------------------------
package wrs9jd.java3D;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
import com.sun.j3d.utils.behaviors.mouse.*;
public class HelloVirtualUniverse extends java.applet.Applet {
VirtualUniverse u = null;
public HelloVirtualUniverse() {}
public BranchGroup createSceneGraph() {
// The transform group will allow the scene to be rotated and zoomed in/out on.
BranchGroup objRoot = new BranchGroup();
TransformGroup objTrans = new TransformGroup();
// Set these capability bits so the behaviors below will work.
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
// Add a behavior so the scene can be rotated (hold the left mouse button).
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(objTrans);
objTrans.addChild(behavior);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10000.0);
behavior.setSchedulingBounds(bounds);
// Add a behavior to zoom in/out (hold down Alt and the left mouse button).
MouseZoom behavior2 = new MouseZoom();
behavior2.setTransformGroup(objTrans);
objTrans.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
// Add the root transform group to the root of the scene.
objRoot.addChild(objTrans);
// Now, add any number of TransformGroup-Shape3D pairs.
objTrans.addChild(new ColorCube(1.2));
// Return the scene graph.
return objRoot;
}
/**
* This method follows Sun's basic recipe for writing a Java3D program
* as given in the Java3D tutorial.
*/
public BranchGroup createViewBranchGraph(Canvas3D c) {
// Create a view object.
View v = new View();
// Create a ViewPlatform object.
ViewPlatform vp = new ViewPlatform();
// Create a PhysicalBody object.
PhysicalBody pb = new PhysicalBody();
// Create a PhysicalEnvironment object.
PhysicalEnvironment pe = new PhysicalEnvironment();
// Attach ViewPlatform, PhysicalBody, PhysicalEnvironment, and Canvas3D objects to View object.
v.attachViewPlatform(vp);
v.setPhysicalBody(pb);
v.setPhysicalEnvironment(pe);
v.addCanvas3D(c);
// Now, construct the view branch graph.
BranchGroup bg = new BranchGroup();
Transform3D trans3D = new Transform3D();
trans3D.lookAt(new Point3d(0,0,30.0), new Point3d(0,0,0), new Vector3d(0,1,0));
trans3D.invert();
TransformGroup tg = new TransformGroup(trans3D);
bg.addChild(tg);
tg.addChild(vp);
// Return the BranchGroup.
return bg;
}
public void destroy() {
u.removeAllLocales();
}
/**
* This method follows Sun's basic recipe for writing a Java3D program
* as given in the Java3D tutorial.
*/
public void init() {
// Create a Canvas3D object.
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
// Create a VirtualUniverse object.
u = new VirtualUniverse();
// Create a Locale object, attaching it to the VirtualUniverse object.
Locale locale = new Locale(u);
// Construct a view branch graph.
BranchGroup view = createViewBranchGraph(c);
// Construct content branch graph(s).
BranchGroup scene = createSceneGraph();
// Compile branch graph(s).
scene.compile();
view.compile();
// Insert subgraphs into the Locale (also making them live).
locale.addBranchGraph(scene);
locale.addBranchGraph(view);
}
public static void main(String[] args) {
new MainFrame(new HelloVirtualUniverse(), 512, 512);
}
}
-
Using virtual universe isn't nessisary, i've moved the view around as i wanted with a simple universe reasonably easily... but it's been a while so i've forgotten exactly how it's done. I'll have a look around for the code..
This discussion has been closed.