• 12
• 12
• 9
• 10
• 13

# Assorted Direct3D Questions

This topic is 3793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, before I begin, I have to apologize about my English... but then please help me out on the following questions.... Question 1: If I have a customized vector that I want to interpolate to (e.g. picking up a weapon on the floor), let's say I don't know the quaternion value on this destination end point..., how can I actually figure it out? Of course I know the vectors, so let's say D3DXVECTOR3 (100.0f, 100.0f, 100.0f) which is the original position of the hand =====> D3DXVECTOR3(var1.x, var1.y, var1.z) which is the position of the weapon..... etc Let's say I can retrieve the original matrix values (object in identity or during half-way-thru of some animation, say walking or deccelarating) and I want to transit from that animation to this customized animation (picking the weapon up). The original animation is from the animation controller object of Direct3D... I can't find (so i can't fill in) the quaternion value on the destination end so the mesh turns out to be torn apart when doing animation. In the code I provided below, I had 2 vectors to interpolate, and I was using Affine Transformation, therefore I needed to fill in both values (vector and quaternion), the reason why I needed to complete an affine was because there was a certain distance between the 2 vectors and a slight angle difference between them... I should use the term "customized real-time animation", this should better describe my situation... :) Question 2: Do I have to generate/make up 10 keyframes randomly when I'd like an animation from the exporter with 10 keyframes to "synchronize" with my "customized" animation whenever a game character comes across an object he's about to pick up? because they have different times ( i know only 2 keys, start and end )? Question 3: How can I calculate the open side/orientation of a hand facing the weapon? so that the trigger is properly gripped... I have some code snippet for you to investigate I just played around with tiny.x....
cAnimation::cAnimation()
{

float x,y,z,w;
float x2,y2,z2,w2;

m_SpecialKey1.m_Time = 0;
m_SpecialKey2.m_Time = 4096; // 80

// calf

m_SpecialKey1.m_matKey._11 = 1.000000;  &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; copied from models
exported from max
m_SpecialKey1.m_matKey._12 = -0.000691;
m_SpecialKey1.m_matKey._13 = -0.000000;
m_SpecialKey1.m_matKey._14 = 0.000000;

m_SpecialKey1.m_matKey._21 = 0.000691;
m_SpecialKey1.m_matKey._22 = 1.000000;
m_SpecialKey1.m_matKey._23 = 0.000000;
m_SpecialKey1.m_matKey._24 = 0.000000;

m_SpecialKey1.m_matKey._31 = 0.000000;
m_SpecialKey1.m_matKey._32 = -0.000000;
m_SpecialKey1.m_matKey._33 = 1.000000;
m_SpecialKey1.m_matKey._34 = 0.000000;

m_SpecialKey1.m_matKey._41 = 119.231514;
m_SpecialKey1.m_matKey._42 = -0.000005;
m_SpecialKey1.m_matKey._43 = 0.000001;
m_SpecialKey1.m_matKey._44 = 1.000000;

m_SpecialKey2.m_matKey._11 = 0.992696;
m_SpecialKey2.m_matKey._12 = -0.120646;
m_SpecialKey2.m_matKey._13 = -0.000000;
m_SpecialKey2.m_matKey._14 = 0.000000;

m_SpecialKey2.m_matKey._21 = 0.120646;
m_SpecialKey2.m_matKey._22 = 0.992696;
m_SpecialKey2.m_matKey._23 = 0.000000;
m_SpecialKey2.m_matKey._24 = 0.000000;

m_SpecialKey2.m_matKey._31 = -0.000000;
m_SpecialKey2.m_matKey._32 = -0.000000;
m_SpecialKey2.m_matKey._33 = 1.000000;
m_SpecialKey2.m_matKey._34 = 0.000000;

m_SpecialKey2.m_matKey._41 = 119.231514;
m_SpecialKey2.m_matKey._42 = 0.000002;
m_SpecialKey2.m_matKey._43 = -0.000002;
m_SpecialKey2.m_matKey._44 = 1.000000;

m_SpecialKey5.m_matKey._11 = -0.950769;
m_SpecialKey5.m_matKey._12 = 0.300574;
m_SpecialKey5.m_matKey._13 = -0.075459;
m_SpecialKey5.m_matKey._14 = 0.000000;

m_SpecialKey5.m_matKey._21 = 0.309313;
m_SpecialKey5.m_matKey._22 = 0.905410;
m_SpecialKey5.m_matKey._23 = -0.290788;
m_SpecialKey5.m_matKey._24 = 0.000000;

m_SpecialKey5.m_matKey._31 = -0.019082;
m_SpecialKey5.m_matKey._32 = -0.299812;
m_SpecialKey5.m_matKey._33 = -0.953807;
m_SpecialKey5.m_matKey._34 = 0.000000;

m_SpecialKey5.m_matKey._41 = -27.853168;
m_SpecialKey5.m_matKey._42 = -0.096285;
m_SpecialKey5.m_matKey._43 = -31.055355;
m_SpecialKey5.m_matKey._44 = 1.000000;

m_SpecialKey6.m_matKey._11 = -0.935626;
m_SpecialKey6.m_matKey._12 = 0.342228;
m_SpecialKey6.m_matKey._13 = -0.086515;
m_SpecialKey6.m_matKey._14 = 0.000000;

m_SpecialKey6.m_matKey._21 = 0.352570;
m_SpecialKey6.m_matKey._22 = 0.894002;
m_SpecialKey6.m_matKey._23 = -0.276506;
m_SpecialKey6.m_matKey._24 = 0.000000;

m_SpecialKey6.m_matKey._31 = -0.017284;
m_SpecialKey6.m_matKey._32 = -0.289208;
m_SpecialKey6.m_matKey._33 = -0.957110;
m_SpecialKey6.m_matKey._34 = 0.000000;

m_SpecialKey6.m_matKey._41 = -27.748009;
m_SpecialKey6.m_matKey._42 = 0.301211;
m_SpecialKey6.m_matKey._43 = -31.076935;
m_SpecialKey6.m_matKey._44 = 1.000000;

m_RotKey1.m_Time = 0;
m_RotKey2.m_Time = 4096;

w = sqrt((m_SpecialKey1.m_matKey._11 + m_SpecialKey1.m_matKey._22 +
m_SpecialKey1.m_matKey._33)+1) / 2;
x = sqrt((m_SpecialKey1.m_matKey._11 - m_SpecialKey1.m_matKey._22 -
m_SpecialKey1.m_matKey._33)+1) / 2;
y = sqrt((-m_SpecialKey1.m_matKey._11 + m_SpecialKey1.m_matKey._22 -
m_SpecialKey1.m_matKey._33)+1) / 2;
z = sqrt((-m_SpecialKey1.m_matKey._11 - m_SpecialKey1.m_matKey._22 +
m_SpecialKey1.m_matKey._33)+1) /2;
//  D3DXQuaternionIdentity(&m_RotKey1.m_quatKey);
m_RotKey1.m_quatKey = D3DXQUATERNION (x,y,z,w);
// 45 degrees
m_RotKey2.m_quatKey = D3DXQUATERNION (0.38268f, 0.38268f, 0.38268f,
0.92387f);  // &lt;&lt;&lt;&lt;&lt; some artbitary key which did not work because the 2
bones b/w calf and thigh would be torn apart
m_SpecialKey3.m_vecKey = D3DXVECTOR3(m_SpecialKey1.m_matKey._11,
m_SpecialKey1.m_matKey._22, m_SpecialKey1.m_matKey._33);//(-0.950769f,
0.905410f, -0.953807f); // 11 22 33

