Unfadable 140 Report post Posted March 26, 2006 Two quick questions: 1) I'm implementing a matrix library and need an inverse function to find inverse cam/world matrices etc. Is Kramer's rule the way to go? If not, can I get a recommendation. 2) Just curious as to how you guys store your game object's orientation. Euler angles, rotation matrices, quats, etc. I'm leaning towards a matrix, so that I can apply world rotations easily w/o converting from/to euler angles. 0 Share this post Link to post Share on other sites
Zipster 2378 Report post Posted March 26, 2006 Quote:Original post by Unfadable1) I'm implementing a matrix library and need an inverse function to find inverse cam/world matrices etc. Is Kramer's rule the way to go? If not, can I get a recommendation.The inverse of an orthonormal matrix is actually just the transpose. So for a 3x3 rotation matrix you can just take the transpose. If you're using a 4x4 homogeneous transformation matrix, then you can invert it in pieces - use R^{T} on the rotational 3x3 submatrix 'R', and use -R^{T}d to invert the 3x1 translation submatrix 'd'.Quote:Original post by Unfadable2) Just curious as to how you guys store your game object's orientation. Euler angles, rotation matrices, quats, etc. I'm leaning towards a matrix, so that I can apply world rotations easily w/o converting from/to euler angles.Most of the time you can get away with Euler angles, but if you experience Gimbal lock problems then you'll have to switch to quaternions. Personally I've always stored Euler angles and created/updated a set of transformation matrices that I pass to DirectX/OpenGL. 0 Share this post Link to post Share on other sites
Unfadable 140 Report post Posted March 26, 2006 Yeah, unfortunately my matrices aren't guaranteed to be orthonormal, so I need a general solution. Kramer's rule then? 0 Share this post Link to post Share on other sites
Zipster 2378 Report post Posted March 26, 2006 For small matrices (4x4 and smaller), you can get away with an explicit formula (like those shown here). For a general NxN matrix, I would use Gauss-Jordan elimination.Just out of curiosity, which matrices do you expect to be non-orthonormal, besides maybe the perspective matrix? 0 Share this post Link to post Share on other sites
Unfadable 140 Report post Posted March 26, 2006 Cool I'll check that out. Thanks.The world matrix of some of my objects may have a scale applied to them.Which reminds me of another question. Is it valid to normalize the basis vectors in a matrix and it still maintain the proper orientation? It seems like it should be, but I've never been sure. 0 Share this post Link to post Share on other sites
Zipster 2378 Report post Posted March 26, 2006 I completely forgot about scaling (I don't use it much). There are also tricks for inverting that transformation. You can compute the length of each basis, divide it out (so normalize the basis vectors), do the transpose thing, and divide out the length again from each of the new basis vectors. In other words, the basis vectors in R and R^{-1} will have inverse lengths.This also answers your new question, that you can change the length of the basis vectors and still maintain the same orientation. 0 Share this post Link to post Share on other sites
noNchaoTic 343 Report post Posted March 26, 2006 You could perhaps include a method for for quick inverse for cases when you KNOW that the matric is orthonormal? 0 Share this post Link to post Share on other sites
Unfadable 140 Report post Posted March 26, 2006 Quote:You could perhaps include a method for for quick inverse for cases when you KNOW that the matric is orthonormal?Oh absolutely. Depending on the scene, this operation may come up a lot and I'd definitely perfer using the transponse.Zipster, cool trick you've posted. Much appreciated. 0 Share this post Link to post Share on other sites