比方說,我有一個如下的數據結構:基本渲染3D透視投影到二維的屏幕,攝像頭(無OpenGL的)
Camera {
double x, y, z
/** ideally the camera angle is positioned to aim at the 0,0,0 point */
double angleX, angleY, angleZ;
}
SomePointIn3DSpace {
double x, y, z
}
ScreenData {
/** Convert from some point 3d space to 2d space, end up with x, y */
int x_screenPositionOfPt, y_screenPositionOfPt
double zFar = 100;
int width=640, height=480
}
...
沒有屏幕剪輯或別的東西也不多,我將如何計算給定空間中某個3d點的某個點的屏幕x,y位置。我想把這個3d點投影到2D屏幕上。
Camera.x = 0
Camera.y = 10;
Camera.z = -10;
/** ideally, I want the camera to point at the ground at 3d space 0,0,0 */
Camera.angleX = ???;
Camera.angleY = ????
Camera.angleZ = ????;
SomePointIn3DSpace.x = 5;
SomePointIn3DSpace.y = 5;
SomePointIn3DSpace.z = 5;
ScreenData.x和y是空間中3d點的屏幕x位置。我如何計算這些值?
我可以使用這裏找到的公式,但我不明白屏幕寬度/高度是如何起作用的。另外,我不明白在wiki條目中觀衆對相機位置的位置。
http://en.wikipedia.org/wiki/3D_projection
長而偉大的答案,值得讚賞! – Gepsens 2012-01-06 16:06:22