Modelview Matrix to vector3D or screen co-ordinates

Discussion about everything. New games, 3d math, development tips...
kulanuja
Posts: 20
Joined: Sat Jun 14, 2008 11:10 am

Modelview Matrix to vector3D or screen co-ordinates

Post by kulanuja »

Hi,

I have a modelview matrix which looks something like
- m0[0] m0[1] ... m0[15]

The corresponding values for the same are
- -0.215125 -0.906283 -0.363831 0.000000 -0.822941 0.127188 0.421722 0.000000 0.361637 -0.419996 0.832359 0.000000 -5.188786 -106.603622 -1713.731812 1.000000

I have to animate my MD2 model on screen according to these values.
Can anybody suggest how I an transform the modelview matrix into vector3D array for rendering on the screen.

I need this for my academic project.

Please help.

Thanks and Regards
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well the model view matrix doesn't transform into the on-screen coordinates... you need a projection matrix for that.

the model view matrix just transforms where in the 3D world the camera is, i believe.

but anyway, you just multiply the matrix with each of the vertices in your model to make the matrix affect the model.
Image Image Image
kulanuja
Posts: 20
Joined: Sat Jun 14, 2008 11:10 am

Post by kulanuja »

Thanks for replying JP!!

But how do I actually (practically) do that? I tried searching the tutorials and examples in all the forum topics to see if I can get an idea..but I did not find anything!! :(
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Why do you want to do this with irrlicht? Irrlicht does it all for you anyway, so there must be some reason you want to do it yourself right? Understanding your reason may help us give you a good response.

To figure out how to do it you'll probably have to look at the relevant classes such as IAnimatedMeshSceneNode, IMeshBuffer, CMatrix etc. to see how you can get access to a node's mesh and vertices and then see how they can be multiplied by a matrix to give you the transformed position.
Image Image Image
kulanuja
Posts: 20
Joined: Sat Jun 14, 2008 11:10 am

Post by kulanuja »

well I am working on a project in which actual user movements are recorded by a webcam and stored in a file.These movements (i.e. the ones recorded by the webcam) are stored in the recorded file in the form of model view matrix.

Now my aim is to render an animation (skeletal animation) on screen corresponding to these captured points.But I am not able to understand how I can do that!!

My scond problem is about skeletal animation.Unfortunately I coud not find a tutorial or good example which can give me an idea of skeletal animation :cry:

Please help me
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I see, is it some kinda of motion-capture you're doing? Using a webcam to get positions of objects in the real-world and recording their movements and then recreating them on-screen?

I'd ignore the skeletal animation bit for now and just find out how to apply your matrices to points to get them moving on the screen.

Basically you just take the matrices you've recorded and apply them to the vertices of your model, just get it working on a simple cube model first. Get the mesh from the model and then iterate through the vertices of the mesh and multiply them by the matrix.
Image Image Image
kulanuja
Posts: 20
Joined: Sat Jun 14, 2008 11:10 am

Post by kulanuja »

Perfect it is indeed motion capture!!

ok ignoring the skeletal animation part, do you think it is possible using a .md2 model is something like sydney.md2??

sorry if I am bothering you, but I am working on IRRLicht for some days now but am not able to figure out how I can achieve my aim!!
kulanuja
Posts: 20
Joined: Sat Jun 14, 2008 11:10 am

Post by kulanuja »

Basically you just take the matrices you've recorded and apply them to the vertices of your model, just get it working on a simple cube model first. Get the mesh from the model and then iterate through the vertices of the mesh and multiply them by the matrix.
Can you explain it to me giving a practical example??
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Skeletal animation is certainly the way you want to go with this, i'm just saying ignore that for the moment and just get the process of applying a matrix to an object to get that moving before you go into the skeletal animation which will be basically the same but applying matrices to multiple objects.

I would imagine using an md2 model (morphing animation) would be much harder because you'd have to know which vertices were part of, say, the hand or head etc. to be able to apply your specific matrices to them. The skeletal animation models take care of this for you because you just apply the matrix to the bone/joint and that in turn affects the necessary vertices.

Ok so i guess as that's what we're aiming for you don't want to affect each individual vertex of a cube, just affect the cube itself with your matrix.

So basically you've got setPosition and setRotation which you can do on a node, so you need to get those informations out of your matrix. To make this easier copy your matrix info into a CMatrix then you can do getRotationDegrees to get a rotation vector to pass to node->setRotation() and getTranslation to get a position vector to pass to node->setPosition().

Capice? See if you can get that working.

EDIT: creating a CMatrix from your matrix data... you may be able to use This;

CMatrix m;
m.setM(pointer_to_your_matrix_data);

That is, if your matrix is the same major as irrlicht's, if not then you can probably use the [] access method.
Image Image Image
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

he's better off doing the multiplication by the whole matrix. Else he'll only divide in multiple operations something that is already joined AND risk missing miscallenous effects like a scale, twist, etc.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

How would he go about doing that then? I can't see any way of applying a whole matrix to a scene node.
Image Image Image
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
seems to be how Irrlicht does it, just before the render.

for example, in Irr, they fake the world projection this way:

case ETS_WORLD:
{
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
// we have to update the clip planes to the latest view matrix
for (u32 i=0; i<MaxUserClipPlanes; ++i)
if (UserClipPlaneEnabled)
uploadClipPlane(i);
}
break;



I'd guess the model matrix is what you are looking for, no? ;)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well that would work, but it's rather fiddly and requires a lot more work, basically having to make a custom scene node for the objects being rendered in this way.
Image Image Image
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

yes, but it's faster AND will not ignore part of the matrix...

+, like most code of the sort, you only need to write it once.
kulanuja
Posts: 20
Joined: Sat Jun 14, 2008 11:10 am

Post by kulanuja »

Hi Guys,

I know this is a diversion from the topic in this post, but I thought of asking it here as this is the only post I am getting replies at :wink:

Please check my query at : http://irrlicht.sourceforge.net/phpBB2/ ... 4&start=45

Please let me know if anyone knows about such a problem and can help me out!!

Regarding the modelview matrix..I am giving it a try as per our discussions.Will let you know the results soon.

Thanks and Regards
Post Reply