From d90393c6345a3afa80648d29886cd002fc02b648 Mon Sep 17 00:00:00 2001 From: blobt Date: Thu, 25 Mar 2021 14:30:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9FTS=E7=9A=84=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/3dMath/v15/.suo | Bin 39936 -> 43520 bytes 3dMath.vcxproj | 1 + 3dMath.vcxproj.filters | 3 ++ CFloat32Array.h | 46 ++++++++++++++++++++++++++++ GMath.cpp | 4 +-- main.cpp | 68 ++++++++++++++++++++++++++++------------- 6 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 CFloat32Array.h diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo index 4c2d4636dbd6fb59bba7a141b743462985c5dd3b..814dadc6b5e4e33d8435759b2d97ded964657a1e 100644 GIT binary patch delta 5064 zcmds4drX_x6~FhhO$>bIWk?{9U_uB6T;c~0hf*-Xp%n0IaY!SQ5H~h~;qd&dm27KC zwXJGLQu3X3tI+z&x~i>~wTaiY+p@(jp=~Ro=oFi&^2A zaE$)}ZU}B2zlBAEQmWy2%~nkxGOaM9>e2BWB=1RY`!zBz!IG*nP>56>!id<0$VB8K zG7v?Ge1sn1LD0}NR5{`kVzBH+x-8K~Jjpkt@mXNelxAipBwFO|*WQa_T)Qx)C(k16cPUdcmjG=NBiW)Iy~c2aC!=UqUsph0!xvWp_(8>qO?!KXgz{dRFaU9is;{hL`^Cp)sVVKzA;gg>rUzUL6%Ma&^i zAZYHVu%1VpLY#wLS%)9|NuuQp);~?q)RXWg@=?Uk5N{!Vj!3rsB0>KuP4*k4FCbzF zIlD|peSeR%^3N&XRaxxTCN)Gh%g;kZbi*aV!ry=!qDLeZs}T5~V$}R~i0C{bX}dN} z42wF`|NR#8zr~lLGX;-xdCMhI5iD-;D792MCzo~Vlxv#2Bcx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atkLlW#5je3BKuEFe9YMe=;-hj#dVFi|aqcXjiV6#pP zl*7$$6p0iA1E#88S8w$}SrB`6uw;g~np2?b3We)6S}@l{Jl~1i)<9~ojh(g@vIwz; zY`|NDl^ckLq$8T$J#POxHPwk$HpXLNV%3ab>L|5jxcj1EI&CJc#6jAiuQoE>iL;fE za$+Y=(uV)pg7pQ67NWy%1KCVAk#=muUT~?_#21od$z^e0v$-hzSz8^zZf%M&9^RD( zFV<-ULmqrzR|VPiyJ1KD(`W2$eyFVZgzW=D@<=eA3qqLS$_XSi_QA{hH-Zx8L6D<1 zX1&2-v}ZPC>DOgs=IG51vr(UA@5s!y3mFh~*fRx=Tr_qa%WRF-9thiC;Xc3=QiB3Y z%I(gkMNKg?TuBpZKp}xU+sC_4zX#5<=N(s2r3V>Jw*K$BgM* z%MRYALffnt1yhP7bVpJQm$Q9}j)^mpl8maeftICMZgmtApEV$9~_iz*!sZ~;vC@r~#jZtTP%(<(ZJW(*|Z zFtQI*(UE6lLh@N<=e3jVRkVFi|FV103znSQHLKK(6l+|XXD7J-j|UR_?;Veyp8Veb zgFdkh_b9vV_}EdrXfhh3*n7&8lw*=6TYb)XNRUTU8d_V`s46O%RDjy&KAG*YG;)~x E3ug7l$p8QV diff --git a/3dMath.vcxproj b/3dMath.vcxproj index 49eedf2..aec4406 100644 --- a/3dMath.vcxproj +++ b/3dMath.vcxproj @@ -125,6 +125,7 @@ + diff --git a/3dMath.vcxproj.filters b/3dMath.vcxproj.filters index d3aa178..afcc776 100644 --- a/3dMath.vcxproj.filters +++ b/3dMath.vcxproj.filters @@ -24,6 +24,9 @@ 头文件 + + 头文件 + diff --git a/CFloat32Array.h b/CFloat32Array.h new file mode 100644 index 0000000..35e40ac --- /dev/null +++ b/CFloat32Array.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include "CArrayBuffer.h" +#include "CDataView.h" + +class CFloat32Array { +public: + CArrayBuffer* buffer; + int byteOffset; + int byteLength; + +private: + int _length; + bool _deleteBuffer; + +public: + CFloat32Array(int length) { + this->buffer = new CArrayBuffer(length * sizeof(float32)); + this->_length = length; + this->_deleteBuffer = true; + } + + CFloat32Array(CArrayBuffer* buffer, int byteOffset, int length) { + this->buffer = buffer; + this->byteOffset = byteOffset; + this->_length = length; + this->byteLength = length * sizeof(float32); + this->_deleteBuffer = false; + } + + ~CFloat32Array() { + if (this->_deleteBuffer) { + delete this->buffer; + this->buffer = nullptr; + printf("delete"); + } + } + + float32& operator [](int idx) { + return *((float32*)(this->buffer->pData + (this->byteOffset + idx * sizeof(float32)))); + } + + int length() { + return this->_length; + } +}; \ No newline at end of file diff --git a/GMath.cpp b/GMath.cpp index 50e40c4..ecf0c5c 100644 --- a/GMath.cpp +++ b/GMath.cpp @@ -452,7 +452,7 @@ GVector operator*(const float & k, const GVector & rhs) { GVector ret(rhs.n); for (int i = 0; i < ret.n; i++) { - ret.v[i] *= k; + ret.v[i] = rhs[i] * k; } return ret; } @@ -461,7 +461,7 @@ GVector operator*(const GVector & lhs, const float & k) { GVector ret(lhs.n); for (int i = 0; i < ret.n; i++) { - ret.v[i] *= k; + ret.v[i] = lhs[i] * k; } return ret; } diff --git a/main.cpp b/main.cpp index 2c268b3..6f0a7bb 100644 --- a/main.cpp +++ b/main.cpp @@ -1,42 +1,66 @@ #include "GMath.h" #include "CArrayBuffer.h" #include "CDataView.h" +#include "CFloat32Array.h" int main() { - CArrayBuffer buffer(16); - CDataView view0(&buffer, 0, buffer.byteLength()); + printf("arr0 ÄÚ²¿Éú³ÉCArrayBuffer\n"); + CFloat32Array arr0(8); + for (int i = 0; i < arr0.length(); i++) { + arr0[i] = i * 100.0; + } + for (int i = 0; i < arr0.length(); i++) { + printf("%f\n", arr0[i]); + } - view0.setFloat32(8, 99.99); - view0.setUint16(8 + 4, 2048); + printf("arr1 ¹²Ïí arr0 ÖÐ CArrayBuffer µÄ²¿·ÖÇø¿é\n"); + CFloat32Array arr1(arr0.buffer, 4 * sizeof(float32), 4); + for (int i = 0; i < arr1.length(); i++) { + printf("%f\n", arr1[i]); + } - printf("%f\n", view0.getFloat32(8)); - printf("%d\n", view0.getUint16(8+4)); + printf("ÖØÖÃarr1µÄ¸÷¸öÔªËØΪ10.0µÄ±¶Êý\n"); + for (int i = 0; i < arr1.length(); i++) { + arr1[i] = i * 10.0; + } + for (int i = 0; i < arr1.length(); i++) { + printf("%f\n", arr1[i]); + } - CDataView view1(&buffer, 8, 18); + /*GVector l(3); + l += 2; + cout << l*3 << endl; - printf("%f\n", view1.getFloat32(0)); - printf("%d\n", view1.getUint16(4)); - - /*float a[] = { - 2, 2, 2, 2, - 3, 3, 3, 3, - 4, 4, 4, 4, - 5, 5, 5, 5 + float a[] = { + 2, -1, 3, + 4, -2, 5, + 6, -3, 8 }; - GMatrix A(4, 4, a); + GMatrix A(3, 3, a); float b[] = { - 2, - 2, - 2, - 2 + 2, -1, 9, + 2, -2, 5, + 3, 1, 2 }; - GMatrix B(4, 1, b); + GMatrix B(3, 3, b); + GMatrix C = A*B; - cout << A*B << endl;*/ + cout << A << endl; + cout << B << endl; + cout << C << endl; + GVector ret(3); + GVector rv = B.GetColVec(1); + for (int i = 0; i < A.GetColNum(); i++) { + GVector l = A.GetColVec(i); + ret += rv[i]*l; + } + + cout << ret << endl; + */ /*float a[] = { 1,0, 1,4