|
@ -1,42 +1,66 @@ |
|
|
#include "GMath.h"
|
|
|
#include "GMath.h"
|
|
|
#include "CArrayBuffer.h"
|
|
|
#include "CArrayBuffer.h"
|
|
|
#include "CDataView.h"
|
|
|
#include "CDataView.h"
|
|
|
|
|
|
#include "CFloat32Array.h"
|
|
|
|
|
|
|
|
|
int main() { |
|
|
int main() { |
|
|
|
|
|
|
|
|
CArrayBuffer buffer(16); |
|
|
|
|
|
CDataView view0(&buffer, 0, buffer.byteLength()); |
|
|
|
|
|
|
|
|
|
|
|
view0.setFloat32(8, 99.99); |
|
|
|
|
|
view0.setUint16(8 + 4, 2048); |
|
|
|
|
|
|
|
|
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]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
printf("%f\n", view0.getFloat32(8)); |
|
|
|
|
|
printf("%d\n", view0.getUint16(8+4)); |
|
|
|
|
|
|
|
|
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]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
CDataView view1(&buffer, 8, 18); |
|
|
|
|
|
|
|
|
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]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
printf("%f\n", view1.getFloat32(0)); |
|
|
|
|
|
printf("%d\n", view1.getUint16(4)); |
|
|
|
|
|
|
|
|
/*GVector l(3);
|
|
|
|
|
|
l += 2; |
|
|
|
|
|
cout << l*3 << endl; |
|
|
|
|
|
|
|
|
/*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[] = { |
|
|
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[] = {
|
|
|
/*float a[] = {
|
|
|
1,0, |
|
|
1,0, |
|
|
1,4 |
|
|
1,4 |
|
|