OpenGL第三人称相机无法正确组合轴

时间:2014-10-18 21:47:18

标签: java opengl 3d

我尝试在OpenGL中实现第三人称相机,似乎差不多完成了。我可以围绕y轴和x+z轴旋转。但是当我同时尝试这两个时它看起来不太好,因为他不再看物体了。你能弄清楚错误在哪里吗?下面是代码:

glTranslatef(world.player.x-4.5f,world.player.y-4.5f,world.player.z-20f-4.5f);

modelHandler.modelList.get("TEST").render();

double camerax = 20 * Math.cos((world.player.getYaw() + 270.0f) * Math.PI / 180) * Math.cos(Math.toRadians(world.player.getPitch())) + world.player.x;
double cameray = 20 * Math.sin((world.player.getPitch()) * Math.PI / 180) + world.player.y;
double cameraz = 20 * Math.sin((world.player.getYaw() - 270.0f) * Math.PI / 180) * Math.cos(Math.toRadians(world.player.getPitch())) + world.player.z-20;


glRotatef(360.0f - world.player.getYaw(), 0.0f, 1.0f, 0.0f);
glRotatef(world.player.getPitch() * (float)Math.cos(Math.toRadians(360.0f - world.player.getYaw())), 1.0f, 0.0f, 0.0f);
glRotatef(world.player.getPitch() * (float)Math.sin(Math.toRadians(360.0f - world.player.getYaw())), 0.0f, 0.0f, 1.0f);
glTranslated(-camerax, -cameray, -cameraz);

// render world and stuff

0 个答案:

没有答案