|
dev.gamez.lv Latvian Game Developers Community
|
View previous topic :: View next topic |
Author |
Message |
Angel
Joined: 02 Jan 2005 Posts: 113 Location: Latvija
|
Posted: Thu Apr 28, 2005 7:30 pm Post subject: Matricas... |
|
Paarbaudot matricu reizinaashanu, atklaajaas, ka peedeejais lauk netiek aizpildiits korekti
1st matrix:
1 | 0 | 0 | 0
0 | 1 | 0 | 0
0 | 0 | 1 | 0
0 | 0 | 0 | 1
2nd Matrix:
2 | 2 | 2 | 2
2 | 2 | 2 | 2
2 | 2 | 2 | 2
2 | 2 | 2 | 2
result:
2 | 2 | 2 | 2
2 | 2 | 2 | 2
2 | 2 | 2 | 2
2 | 2 | 2 | -1.07374e+008
Vai kaadam nav nojausmas kapeec taa???
Reizinaashana:
Code: |
cMatrix4x4 cMatrix4x4::operator *(const cMatrix4x4 &M){
cMatrix4x4 mMat;
// First Row
mMat._11 = _11*M._11 + _12*M._21 + _13*M._31 + _14*M._41;
mMat._12 = _11*M._12 + _12*M._22 + _13*M._32 + _14*M._42;
mMat._13 = _11*M._13 + _12*M._23 + _13*M._33 + _14*M._43;
mMat._14 = _11*M._14 + _12*M._24 + _13*M._34 + _14*M._44;
// Second Row
mMat._21 = _21*M._11 + _22*M._21 + _23*M._31 + _24*M._41;
mMat._22 = _21*M._12 + _22*M._22 + _23*M._32 + _24*M._42;
mMat._23 = _21*M._13 + _22*M._23 + _23*M._33 + _24*M._43;
mMat._24 = _21*M._14 + _22*M._24 + _23*M._34 + _24*M._44;
// Third Row
mMat._31 = _31*M._11 + _32*M._21 + _33*M._31 + _34*M._41;
mMat._32 = _31*M._12 + _32*M._22 + _33*M._32 + _34*M._42;
mMat._33 = _31*M._13 + _32*M._23 + _33*M._33 + _34*M._43;
mMat._34 = _31*M._14 + _32*M._24 + _33*M._34 + _34*M._44;
// Fourth Row
mMat._41 = _41*M._11 + _42*M._21 + _43*M._31 + _44*M._41;
mMat._42 = _41*M._12 + _42*M._22 + _43*M._32 + _44*M._42;
mMat._43 = _41*M._13 + _42*M._23 + _43*M._33 + _44*M._43;
mMat._44 = _41*M._14 + _42*M._24 + _43*M._34 + _44*M._44;
return mMat;
}
|
Uzraksta uz ekraana
Code: |
void WriteMatrix(cMatrix4x4 &mMat){
cout<<mMat._11<<" | "<<mMat._12<<" | "<<mMat._13<<" | "<<mMat._14<<endl;
cout<<mMat._21<<" | "<<mMat._22<<" | "<<mMat._23<<" | "<<mMat._24<<endl;
cout<<mMat._31<<" | "<<mMat._32<<" | "<<mMat._33<<" | "<<mMat._34<<endl;
cout<<mMat._41<<" | "<<mMat._42<<" | "<<mMat._43<<" | "<<mMat._44<<endl;
}
|
Matricas klasse
Code: |
class cMatrix4x4{
private:
public:
float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
float _41, _42, _43, _44;
|
|
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Fri Apr 29, 2005 8:33 am Post subject: |
|
Parādi kā inicializē matricas elementus, t.b. piešķir visas tās 0,1,2 vērtības. |
|
Back to top |
|
|
Angel
Joined: 02 Jan 2005 Posts: 113 Location: Latvija
|
Posted: Fri Apr 29, 2005 9:06 am Post subject: |
|
Code: | int main()
{
mMat = new cMatrix4x4[5];
float temp[16] = { 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
mMat[0] = cMatrix4x4(temp);
mMat[1] = mMat[0] * 4;
mMat[2] = matrix4.Identity();
mMat[3] = cMatrix4x4( 2,3,4,5,
4,5,6,7,
1,2,3,4,
1,4,7,2);
mMat[4] = mMat[0]*mMat[3];
Write("Matrix1: matrix from float[16]");
WriteMatrix(mMat[0]);
Write("Matrix2: matrix1 * 4");
WriteMatrix(mMat[1]);
Write("Matrix3: matrix4.identity()");
WriteMatrix(mMat[2]);
Write("Matrix4: matrix");
WriteMatrix(mMat[3]);
Write("Matrix5: Matrix1 * Matrix4");
WriteMatrix(mMat[4]);
cin.get();
} |
Sheit gan tas viss ir mazliet izplests, bet vienmeer kaa notiek kaada darbiiba pēdējā laukā paraadaas mistisks rezultaats un ja veel ar to matricu reizina(kurai ir tas mistiskais rezultaats), tad vairaakos laukos taads paraadaas
Code: | cMatrix4x4(){
_11 = 0; _12 = 0; _13 = 0; _14 = 0;
_21 = 0; _22 = 0; _23 = 0; _24 = 0;
_31 = 0; _32 = 0; _33 = 0; _34 = 0;
_41 = 0; _42 = 0; _43 = 0; _44 = 0;
}
cMatrix4x4(const cMatrix4x4 &M){
_11 = M._11; _12 = M._12; _13 = M._13; _14 = M._14;
_21 = M._21; _22 = M._22; _23 = M._23; _24 = M._24;
_31 = M._31; _32 = M._32; _33 = M._13; _34 = M._34;
_41 = M._41; _42 = M._42; _43 = M._43; _14 = M._44;
}
cMatrix4x4(const float a[16]){
_11=a[0]; _12=a[1]; _13=a[2]; _14=a[3];
_21=a[4]; _22=a[5]; _23=a[6]; _24=a[7];
_31=a[8]; _32=a[9]; _33=a[10]; _34=a[11];
_41=a[12]; _42=a[13]; _43=a[14]; _44=a[15];
}
cMatrix4x4(float f11, float f12, float f13, float f14,
float f21, float f22, float f23, float f24,
float f31, float f32, float f33, float f34,
float f41, float f42, float f43, float f44){
_11=f11; _12=f12; _13=f13; _14=f14;
_21=f21; _22=f22; _23=f23; _24=f24;
_31=f31; _32=f32; _33=f33; _34=f34;
_41=f41; _42=f42; _43=f43; _44=f44;
}
|
Varbuut sho arii vaig.... |
|
Back to top |
|
|
Janus
Joined: 01 Dec 2003 Posts: 7
|
Posted: Fri Apr 29, 2005 10:35 am Post subject: |
|
Un, ja tu neatgreiz lokālo variabli, bet taisi
Code: |
cMatrix4x4& cMatrix4x4::operator *(const cMatrix4x4 &M){
cMatrix4x4* mMat = new cMatrix4x4();
mMat->_11 = _11*M._11 + _12*M._21 + _13*M._31 + _14*M._41;
...
mMat->_44 = _41*M._14 + _42*M._24 + _43*M._34 + _44*M._44;
return *mMat;
}
|
kā tad izskatās? |
|
Back to top |
|
|
anggelus
Joined: 23 Feb 2005 Posts: 383 Location: Rīga (LV)
|
Posted: Fri Apr 29, 2005 10:49 am Post subject: |
|
nedomāju, ka tā ir laba doma izmantot new. Katru reizi reizinot matricas tiks rezervēta atmiņa un nekur netiks atbrīvota, tad padomā, ja matricu reizināšana notiek kaut vai vienu reizi kadrā, tad cik daudz atmiņas būs nepieciešams _________________ No comprendo lo que dice. |
|
Back to top |
|
|
Angel
Joined: 02 Jan 2005 Posts: 113 Location: Latvija
|
Posted: Fri Apr 29, 2005 2:04 pm Post subject: |
|
Probleema tika atrisinaata!!! Paarrakstiiju visu citaadaa veidaa |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|