#### Archived

This topic is now archived and is closed to further replies.

# Any ideas on design of D3D Matrix class?

This topic is 5045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi im using the D3DX matrix functions to make a Matrix class. But i can''t decide on how to make the class very flexibile, but still easy to use. Any ideas? by flexible i mean being able to use different functions with other things eg D3DXMatrixRotationYawPitchRoll with camera and world, etc and easy by just having setPosition(x,y,z) etc Thanks,

##### Share on other sites

Usually when people make their own matrix class, it''s for the learning experience, so they write their own code... try that.

##### Share on other sites
the only good reason i can think of to write your own is to optimize away matrix multiplications. when you create rotation, translation, etc matrices they are mostly zero. so i multiplied them out by hand and only kept the non-zero multiplications. for example, here is my scaling function:
CMatrix & CMatrix::Scale(float x, float y, float z){	_11 *= x; _12 *= y; _13 *= z;	_21 *= x; _22 *= y; _23 *= z;	_31 *= x; _32 *= y; _33 *= z;	_41 *= x; _42 *= y; _43 *= z;	return *this;}

this replaces two function calls (Scale, Multiply) and a matrix multiplication (64 muls, 48 adds) with 12 muls and one function call. just lay out the memory properly (only two options here, either it gets transposed or it doesn''t) and you can simply cast it to a D3DMATRIX.

i only did this to the most common operations, but it is trivial to multiply it out by hand once. if more exotic operations turn out to take up significant time, i''ll do it to them too (or maybe do it anyways when i''m bored...)

##### Share on other sites
quote:
Original post by billybob
if more exotic operations turn out to take up significant time, i''ll do it to them too (or maybe do it anyways when i''m bored...)
All of the matrix optimizations have already been optimized by Intel. Even if you can short-cut a multiplication or two, I doubt your going to cut that many cycles.

Dustin Franklin
Mircrosoft DirectX MVP

##### Share on other sites
I know D3DX is extremely optimized, and I would be using it if I could, I use D3D indirectly through an API independant set of abstract classes. I did this because I really want to experiment with software rendering (I don''t care how slow it will be, it will be fun), and if I can write into a renderer that works, I will have an easy program to test with. I suppose I could also write an opengl version, but I don''t plan on it.

• ### Forum Statistics

• Total Topics
628706
• Total Posts
2984309

• 23
• 10
• 9
• 13
• 13