【发布时间】:2015-05-29 21:30:38
【问题描述】:
我一直试图让一个物体绕另一个物体运行:
//childX,childY,childZ are my starting coordinates
//here I count distance to the middle of my coordinate plane
float r = (float) Math.sqrt(Math.pow(childX, 2)+Math.pow(childY, 2)+Math.pow(childZ,2));
//here i convert my angles to radians
float alphaToRad = (float) Math.toRadians(findParent(figure.parentId).rotate[1]);//up_down
float betaToRad = (float) Math.toRadians(findParent(figure.parentId).rotate[0]);//left_right
float newX = (float) (r*Math.cos(betaToRad)*Math.cos(alphaToRad));
float newY = (float) (r*Math.cos(betaToRad)*Math.sin(alphaToRad));
float newZ = (float) (r*Math.sin(betaToRad));'
我有起点坐标 (5,5,0) 和角度 0° 和 0°,因此这意味着在计算新坐标后坐标不应改变。但结果是:
newX: 7.071068 newY: 0.0 newZ: 0.0
我尝试计算新坐标的每一种方法总是有这个奇怪的结果。那是什么 7.07,我怎样才能得到正确的结果?
@编辑
为了使我的新点相对于旧点,我只是将旧点的角度添加到新点:
float alphaToRad = (float) Math.toRadians(findParent(figure.parentId).rotate[1]) + Math.atan(childY/childX);
float betaToRad = (float) Math.toRadians(findParent(figure.parentId).rotate[0]) + Math.asin(childZ/r);
现在一切正常。解决了
【问题讨论】:
标签: opengl rotation jogl coordinate orbit