• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Character Animation

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

## Recommended Posts

I'm trying to achieve character animation through the use of a single-mesh, an articulated skeleton and keyframing. However, I don't just want to draw the mesh using an indirect recursive translation/rotation function (I already know how to do that). What I need is for this character to interact with it's 3D environment 'physically' (ie, ragdoll), so the way I'm looking at it, all I really need to do is translate/rotate each bone directly (along with each vertex weighted to the bone), and the rest should fall into place. My problem lies in rotating the bones/vertices around a single point (their 'parent' bones). Example: If the rootBone is positioned at 0,0,0 and it has a single child bone, positioned at 1,0,0; and I set 2 keyframes for the rootBone's orientation; 0,0,0 at time 0s, 0,5,0 at time 10s. As time progresses from 0s to 10s, the rootBone's child bone rotates around the rootBone approx 300 degrees. I believe the problem lies in my rotation function. Perhaps someone can confirm that it works properly? Here's how I'm doing it:
// The following is uber-pseudo-code

Bone
{
Vector3f position, orientation;
Bone children[];
int numChildren;
}

EvaluateBone(rootBone)
{
for(i=0;i<rootBone.numChildren;i++)
{
rootBone.child[i].position = Vector3fRotated(rootBone.child[i].position,rootBone.position,rootBone.orientation);
EvaluateBone(rootBone.child[i]);
}
}

// The following function is actual code

Vector3f Vector3fRotated(Vector3f source, Vector3f origin, Vector3f rotation)
{
Vector3f result = source;

float x1,x2,x3,y1,y2,y3,z1,z2,z3;
float xReal = source.x, yReal = source.y, zReal = source.z;

xReal -= origin.x;
yReal -= origin.y;
zReal -= origin.z;

x1 = zReal*sin(rotation.y)+xReal*cos(rotation.y);
y1 = yReal;
z1 = zReal*cos(rotation.y)-xReal*sin(rotation.y);

x2 = x1;
y2 = y1*cos(rotation.x)-z1*sin(rotation.x);
z2 = y1*sin(rotation.x)+z1*cos(rotation.x);

x3 = y2*sin(rotation.z)+x2*cos(rotation.z);
y3 = y2*cos(rotation.z)-x2*sin(rotation.z);
z3 = z2;

result.x = x3+origin.x;
result.y = y3+origin.y;
result.z = z3+origin.z;

return(result);
}

Thanks for your help. [edited by - mattbbangin on April 11, 2004 4:26:49 PM]

##### Share on other sites
void Matrix::setRotationRadians( const float *angles )
{
double cr = cos( angles[0] );
double sr = sin( angles[0] );
double cp = cos( angles[1] );
double sp = sin( angles[1] );
double cy = cos( angles[2] );
double sy = sin( angles[2] );

...
}

''cr'' and ''sr'' appear to mean ''cos(roll)'' and ''sin(roll)''
so they have *angles setup in the manner of ROLL, PITCH, YAW.
that means that i shouldnt assume that ''const float *angles'' is a ptr to the members (XYZ) of a standard Vector3f structure, correct?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015818
×