简体   繁体   English

opengl相机围绕对象旋转

[英]opengl camera rotation around object

I'm fighting with the code, to make it rotate camera around the object. 我正在与代码战斗,以使其围绕对象旋转相机。 The code that I'm using is: 我正在使用的代码是:

eyeX = (float) (obj.x + 500*Math.cos(Math.toRadians(angle))*Math.sin(Math.toRadians(angle))); eyeY = (float) (obj.y + 500*Math.sin(Math.toRadians(angle))*Math.sin(Math.toRadians(angle))); eyeZ = (float) (obj.z + 500*Math.cos(Math.toRadians(angle))); Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, obj.x, obj.y, obj.z, 0, 1, 0);

Where obj is the model I want to rotate the camera around, and angle is incremented by 1 with every draw. 其中obj是我要旋转相机的模型,每次绘制时角度都增加1。 Can somebody shed a light to this problem, what I'm doing wrong? 有人可以阐明这个问题吗,我做错了什么?

What exact camera motion are you trying to achieve? 您要达到什么精确的摄像机运动? If you want to turn around obj on the XZ plane while remaining at a constant height, you should do: 如果要在XZ平面上绕转obj并保持恒定高度,则应该执行以下操作:

eyeX = (float)(obj.x + 500*Math.cos(Math.toRadians(angle)); eyeX =(float)(obj.x + 500 * Math.cos(Math.toRadians(angle));

eyeY = (float)(y0); eyeY =(float)(y0); //constant height //恒定高度

eyeZ = (float)(obj.z + 500*Math.sin(Math.toRadians(angle)); eyeZ =(float)(obj.z + 500 * Math.sin(Math.toRadians(angle));

Also, if y0 != 0, then (0, 1, 0) is not a proper "up" vector and will distort you view. 另外,如果y0!= 0,则(0,1,0)不是正确的“向上”向量,会使您的视线变形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM