“添加”两个角度
好吧,所以我有两个角度。一是操纵杆的角度,二是摄像机与玩家的角度。相机的角度。现在我想要它,所以当我按下操纵杆时,它会将玩家移离摄像机。我该怎么做?在 Java 或 Ardor3d 中是否有一种简单的方法可以做到这一点?
编辑:这是我如何获取角度的代码。
float camDegree = (float) Math.toDegrees(Math.atan2(
_canvas.getCanvasRenderer().getCamera().getLocation().getXf() - colladaNode.getTranslation().getXf(),
_canvas.getCanvasRenderer().getCamera().getLocation().getYf()) - colladaNode.getTranslation().getYf());
player.angle = (float) Math.toDegrees(Math.atan2(padX, padY));
Quaternion camQ = new Quaternion().fromAngleAxis(camDegree, Vector3.UNIT_Y);
Alright, so I got two angles. One is the joystick's angle, and the other is the camera to player angle. The camera's angle. Now I want it so when I press up on the joystick it moves the player away from the camera. How would I do this? And is there a easy way to do it in Java or Ardor3d?
edit: Here is the code of how I get my angles.
float camDegree = (float) Math.toDegrees(Math.atan2(
_canvas.getCanvasRenderer().getCamera().getLocation().getXf() - colladaNode.getTranslation().getXf(),
_canvas.getCanvasRenderer().getCamera().getLocation().getYf()) - colladaNode.getTranslation().getYf());
player.angle = (float) Math.toDegrees(Math.atan2(padX, padY));
Quaternion camQ = new Quaternion().fromAngleAxis(camDegree, Vector3.UNIT_Y);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不得不说,我不太明白你的问题,但它似乎是关于如何使用操纵杆实现与相机相关的控制。
我能给你的最重要的建议是,最好不要计算角度,而是直接使用向量。
假设相机朝 v 方向看(在某些类型的游戏中,该向量将直接指向玩家,但并非所有类型的游戏,且并非总是如此):
通常您不关心该向量的垂直分量,因此,删除它以获得水平分量,我将其称为 y ,原因稍后会变得显而易见:
其中向上 是垂直向上的单位向量。
我们可以使用叉积找到垂直于 y 的水平向量(并记住右手定则):
现在您可以看到 y 是平面中指向前方(远离相机)的向量,而 x 是指向右侧的平面(相对于相机的侧面)。如果对这些向量进行归一化:
那么您可以使用x̂和ŷ作为玩家相对于相机运动的坐标基础。如果您的操纵杆读数为 Jx 和 Jy,则将玩家移动
其中 s 是与玩家速度成正比的适当标量值。
(请注意,此答案中的任何一点都没有计算角度!)
I have to say that I don't really understand your question, but it seems to be about how to implement camera-relative control using a joystick.
The most important piece of advice I can give you is that it's better not to compute angles, but to work directly with vectors.
Suppose that the camera is looking in the direction v (in some types of game this vector will be pointing directly at the player, but not all types of game, and not always):
Typically you don't care about the vertical component of this vector, so remove it to get the horizontal component, which I'll call y for reasons that will become apparent later:
where up is a unit vector pointing vertically upwards.
We can find the horizontal vector that's perpendicular to y using the cross product (and remembering the right hand rule):
Now you can see that y is a vector in the plane pointing forwards (away from the camera), and x a vector in the plane pointing right (sideway with respect to the camera). If you normalise these vectors:
then you can use x̂ and ŷ as the coordinate basis for camera-relative motion of the player. If your joystick readings are Jx and Jy, then move the player by
where s is an appropriate scalar value proportional to the player's speed.
(Notice that no angles were computed at any point in this answer!)