2つの3Dオブジェクト間の距離を測定する方法を理解したいと思います。それらを親オブジェクトと子オブジェクトと呼ぶことにしましょう。親は車のボディ、子供は車の車輪と考えてください。XNAを使用している親オブジェクトの向きに関連した、Matrixオブジェクト間の距離?
ワールド空間のオブジェクトの位置に基づいて違いを得る方法を理解していますが、親オブジェクトの相対的なオブジェクト空間に基づく測定として違いを得たいと思います。
例:親が東向きで、子が2X、親から3Yの場合、相対的な意味で測定されます。親が60度回転した場合、子供の相対的な位置は、オブジェクト空間内の2x、3yの距離にとどまる。世界の空間の感覚のように、Vector3としての子オブジェクトの測定値はかなり異なっています。
基本的には、特許の右側にある子オブジェクトが常に親オブジェクトの右にとどまるように、違いを得るための予測可能な方法が必要です。
これは、親コンポーネントであるが、このアップデートは、すべてのフレームを実行している:
[Serializable]
public class Component_Parent : BaseComponentAutoSerialization<ISceneEntity>
{
public override void OnUpdate(GameTime gameTime)
{
PassThrough.ParentMatrix = ParentObject.World;
PassThrough.ParentTranslation = ParentObject.World.Translation;
}
}
この次の部分は、子コンポーネントである:
[Serializable]
public class Component_Child : BaseComponentAutoSerialization<ISceneEntity>
{
Vector3 _parentOffset;
Quaternion _parentQuaternionOffset;
public override void OnUpdate(GameTime gameTime)
{
// Get a sceneobject from the ParentObject
SceneObject sceneobject = (SceneObject)ParentObject;
// This relies on the position never being at 0,0,0 for setup, so please don't do that
// or change it with more look ups so that you don't need to rely on a Zero Vector3 :-)
if (PassThrough.GroupSetupMode || _parentOffset == Vector3.Zero)
{
if (PassThrough.ParentTranslation != Vector3.Zero)
{
_parentOffset = sceneobject.World.Translation - PassThrough.ParentTranslation;
// Decompose World Matrix (Parent)
Quaternion parentQ = new Quaternion();
Vector3 parentSpot = new Vector3();
Vector3 parentScale = new Vector3();
PassThrough.ParentMatrix.Decompose(out parentScale, out parentQ, out parentSpot);
Matrix identity = Matrix.Identity;
// Decompose Identity Matrix (Parent)
Quaternion identityQ = new Quaternion();
Vector3 identitySpot = new Vector3();
Vector3 identityScale = new Vector3();
identity.Decompose(out identityScale, out identityQ, out identitySpot);
_parentQuaternionOffset = identityQ - parentQ;
}
}
else
{
if (_parentOffset != Vector3.Zero)
{
// Decompose World Matrix (Child)
Quaternion rotationQ = new Quaternion();
Vector3 spot = new Vector3();
Vector3 scale = new Vector3();
sceneobject.World.Decompose(out scale, out rotationQ, out spot);
// Decompose World Matrix (Parent)
Quaternion parentQ = new Quaternion();
Vector3 parentSpot = new Vector3();
Vector3 parentScale = new Vector3();
PassThrough.ParentMatrix.Decompose(out parentScale, out parentQ, out parentSpot);
Matrix location = Matrix.CreateTranslation(PassThrough.ParentTranslation);
Matrix rotation = Matrix.CreateFromQuaternion(parentQ);
Matrix rotation2 = Matrix.CreateFromQuaternion(_parentQuaternionOffset);
Matrix newWorld = rotation * location;
Vector3 testTranslation = newWorld.Translation + ((newWorld.Left * _parentOffset.X) + (newWorld.Up * _parentOffset.Y) + (newWorld.Forward * _parentOffset.Z));
Matrix scaleM = Matrix.CreateScale(scale);
//sceneobject.World = scaleM * (rotation * (Matrix.CreateTranslation(testTranslation)));
sceneobject.World = (Matrix.CreateTranslation(testTranslation));
}
}
}
}
私はそれがを追跡することとは何かを持っていると思います恒等行列からのオフセット回転と、私はその効果のためにいくつかのコードを追加しようとし始めましたが、実際に次に何があるのかは分かりません。
追加:
私はワールド空間の方向を向いて親オブジェクトを持っている場合は、すべての作品は、問題だし、別の方向を向いていますし、子供は彼らが同じ量だけ回転させるように思われる場合には一緒にグループ化される。
私が試してみて、説明するデモビデオをアップロードしました:
http://www.youtube.com/watch?v=BzAKW4WBWYs
私は、コンポーネントの完全なコードを通じて、静的なパスとシーンエンティティを貼り付けました。
おかげ
私はあなたの質問を理解していません。あなたは親/子の間の距離をしたいですか?または原点からの子供の距離? – namar0x0309
親と子の間の、親の方向に対する相対的な距離。 –
どのような方向であっても、子供は同じ距離になります。親の行列が適用され、次に子行列が適用されます。子の行列の平行移動部分が触られていない限り、距離は同じままです。 – namar0x0309