下面列出了怎么用javafx.scene.shape.Shape3D的API类实例代码及写法,或者点击链接到github查看源代码。
public void setXYZData(List<Double> xData, List<Double> yData, List<Double> zData, List<Color> colors) {
xAxisData = xData;
yAxisData = yData;
zAxisData = zData;
scatterDataGroup.getChildren().clear();
//for now we will always default to x axis
//later we could maybe dynamically determine the smallest axis and then
//uses 0's for the other axes that are larger.
for(int i=0;i<xAxisData.size();i++) {
final Shape3D dataSphere = createDefaultNode(nodeRadius);
double translateY = 0.0;
double translateZ = 0.0;
if(!yAxisData.isEmpty() && yAxisData.size() > i)
translateY = yAxisData.get(i);
if(!zAxisData.isEmpty() && zAxisData.size() > i)
translateZ = zAxisData.get(i);
dataSphere.setTranslateX(xAxisData.get(i));
dataSphere.setTranslateY(translateY);
dataSphere.setTranslateZ(translateZ);
dataSphere.setMaterial(new PhongMaterial(colors.get(i)));
scatterDataGroup.getChildren().add(dataSphere);
}
}
private Shape3D createDefaultNode(double radius) {
switch(defaultNodeType) {
case SPHERE: return new Sphere(radius);
case CUBE: return new Box(radius, radius, radius);
default: return new Box(radius, radius, radius);
}
}
/**
* Updates the transformation matrix.
* can change the Translate for fixed distance
*/
default void updateMatrix(){
Transform cam = getOther().getLocalToSceneTransform(),
self = getBillboardNode().getLocalToSceneTransform();
Bounds b;
double cX,
cY,
cZ;
if(!(getBillboardNode() instanceof Shape3D)){
b = getBillboardNode().getBoundsInLocal();
cX = b.getWidth() / 2;
cY = b.getHeight() / 2;
cZ = b.getDepth() / 2;
}else{
cX = self.getTx();
cY = self.getTy();
cZ = self.getTz();
}
Point3D camPos = new Point3D(cam.getTx(), cam.getTy(), cam.getTz());
Point3D selfPos = new Point3D(cX, cY, cZ);
Vector3D up = Vector3D.UP,
forward = new Vector3D(
(selfPos.getX()) - camPos.getX(),
(selfPos.getY()) - camPos.getY(),
(selfPos.getZ()) - camPos.getZ()
).toNormal(),
right = up.crossProduct(forward).toNormal();
up = forward.crossProduct(right).toNormal();
switch(getBillboardMode()){
case SPHERICAL:
affine.setMxx(right.x); affine.setMxy(up.x); affine.setMzx(forward.x);
affine.setMyx(right.y); affine.setMyy(up.y); affine.setMzy(forward.y);
affine.setMzx(right.z); affine.setMzy(up.z); affine.setMzz(forward.z);
affine.setTx(cX * (1 - affine.getMxx()) - cY * affine.getMxy() - cZ * affine.getMxz());
affine.setTy(cY * (1 - affine.getMyy()) - cX * affine.getMyx() - cZ * affine.getMyz());
affine.setTz(cZ * (1 - affine.getMzz()) - cX * affine.getMzx() - cY * affine.getMzy());
break;
case CYLINDRICAL:
affine.setMxx(right.x); affine.setMxy(0); affine.setMzx(forward.x);
affine.setMyx(0); affine.setMyy(1); affine.setMzy(0);
affine.setMzx(right.z); affine.setMzy(0); affine.setMzz(forward.z);
affine.setTx(cX * (1 - affine.getMxx()) - cY * affine.getMxy() - cZ * affine.getMxz());
affine.setTy(cY * (1 - affine.getMyy()) - cX * affine.getMyx() - cZ * affine.getMyz());
affine.setTz(cZ * (1 - affine.getMzz()) - cX * affine.getMzx() - cY * affine.getMzy());
break;
}
}