我想知道是否有任何关于在Java中创建3D矩形的简单代码示例或指南,而不使用任何3D库(如Java3D或OpenGL)!
答案 0 :(得分:1)
3D矩形称为矩形棱镜。
定义3D形状并不是很困难。这是矩形棱镜的一个定义。
import java.awt.Graphics;
public class RectangularPrism {
protected Point3D originPoint;
protected Point3D xPoint;
protected Point3D yPoint;
protected Point3D zPoint;
public RectangularPrism() {
}
public RectangularPrism(Point3D originPoint, Point3D xPoint,
Point3D yPoint, Point3D zPoint) {
this.originPoint = originPoint;
this.xPoint = xPoint;
this.yPoint = yPoint;
this.zPoint = zPoint;
}
public void setOriginPoint(Point3D originPoint) {
this.originPoint = originPoint;
}
public void setxPoint(Point3D xPoint) {
this.xPoint = xPoint;
}
public void setyPoint(Point3D yPoint) {
this.yPoint = yPoint;
}
public void setzPoint(Point3D zPoint) {
this.zPoint = zPoint;
}
public void render(Graphics g, Point3D viewPoint) {
}
public class Point3D {
protected int x;
protected int y;
protected int z;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
}
它正在创建需要进行一些计算的渲染方法。对于您想要定义的每个3D形状,该计算都会有所不同。
你的调用例程必须弄清楚渲染所有3D形状的顺序。基本上,必须首先渲染最远的3D形状,以便更接近的3D形状正确重叠。
3D库不仅具有所有这一点,而且还进行了优化,以便可以在最短的时间内渲染3D场景。
答案 1 :(得分:0)
您可以使用java.awt.Graphics.draw3DRect()方法 http://www.java-examples.com/draw-3d-rectangle-square-applet-window-example
答案 2 :(得分:0)
我已经实现了简单的查看器,您可以在http://dl.dropbox.com/u/14767221/projection.7z
下载