以下代码将一个多维数据集放置在 (0, 0, 0) 处,另一个放置在 (0, .5, .5) 处,每个多维数据集的维度为 (.5, .5, .5)。我正在尝试将屏幕的视图旋转到这样的视图,但我得到了这个视图
。另外,我意识到我把颜色弄反了。
无论如何,这是我到目前为止的代码:
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();
}
}
所以现在画布是黑色的,我想这可能是我在lookAt函数上的定位。我也不确定向上向量的用途。有想法该怎么解决这个吗?