Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bone Animation, feedback needed

Started by Calin May 10, 2020 at 4:08 PM 78 replies 27.1k views
Original Post
Calin
Calin

Im starting to work on the system to animate 3d characters. I dont want to use any existing animation format and Im only looking for basic functionality. Im not even sure how to call it/what I will end up making. I don`t want to use matrices for vertex position transformations. Anyone with experience in animation? [hopes his post passes unnoticed]

My project`s facebook page is “DreamLand Page”
TeaTreeTim
TeaTreeTim

A matrix is just a way of representing a mathematical function. You can represent it how you want but the systems you will be working with like shaders and graphics api's already understand the format. At a basic level, animation can just be rotating bone heads, so you start with a root and work your way along the hierarchy rotating joined bones. Perhaps give more details as to what you have done and what you expect to achieve for more help.

fleabay
fleabay

Calin said:
I don`t want to use matrices for vertex position transformations.

You're quite the contrarian aren't you?

All a 3D matrix is is 4 vectors and all a vector is is 4 floats. I use matrices all the time but they are 16 values in a 1D float array. It doesn't make any sense to avoid matrices, especially with rotations.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
Calin
Calin

TeaTreeTim said:
Perhaps give more details as to what you have done

I have a function to rotate vertices around one axis using sin and arcsin.

My project`s facebook page is “DreamLand Page”
Calin
Calin

fleabay said:

You're quite the contrarian aren't you?

No, I`m just trying to find/use the most simple solution to a problem.

At a basic level, animation can just be rotating bone heads, so you start with a root and work your way along the hierarchy rotating joined bones.

I understand that when you use bones you have groups of vertices with different origin.

My project`s facebook page is “DreamLand Page”
fleabay
fleabay

Calin said:
No, I`m just trying to find/use the most simple solution to a problem.

I'm not sure if you understand spoken English or not, but if so watch this, it should be cued up to 20:58 already. Please watch it to get a better understanding of matrices (specifically the rotation matrix)

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
Calin
Calin

@fleabay What I don`t understand about matrices is that when you rotate an object how does the computer know where the vertex origin is found?

My project`s facebook page is “DreamLand Page”
fleabay
fleabay

@Calin The origin is at 0,0,0. And really, there is no ‘object rotation’, all rotations are done per vertex (or per joint in skeletal animation). So a vertex at 2,2,0 has it's origin at 0,0,0. If a vertex is at 83.3, 345.3, 3.3, it's origin is at 0,0,0 also.

Also joint are parented to each other in a hierarchy. Each parent joint affects the children joints with rotation as well as translation.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
NikiTo
NikiTo

Calin said:
What I don`t understand about matrices is that when you rotate an object how does the computer know where the vertex origin is found?

Calin
Calin

How do I apply a matrix to a vertex position?

struct vertex
{
float x;
float y;
float z;
};
vertex V;
V.x = 3;
V.y = 0;
V.z = 0;
D3DXMATRIXA16 testM;
D3DXMatrixRotationY( &testM,0.50f );
V.x = ??
V.z = ?? 
My project`s facebook page is “DreamLand Page”
Calin
Calin

http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-5

how cute, reading

[edit] it was a good read, a brush up on stuff I have forgoten. It doesnt answer my question however. I want to know the math behind matrices. ( Im not using SetTransform() calls ). How do I get the new vertex position without calling SetTransform() ?

My project`s facebook page is “DreamLand Page”
JoeJ
JoeJ

Calin said:
I want to know the math behind matrices.

You can understand it in a geometric way, ignoring it is linear algebra. Worked well for me.

On the left we have a transform or frame, like it looks in a 3D modeling program. Red = X axis, Green = Y, Blue = Z.

On the right is the 4x4 Mmatrix with their numbers. Colored upper left is a 3x3 matrix, which we can use if we only care about rotation.
The three axis are row vectors, colored accordingly. If there is no scale or sheer, those 3 vectors are unit length and orthogonal to each other. You can use them directly, e.g. to display the arrows on the left, but also for more useful things.

The 4th row stores position. (0,0,0) in our case. The right column (0,0,0,1) can be ignored for now (and indeed we often only store a 3x4 transform to save space and avoid useless operations).

