diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo
index 4c2d463..814dadc 100644
Binary files a/.vs/3dMath/v15/.suo and b/.vs/3dMath/v15/.suo differ
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