The following code puts a cube at (0, 0, 0) and another at (0, .5, .5) and each cube is (.5, .5, .5) in dimension. I'm trying to rotate the view that the screen gets to one like this but instead I get this view . Also, I realize I got the colors backwards.
Anyway, this is my code so far:
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 right now the canvas is black and I think it might be my positioning on the lookAt function. I'm also not exactly for sure what the up vector is for. Any ideas on how to fix this?