Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Cool

Cool

mozie
Not your journal. · · 2 min read
746 2
Yeah, cool! I decided to try to write a 4x3 matrix class from memory alone. I have been using the D3DXMATRIX class in all of my code, and a little while I ago I pulled out a single class to do some work on it. Anyways I needed to include D3D stuff to work on something that only used (I think) the vector class. So that brough me to writing (cough::copy::cough) my vector class from my math book. Well now I wanted to see what I learned, or should I say retained. So I decided to write it all before I looked at my book, or the code sample files.

Well, if you are still reading this entry, here you have it. Fresh out of my brain, and it even compiles!
#ifndef MATRIX_4_X_3_H#define MATRIX_4_X_3_H#include "vectormath.h"class Matrix4x3{public:	float m11,m12,m13;	float m21,m22,m23;	float m31,m32,m33;	float tx,ty,tz;	Matrix4x3 operator *(const Matrix4x3 &a) const	{		Matrix4x3 d;		d.m11 = (m11 * a.m11) + (m12 * a.m21) + (m13 * a.m31);		d.m12 = (m11 * a.m12) + (m12 * a.m22) + (m13 * a.m32);		d.m13 = (m11 * a.m13) + (m12 * a.m23) + (m13 * a.m33);		d.m21 = (m21 * a.m11) + (m22 * a.m21) + (m23 * a.m31);		d.m22 = (m21 * a.m12) + (m22 * a.m22) + (m23 * a.m32);		d.m23 = (m21 * a.m13) + (m22 * a.m23) + (m23 * a.m33);		d.m31 = (m31 * a.m11) + (m32 * a.m21) + (m33 * a.m31);		d.m32 = (m31 * a.m12) + (m32 * a.m22) + (m33 * a.m32);		d.m33 = (m31 * a.m13) + (m32 * a.m23) + (m33 * a.m33);		return d;	}	Matrix4x3() {}	~Matrix4x3() {}	void Identity()	{		m11 = m22 = m33 = 1.0f;		m12=m13=m21=m23=m31=m32=m33 = 0.0f;		tx=ty=tz = 0.0f;	}	void RotateX(float thetaX)	{		m22 = cos(thetaX);		m23 = sin(thetaX);		m32 = -sin(thetaX);		m33 = cos(thetaX);	}	void RotateY(float thetaY)	{		m11 = cos(thetaY);		m13 = -sin(thetaY);		m31 = sin(thetaY);		m33 = cos(thetaY);	}	void RotateZ(float thetaZ)	{		m11 = cos(thetaZ);		m12 = sin(thetaZ);		m21 = -sin(thetaZ);		m22 = cos(thetaZ);	}	void Translate(Vector3 vec)	{		tx = vec.x;		ty = vec.y;		tz = vec.z;	}	void Copy(const Matrix4x3 &a)	{		m11 = a.m11; m12 = a.m12; m13 = a.m13;		m21 = a.m21; m22 = a.m22; m23 = a.m23;		m31 = a.m31; m32 = a.m32; m33 = a.m33;	}};#endif // MATRIX_4_X_3_H

Discussion

Loading comments...