Keep doing it wrong (Directions)?

Started by
-1 comments, last by lucky6969b 7 years, 5 months ago

Hello,
I have generated a path which is 100% right....
But when I animate it, the agent is wagging at its tail (again?!)

It is basically interweaving between 0.7 and 0.9 during a diagonal move


idx: 0 x:-18.8936 y:-0.0923912 z:14.4929 dir:6.28319
idx: 1 x:-19.8936 y:-0.0923912 z:13.4929 dir:2.35619
idx: 2 x:-20.8936 y:-0.0923912 z:12.4929 dir:2.35619
idx: 3 x:-21.8936 y:-0.0923912 z:11.4929 dir:2.35619
idx: 4 x:-22.8936 y:-0.0923912 z:10.4929 dir:2.35619
idx: 5 x:-23.8936 y:-0.0923912 z:9.49293 dir:2.35619
idx: 6 x:-24.8936 y:-0.0923912 z:8.49293 dir:2.35619
idx: 7 x:-25.8936 y:-0.0923912 z:7.49293 dir:2.35619
idx: 8 x:-26.8936 y:-0.0923912 z:6.49293 dir:2.35619
idx: 9 x:-27.8936 y:-0.0923912 z:5.49293 dir:2.35619
idx: 10 x:-28.8936 y:-0.0923912 z:4.49293 dir:2.35619
idx: 11 x:-29.8936 y:-0.0923912 z:3.49293 dir:2.35619
idx: 12 x:-30.8936 y:-0.0923912 z:2.49293 dir:2.35619
idx: 13 x:-31.8936 y:-0.0923912 z:1.49293 dir:2.35619

Instant. Orientation: 1.74846e-007
Instant. Orientation: 1.74846e-007
t:0.0282843
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.0665941
t:0.0583363
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.137019
t:0.0901561
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.210831
t:0.11844
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.27546
t:0.148492
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.342782
t:0.178544
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.408386
t:0.208596
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.471943
t:0.238649
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.533135
t:0.266933
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.588292
t:0.296985
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.644029
t:0.327037
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.696539
t:0.355321
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.742775
t:0.385373
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.788283
t:0.413657
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.827509
t:0.445477
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.867239
t:0.475529
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.900292
t:0.505581
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.928832
t:0.535633
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.952717
t:0.565685
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.971827
t:0.59397
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.985366
t:0.624022
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.994956
t:0.654074
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.99956
t:0.684126
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.999154
t:0.714178
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.99374
t:0.74423
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.983347
t:0.774282
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.968025
t:0.804334
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.947851
t:0.832618
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.924523
t:0.86267
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.895241
t:0.89449
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.859351
t:0.92631
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.818632
t:0.956362
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.775948
t:0.986414
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.729376
t:1
Start Orientation: 1.74846e-007
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.707107
Instant. Orientation: 0.707107
t:0.030052
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.6865
t:0.0618718
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.723693
t:0.0919239
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.756992
t:0.121976
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.788432
t:0.152028
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.817936
t:0.183848
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.846985
t:0.2139
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.87228
t:0.243952
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.895434
t:0.275772
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.917551
t:0.305824
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.936122
t:0.335876
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.952394
t:0.365928
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.966327
t:0.39598
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.977888
t:0.426032
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.987047
t:0.457852
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.994103
t:0.487904
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.998254
t:0.517956
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.999954
t:0.548008
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.999199
t:0.57806
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.99599
t:0.60988
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.989927
t:0.639932
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.981698
t:0.668216
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.971751
t:0.698268
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.958866
t:0.730088
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.942658
t:0.76014
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.924967
t:0.790192
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.905004
t:0.820244
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.882819
t:0.850296
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.858467
t:0.883884
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.828758
t:0.915703
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.798266
t:0.945756
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.767449
t:0.977575
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====

Instant. Orientation: 0.732766
t:1
Start Orientation: 0.707107
Desired Orientation: 2.35619
=====
[/code]


What I did was to extract the direction like this


this->m_right = D3DXVECTOR3(this->m_localMatrix._11, this->m_localMatrix._12, this->m_localMatrix._13);
this->m_up = D3DXVECTOR3(this->m_localMatrix._21, this->m_localMatrix._22, this->m_localMatrix._23);
this->m_direction = D3DXVECTOR3(this->m_localMatrix._31, this->m_localMatrix._32, this->m_localMatrix._33);            

And the mover like this


D3DXQUATERNION qFinal, qStart, qEnd;
// Get Start Rotation
double fOldDir = l_transform->m_MotionInfo.fStartDir;
fOldDir = CapRadian(fOldDir);
D3DXQuaternionRotationAxis(&qStart, &D3DXVECTOR3(0, 1, 0), fOldDir);                            
                                

// Get End Direction
float fNewDir = l_transform->m_MotionInfo.fEndDir;
fNewDir = CapRadian(fNewDir);
D3DXQuaternionRotationAxis(&qEnd, &D3DXVECTOR3(0, 1, 0), fNewDir);
                                
// Interpolate
D3DXQuaternionSlerp(&qFinal, &qStart, &qEnd, l_transform->m_MotionInfo.fS);                            

                                 
                                l_transform->setRotation(qFinal);                              
 
TRACE("t:" << l_transform->m_MotionInfo.fS);
TRACE("Start Orientation: " << fOldDir);
TRACE("Desired Orientation: " << fNewDir);

Could anyone shed some lights on this?

I am wondering why this works

D3DXVECTOR3 axis;
FLOAT angle;
D3DXQuaternionToAxisAngle(&m_rotation, &axis, &angle);

this->m_direction.x = angle;

and this won't -> the local matrix is collapsed with scaling, position etc

this->m_right = D3DXVECTOR3(this->m_localMatrix._11, this->m_localMatrix._12, this->m_localMatrix._13);
this->m_up = D3DXVECTOR3(this->m_localMatrix._21, this->m_localMatrix._22, this->m_localMatrix._23);
this->m_direction = D3DXVECTOR3(this->m_localMatrix._31, this->m_localMatrix._32, this->m_localMatrix._33);          

Thanks
Jack

This topic is closed to new replies.

Advertisement