我有一个场景基本上是一个15x15的方形楼层(四边形坐标(0,0,0)(0,0,15)(15,0,15)(15,0,0))。
我将场景中心设置为(7.5,0,7.5)。 问题是我无法弄清楚如何围绕该场景中心水平旋转相机(也就是让相机在场景中心周围做360度水平圆)。 我知道你需要用罪和cos做点什么,但不知道到底是什么。
这是代码(普通C):
//set camera position //camera height is 17 GLfloat camx=0, camy=17, camz=0; //set center of scene GLfloat xref=7.5, yref=0, zref=7.5; gluLookAt(camx, camy, camz, xref, yref, zref, 0, 1, 0); //projection is standard gluPerspective, nothing special gluPerspective(45, (GLdouble)width/(GLdouble)height, 1, 1000);I have a scene which is basically a square floor measuring 15x15 (a quad with coordinates (0,0,0) (0,0,15) (15,0,15) (15,0,0) ).
I 've set the center-of-scene to be at (7.5,0,7.5). Problem is I can't figure out how to rotate the camera horizontally around that center of scene (aka make the camera do a 360 horizontal circle around center-of-scene). I know you need to do something with sin and cos, but don't know what exactly.
Here is the code (plain C):
//set camera position //camera height is 17 GLfloat camx=0, camy=17, camz=0; //set center of scene GLfloat xref=7.5, yref=0, zref=7.5; gluLookAt(camx, camy, camz, xref, yref, zref, 0, 1, 0); //projection is standard gluPerspective, nothing special gluPerspective(45, (GLdouble)width/(GLdouble)height, 1, 1000);最满意答案
您需要修改camx和camz变量。
你想要穿过的点位于圆上,它们的坐标由x = r*sin(alpha) + 7.5, z = r*cos(alpha) + 7,5 ,其中r是圆的半径, alpha是xy平面与相机当前位置之间的角度。
当然,角度取决于旋转速度以及从动画开始的时间。 基本上,您唯一需要做的就是设置正确的角度,然后根据上面的表达式计算坐标。
有关圆坐标的更多信息,请参阅Wiki: http : //en.wikipedia.org/wiki/Unit_circle
You need to modify the camx and camz variables.
The points you want to walk through lie on the circle and their coordinates are determined by x = r*sin(alpha) + 7.5, z = r*cos(alpha) + 7,5, where r is the radius of the circle and alpha is the angle between xy plane and the current position of your camera.
Of course the angle depends on the rotation speed and also on the time from the beginning of the animation. Basically, the only thing you need to do is to set the right angle and then calculate the coordinates from the expressions above.
For more info about the circle coordinates, see Wiki : http://en.wikipedia.org/wiki/Unit_circle
更多推荐
发布评论