世界速度本地(船可能会向后飞因此需要世界负速度等) [英] world velocity to local (ship might be flying backward so need worlds negative velocity etc.)

查看:215
本文介绍了世界速度本地(船可能会向后飞因此需要世界负速度等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题pretty的多说,这一切..说我有一艘船,它的worldVelocity是一个Vector3类型使用这些值: X:0 Y:0 Z:1 (假设+ Z是正向,+ Y是了,+ X为右) 此Vector3类型被添加到船舶worldTranslations矩阵,其存储的平移和旋转。

title pretty much says it all.. say I have a ship, its worldVelocity is a Vector3 with these values: X: 0 Y: 0 Z: 1 (assuming +Z is Forward, +Y is Up, and +X is Right) this Vector3 is added to the ships worldTranslations Matrix which stores translation and rotation.

worldTranslations.Translation + = worldVelocity

worldTranslations.Translation += worldVelocity

和我的船前进,并停止在加快速度1(正确),因为这是它的目标速度,但如果船舶已经向右旋转180度,所以其现在倒飞。自动船舶目标速度应该会检测到这一点,并开始尝试再往前飞。

and my ship goes forward, and it stops accelerating at speed 1 (correctly) as this is its target velocity, but what if the ship has been rotated Right 180 degrees, so its now flying backwards. Automatically the ships target velocity should detect this and begin trying to fly forward again.

现在的问题是,我不知道如何让本地的速度了我的船速度和localTransforms,我不能在任何地方找到答案..

The problem is I don't know how to get the local velocity out of my ships velocity and localTransforms, and I cant find an answer anywhere..

所以此刻我的船采用了世界上速度为如果达到了目标速度,只要犯规转船检查,它飞正常。我的目标速度将是一个,所以我的船将其当前速度(0,0,0)的目标速度(0,0,1),并适当加速,直至达到其目标(0,0,1),并停止加速到保持稳定的速度,但如果我转(说的对只有90度),目前的速度是现在(-1,0,0),因为船是漂流现在剩下的,所以应使用相对速度来判断,它需要加速(1,0,1),回到(0,0,1),但我不知道如何获得相对速度,因此目前使用的世界速度这仍然是(0,0,1),即使其飞行离开因此它认为它的都好,但它仍然漂流离开。

so at the moment my ship uses the world velocity for checking if its reached its target speed, so long as the ship doesnt rotate, it flies properly. My target speed will be one, so my ship compares its current velocity (0,0,0) to target velocity (0,0,1) and properly accelerates till it reaches its target (0,0,1) and stops accelerating to maintain a constant speed, but if i turn (say just 90 degrees right), current velocity is now (-1,0,0) because the ship is drifting left now, so it should use that relative velocity to determine that it needs to accelerate (1,0,1) to get back to (0,0,1) but I have no idea how to get relative velocity so it currently uses world velocity which is still (0,0,1) even though its flying left and so it thinks its all good but its still drifting left..

谢谢..再次大​​家:)

Thanks.. again everyone :)

推荐答案

答案是通过逆旋转矩阵变换的速度矢量。

The answer was to transform the velocity vector by the inverse rotation matrix.

这个职位是做我的朋友认识到使用其内置的功能之一期望的结果是实现了在Unity3D,但最终是同一个问题:

This post was made as my friend realised the desired result was achieved in Unity3D using one of its built in functions, but ultimately is the same question:

<一个href="http://stackoverflow.com/questions/17389414/xna-equivalency-of-unity-function-transform-inversetransformdirection">XNA统一功能Transform.InverseTransformDirection等效

更详细的解释可以在该网页上找到。

More detailed explanation can be found on that page.

然而,如果这不适合你,因为它并没有立即解决我的问题,请检查向量的一个组成部分的时间。我不得不-1乘以向量只有Z分量,使其工作。其他数学最有可能的干扰,所以我建议你检查单独的结果向量部件的结果。

However if this does not work for you, as it didn't immediately fix my problem, try examining one component of the vector at a time. I had to multiply only the Z component of the vector by -1 to make it work. Most likely interference by other maths so I recommend you examine the result vectors components results individually.

-Aaron

这篇关于世界速度本地(船可能会向后飞因此需要世界负速度等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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