Now an example. Assume we have a matrix for a object, and we want to transform a mesh vertex from the objects local space to the world space so we can display, or check collisions etc.
This is quite simple:

vec3 worldSpacePosition = matrix[3] + // position of object 
	matrix[0] * localVertex.x + // vertex x times orientation x axis of object
	matrix[1] * localVertex.y + 
	matrix[2] * localVertex.z;
	

(assuming i can access matrix rows with [] operater, which is usually implemented this way.)

Next example is to do the opposite. We know world position of a point and want to calculate the local position relative to the object.

localPosition.x = matrix[0].dot(worldPos - matrix[3]); // first move the position to the origin of the object by subtracting object position,
localPosition.y = matrix[1].dot(worldPos - matrix[3]); // then for each axis see how far the point is away from athe plane of this axis.
localPosition.z = matrix[2].dot(worldPos - matrix[3]);

Do you know how dot product works?
It's essential. if we have a unit vector like a normal, this normal has a plane (the surface it points way from). Using dot product we can measure distance to this plane.
Be sure to understand this. It's not obvious at first but easy.
If you don't know learn about dot (and cross) product first.

Now you have learned many things:

Rotating vectors. First example did rotate by the matrix, second example did unrotate.

Because matrices are just bunch of vectors, you could now also transform a child bone matrix by the parent bone matrix. Just do above examples for each axis vector and also position.
This also implies that matrix multiplication can be understood by understanding dot product. And if you look up your matrix library multiplication code it is equivalent to doing dot products.

The 'unrotation' or ‘untransform’ is related to taking the inverse of a matrix, which also can be done with simple dot products if it is a orthogonal frame like mostly.

This is usually enough to know about matrices representing transforms. But there are pitfalls:

Conventions:

Row- and Column-major order. Some people prefer to put axis and position into columns not rows. The matrix is then transposed in comparison to my example. DirectX is an example for this.
You can still do the same things, and they often work regardless. But it causes confusion and some trial and error.

Left Handed vs. Right Handed coordinate systems. Some people have Y up, some down, for example.

JoeJ
JoeJ

An often used alternative for 4x4 matrix transform is using a vec3 for position and a quaternion for orientation. (Some math gurus even use dual quaternion for both)

This takes less space, but it can not represent scale.

I usually prefer it, especially when working on character hierarchies and related IK and physics tasks.

Calin
Calin

so the arrows are vectors, I got it

My project`s facebook page is “DreamLand Page”
JoeJ
JoeJ

Yeah, the drawn axis arrows are directions, so vectors, and each is stored directly also in matrix form.

The position of the object is a point, also stored (4th. row or column - depending on convention).

So this hopefully demystifies transformation matrices, and you see how all those numbers make sense geometrically, and how they can be used e.g. to get front facing direction of a camera matrix and so on.

BTW, the difference between point and vector can be more than just rhetorical when working with matrices.
E.g.:

vec4 normal (5,0,0,0); // this is a direction, so set 4th number to 0.
vec4 transormedNormal = matrix * normal. // this performs only rotation because the 0 cancels out translation row

vec4 position (5,0,0,1); // this is a point, so set 4th number to 1.
vec4 transformedPosition = matrix * position. // performs rotation and translation

While this is nice maybe, it can waste space and useless instructions for the pure rotation, so matrix libraries often have rotation only functions so there is no need for a 4th number in the vector.

Thinking about the difference between points and vector can sometimes help in general.

It certainly helps a lot to make a difference between rotation and orientation, because that's much harder to understand and deal with.

NikiTo
NikiTo

@JoeJ Now you have to explain to me tensors.

JoeJ
JoeJ

‘Tensor’… no idea what it means. Reading it up on Wikipedia i see it is something we use a lot, but lacking math education i do not know what concepts the word really represents. Sounds like meaning pretty any mathematical construct (a single number, a complex number, a vector, also more of those for n dimensions), that can be related to adjacent constructs of the same type with a linear equation? I wish i knew better… like often : )

NikiTo
NikiTo

@JoeJ I read too, but can not understand what people do with tensors in computer science.
You give me 100 tensors…. and what next? What should i do with your 100 tensors?

When i am complete zero at something i need to read a whole e-book. Preferably with the word "dummies" in the name of the book hahaha

Definitively a book is a lot of help. Bugs never give me time to read a book.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.