Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Matrix math help wanted

$
0
0
I have the following fragments of code: (obviously there is more to the Matrix3 class, this is just the bits that are relavent) class Matrix3 { float m[4][3]; Matrix3 operator*(const Matrix3&) const; }; Matrix3 Matrix3::operator*(const Matrix3 &m2) const { Matrix3 ret; ret.m[0][0] = this->m[0][0] * m2.m[0][0] + this->m[0][1] * m2.m[1][0] + this->m[0][2] * m2.m[2][0]; ret.m[1][0] = this->m[1][0] * m2.m[0][0] + this->m[1][1] * m2.m[1][0] + this->m[1][2] * m2.m[2][0]; ret.m[2][0] = this->m[2][0] * m2.m[0][0] + this->m[2][1] * m2.m[1][0] + this->m[2][2] * m2.m[2][0]; ret.m[3][0] = m2.m[0][0] * this->m[3][0] + m2.m[1][0] * this->m[3][1] + m2.m[2][0] * this->m[3][2] + m2.m[3][0]; ret.m[0][1] = this->m[0][0] * m2.m[0][1] + this->m[0][1] * m2.m[1][1] + this->m[0][2] * m2.m[2][1]; ret.m[1][1] = this->m[1][0] * m2.m[0][1] + this->m[1][1] * m2.m[1][1] + this->m[1][2] * m2.m[2][1]; ret.m[2][1] = this->m[2][0] * m2.m[0][1] + this->m[2][1] * m2.m[1][1] + this->m[2][2] * m2.m[2][1]; ret.m[3][1] = m2.m[0][1] * this->m[3][0] + m2.m[1][1] * this->m[3][1] + m2.m[2][1] * this->m[3][2] + m2.m[3][1]; ret.m[0][2] = this->m[0][0] * m2.m[0][2] + this->m[0][1] * m2.m[1][2] + this->m[0][2] * m2.m[2][2]; ret.m[1][2] = this->m[1][0] * m2.m[0][2] + this->m[1][1] * m2.m[1][2] + this->m[1][2] * m2.m[2][2]; ret.m[2][2] = this->m[2][0] * m2.m[0][2] + this->m[2][1] * m2.m[1][2] + this->m[2][2] * m2.m[2][2]; ret.m[3][2] = m2.m[2][2] * this->m[3][2] + m2.m[1][2] * this->m[3][1] + m2.m[0][2] * this->m[3][0] + m2.m[3][2]; return ret; } Then I have code that does this as part of an exporter to a custom file format: Matrix3 anim = //blah Matrix3 inverse = //blah Matrix3 m2 = anim * inverse; Ignore the //blah bits, they are just giving both anim and inverse some values (how they do that doesn't matter). I am writing an importer for this file format that does the opposite of the exporter and as part of that I am able to produce the "inverse" matrix and the "m2" matrix but not the "anim" matrix. Given the "inverse" and "m2" matrices and the above multiplication operator code, is it possible to write a function that can recover the "anim" matrix and what should that function look like? And no there are no functions in the Matrix3 class that look to be useful for this.

Viewing all articles
Browse latest Browse all 17825

Trending Articles