You might want to look at this matrix header written by me.
- It checks the dimensions (in multiplication, for example) at compile-time instead of run-time
- it doesn't use dynamic memory.
You might want to look at this matrix header written by me.
- It checks the dimensions (in multiplication, for example) at compile-time instead of run-time
- it doesn't use dynamic memory.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
Well since DirectX and about a ton of other graphics APIs including OpenGL use matrices to do 3D graphics, I'm fairly sure that they are not where the slow-down in code is going to be. OpenGL and I think DX create a 1 dimensional 4x4 matrix - like I showed before - and then concatenate them .
Matrix multiplies are not slow and I can't think of anything that would be faster in pure asm than accessing a linear array. All values could be stored using a stosd esp. if they are floats. Not sure what the big deal here is.
I have already created a matrix class using my system, but it isn't for any specific project (yet). It is a general class, designed to do whatever it is needed to do. Doesn't mean it's the only matrix class I'll ever create, however .
Do not make direct eye contact with me.
Depends on the size of the matrix... Calculating determinants and eigenvectors/eigenvalues as one might do in a scientific app (on large matrices) is umm... generally quite slow.Originally posted by Bubba
Well since DirectX and about a ton of other graphics APIs including OpenGL use matrices to do 3D graphics, I'm fairly sure that they are not where the slow-down in code is going to be. OpenGL and I think DX create a 1 dimensional 4x4 matrix - like I showed before - and then concatenate them .
Though I agree that a linear array is the way to go. You might want to look at making the size a template parameter as well. Then you'd know size constraints, etc. at compile-time.
Cheers
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
You could do something like that this way:Originally posted by Zach L.
You might want to look at making the size a template parameter as well. Then you'd know size constraints, etc. at compile-time.
As for matricies vs. arrays - consider the following:Code:template<int rows, int cols, typename T=double>
ggCode:#include <iostream> #include <cstring> using namespace std; int main() { int matrix[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; int array[9] = {1,2,3,4,5,6,7,8,9}; if (memcmp(matrix, array, 9*sizeof(int)) == 0) cout << "Same" << endl; else cout << "Different" << endl; return 0; }//main
#1.
#2.Code:union { struct { float m11,m12,m13,m21,m22,m23,m31,m32,m33; }; float m[3][3]; };
You can round, but you can't round to the units place, else 0.5 =1. It is simpler to just write
Code:bool eqflt(float a,float b,float tol) { if(fabs(tol)>fabs(a-b)) return true; return false; } if(eqflt(mag(vector),1.0f,0.00001f)) printf("normalized");
docs: how to ask | OpenGL | Xlib | IA32 | assembly | server | pthreads | sockets
tricks: sqrt | complex mul | pow | polynomial
philosophy: dictionary | uncleal | maddox | bible