Rotate the viewing platform in Java3d

The following code puts the cube in (0, 0, 0) and the other in (0, .5, .5), and each cube is (.5, .5, .5) in dimension. I'm trying to turn the idea that the screen is becoming like this good but instead i get this view alt text . In addition, I understand that I got the colors back.

Anyway, this is my code:

import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; public class Positioning { private Color3f lightBlue; private Color3f aquaGreen; private Color3f white; private Color3f teal; private BranchGroup group; private SimpleUniverse universe; public Positioning() { lightBlue = new Color3f(0.0f, 0.749019608f, 1.0f); aquaGreen = new Color3f(0.439215686f, 0.858823529f, 0.576470588f); white = new Color3f(1.0f, 1.0f, 1.0f); teal = new Color3f(0.196078431f, 0.6f, 0.8f); universe = new SimpleUniverse(); group = new BranchGroup(); addCube(0.5f, 0.5f, 0.5f, new Vector3f(0.0f, 0.0f, 0.0f), lightBlue); addCube(0.5f, 0.5f, 0.5f, new Vector3f(0.5f, 0.0f, 0.5f), aquaGreen); //add light DirectionalLight light1 = new DirectionalLight(white, new Vector3f(0.0f, 7.0f, -12.0f)); light1.setInfluencingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0)); group.addChild(light1); //look at the right spot Transform3D lookAt = new Transform3D(); lookAt.lookAt(new Point3d(0.0, 0.0, 3.0), new Point3d(0.0, 0.0, 0.0), new Vector3d(1.0, 1.0, 0.0)); lookAt.invert(); universe.getViewingPlatform().getViewPlatformTransform().setTransform(lookAt); universe.addBranchGraph(group); } public void addCube(float x, float y, float z, Vector3f position, Color3f color) { TransformGroup tg = new TransformGroup(); Transform3D trans = new Transform3D(); Appearance app = new Appearance(); Material mat = new Material(); mat.setDiffuseColor(color); mat.setSpecularColor(color); app.setMaterial(mat); Box b = new Box(x, y, z, app); //move into position and add to the branch group trans.setTranslation(position); tg.setTransform(trans); tg.addChild(b); group.addChild(tg); } public static void main(String[] args) { new Positioning(); } } 

So, now the canvas is black, and I think it could be my positioning in the lookAt function. I also do not know exactly what the vector is for. Any ideas on how to fix this?

+7
java rotation 3d java-3d
source share
1 answer

I am not familiar with Java, but usually you can customize the view matrix using some kind of "lookAt" function. A quick look at the documents came up with this one .

BTW, setNominalViewingTransform only translates along the z axis, so the screenshot shown is what I expect to see. You are right to try to customize the view transformation yourself.

Edit

As for the up direction for the lookAt function, this is just a way to control the camera roll. In other words, by specifying the viewpoint and the center point (the point the camera is looking at), you only determine the direction. The camera can still rotate on this axis 360 degrees. If you want to look at things correctly, then just point the vector in the up direction in your system - if it is y, then it will be (0,1,0). If you want to look at things upside down, it will be (0, -1.0).

Note that you do not have to check that the up vector is perpendicular to the direction defined by the eye and center. As long as it is not parallel to this direction, then the method should automatically use the component of your attached up vector, which is perpendicular to the direction.

Edit2:

Based on your changes, it looks like you put the position in place of “up” and not in the direction. It should be just a vector (0,1,0). Having said that, he still won’t fix your problem, because the wrong “up” vector means that the camera can turn around on its own axis so that it flips to its side, etc., but it won’t affect direction.

Therefore, there must be something wrong with the eye and center positions, or the matrix is ​​still not inverted. Your edit for invert() does not look right, since you did not call it on lookAt Transform3D , but I assume this is just a typo. when did you update the question?

I would try a simpler viewing angle to get you started. Just try looking along the z axis with something like

  Transform3D lookAt = new Transform3D(); lookAt.lookAt( new Point3d( 0.0, 0.0, 1.0 ) , new Point3d( 0.0, 0.0, 0.0 ) , new Vector3d( 0.0, 1.0, 0.0) ); lookAt.invert(); 

What is going on with this?

If you still get black, try moving the viewpoint along the z axis, maybe try 2.0, 3.0, and then a few negative values.

Another possibility is that your camera is looking in the right direction, but objects are selected due to clipping of a truncated cone. You might want to check the documentation to see why click planes are set by default. This may appear in the example above when you change the position of the eyes along the z axis. If you can see your objects for some z values, but not for others, this is probably a clipping problem.

Let me know how you are doing.

+4
source share

All Articles