'添加'两个角度 [英] 'adding' two angles

查看:125
本文介绍了'添加'两个角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有两个角度。一个是游戏杆的角度,另一个是玩家角度的相机。相机的角度。现在我想要它,所以当我按下操纵杆时,它会将播放器从相机移开。我将如何做到这一点?有没有一种简单的方法可以在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);


解决方案

我不得不说你的问题,但它似乎是关于如何使用操纵杆实现相机相对控制。



我可以给你的最重要的建议是,最好不要以计算角度,但直接与矢量。



假设相机正在朝 v 方向看(在某些类型的游戏中向量将直接指向玩家,但不是所有类型的游戏,而不是总是):



通常你不在意关于此向量的垂直分量,请将其移除以获取水平分量,我将其称为 y ,原因稍后会变得明显:


y = v - ( v 向上向上 $ b

其中向上是垂直向上指向的单位向量。

我们可以使用交叉乘积(并记住右手规则)找到与 y 垂直的水平向量:


x = v ×向上



现在你可以看到 y 是指向前的平面中的矢量(远离相机), x 指向右侧的矢量(相对于相机)。如果您对这些向量进行归一化处理:


x = x / | x |



= y / | y / p>

然后您可以使用 x ŷ玩家的相对运动。如果您的游戏杆读数是 Jx Jy ,那么请移动玩家
$ b


Jx x + Jy


其中 s 是一个与玩家速度成正比的适当标量值。

(请注意,在这个答案中的任何一点都没有计算角度!)

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);

解决方案

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:

y = v − (v · up) up

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):

x = v × up

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:

= x / |x|

ŷ = y / |y|

then you can use 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

s (Jx + Jy ŷ)

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!)

这篇关于'添加'两个角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