m_SpecialKey4.m_vecKey = D3DXVECTOR3(-27.748009f, 0.301211f, -31.076935f);
&lt;&lt;&lt;&lt; same as above

///////////// the following is the key for the thigh.

m_RotKey3.m_Time = 0;
m_RotKey4.m_Time = 4096;
w2 = sqrt((m_SpecialKey5.m_matKey._11 + m_SpecialKey5.m_matKey._22 +
m_SpecialKey5.m_matKey._33)+1) / 2;
x2 = sqrt((m_SpecialKey5.m_matKey._11 - m_SpecialKey5.m_matKey._22 -
m_SpecialKey5.m_matKey._33)+1) / 2;
y2 = sqrt((-m_SpecialKey5.m_matKey._11 + m_SpecialKey5.m_matKey._22 -
m_SpecialKey5.m_matKey._33)+1) / 2;
z2 = sqrt((-m_SpecialKey5.m_matKey._11 - m_SpecialKey5.m_matKey._22 +
m_SpecialKey5.m_matKey._33)+1) /2;

m_RotKey3.m_quatKey = D3DXQUATERNION (x2,y2,z2,w2);

m_RotKey4.m_quatKey = D3DXQUATERNION (0.38268f, 0.38268f, 0.38268f,
0.92387f);  &lt;&lt;&lt;&lt;&lt; some artbitary key which did not work because the 2 bones
b/w calf and thigh would be torn apart

m_SpecialKey7.m_vecKey = D3DXVECTOR3(m_SpecialKey5.m_matKey._11,
m_SpecialKey5.m_matKey._22,  m_SpecialKey5.m_matKey._33);

m_SpecialKey8.m_vecKey = D3DXVECTOR3(-27.748009f, 0.301211f, -31.076935f);
&lt;&lt;&lt;&lt; same as above

}

Thanks Jack EDIT: Please remember to use 'source' tags in future. [Edited by - jollyjeffers on November 3, 2007 7:06:23 AM]