我需要将相机绕轴旋转一定程度。怎么能实现呢?我无法制定计算新lookX,lookY,lookZ的公式。我将非常感谢你的帮助!
Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
视频以防万一:Video
答案 0 :(得分:0)
所以,解决方案是:
float deltaZ = 4; // for example 4, it can be any number
oglr.angleX += (downX-x)/10;
oglr.angleY += (y-downY)/10;
if (oglr.angleX > 90 && oglr.angleX < 270) oglr.lookZ = oglr.eyeZ + deltaZ;
else oglr.lookZ = oglr.eyeZ - deltaZ;
if (oglr.angleX < 0) oglr.angleX = 360+oglr.angleX;
if (oglr.angleX > 360) oglr.angleX = oglr.angleX%360;
oglr.lookX = oglr.eyeZ > oglr.lookZ ? (float)Math.tan(Math.toRadians(oglr.angleX))*(oglr.eyeZ-oglr.lookZ) + oglr.eyeX : (float)Math.tan(Math.toRadians(oglr.angleX-180))*(oglr.eyeZ-oglr.lookZ) + oglr.eyeX;
oglr.lookY = (float)Math.tan(Math.toRadians(oglr.angleY))*(Math.abs(oglr.eyeZ-oglr.lookZ)) + oglr.eyeY;
downX = x;
downY = y;
注意:oglr - OpenGLRenderer; x,y - MotionEvent.getX()和getY()