开发者

computing the matrix that turns one set of coordinates into another

开发者 https://www.devze.com 2023-01-29 10:52 出处:网络
I am playing with some models for the game glest. These models are made up of one or more meshes; each mesh is made up of many frames which describe the position of each vertex for each frame of anim

I am playing with some models for the game glest.

These models are made up of one or more meshes; each mesh is made up of many frames which describe the position of each vertex for each frame of animation. In the model shown below, the position of each vertex in each wheel in each frame is in an array.

These models have been exported from 3D tools like Blender. Someone somewhere has the originals.

But I am wondering, for simple animation such as a wheel turning, how can you compute the transforms - the steps of rotate, scale and translate, or the matrix that when applied to the previous frame will result in the new frame?

(Obviously not all frames will have such transforms, because they may distort the models and such.)

Also, how can you detect mirroring and other opportunities to reduce the amount of vertex data by applying a matrix and rendering the same vertices again?

Running speed - if its 开发者_StackOverflow社区measured in just minutes - won't be a problem.

computing the matrix that turns one set of coordinates into another


First off, some assumptions:

  • You're dealing with 3D affine transformations (linear transformation plus translation).
  • You have the vertices for each frame in your animation
  • You can associate at least 4 vertices in a frame with 4 vertices in the next frame

Then you can take 4 vertices as 4D collumn vectors (appending a 1 in each vector's 4th element) in the original space and concatenate them to create a 4x4 matrix, called X. Do the same for their corresponding vectors in the tranformed space and call them Y, which will also be a 4x4 matrix. A little linear algebra provides you with a method to find the 4x4 matrix A that when applied to X gives you Y. Thus:

AX = Y
A = YX-1

Using this to get rotations and scaling is not trivial. However, the rightmost column of A will contain the translation for the object between the successive frames.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号