Browse Source

用cpp

master
blobt 4 years ago
parent
commit
4b68848f12
  1. BIN
      .vs/3dMath/v15/.suo
  2. BIN
      .vs/3dMath/v15/Browse.VC.opendb
  3. 2
      3dMath.vcxproj
  4. 6
      3dMath.vcxproj.filters
  5. 23
      CArrayBuffer.h
  6. 36
      CDataView.h
  7. 37
      main.cpp

BIN
.vs/3dMath/v15/.suo

BIN
.vs/3dMath/v15/Browse.VC.opendb

2
3dMath.vcxproj

@ -123,6 +123,8 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="CArrayBuffer.h" />
<ClInclude Include="CDataView.h" />
<ClInclude Include="GMath.h" />
</ItemGroup>
<ItemGroup>

6
3dMath.vcxproj.filters

@ -18,6 +18,12 @@
<ClInclude Include="GMath.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CArrayBuffer.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CDataView.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="GMath.cpp">

23
CArrayBuffer.h

@ -0,0 +1,23 @@
#pragma once
typedef unsigned char Byte;
class CArrayBuffer {
public:
CArrayBuffer(int byteLength = 8) {
this->_byteLenght = byteLength;
this->pData = new Byte[this->_byteLenght];
}
~CArrayBuffer() {
if (this->pData != nullptr) {
delete[] this->pData;
this->pData = nullptr;
}
}
int byteLength() {
return this->_byteLenght;
}
public:
Byte *pData;
private:
int _byteLenght;
};

36
CDataView.h

@ -0,0 +1,36 @@
#pragma once
#include <cstring>
#include "CArrayBuffer.h"
typedef unsigned short uint16;
typedef float float32;
class CDataView {
public:
CArrayBuffer* buffer;
int byteOffset;
int byteLength;
CDataView(CArrayBuffer* pBuffer, int byteOffset, int byteLength) {
this->buffer = pBuffer;
this->byteOffset = byteOffset;
this->byteLength = byteLength;
}
void setFloat32(int offset, float32 value) {
memcpy(this->buffer->pData + (this->byteOffset + offset), &value, sizeof(float32));
}
float32 getFloat32(int offset) {
return *((float32*)(this->buffer->pData + (this->byteOffset + offset)));
}
void setUint16(int offset, uint16 value) {
memcpy(this->buffer->pData + (this->byteOffset + offset), &value, sizeof(uint16));
}
uint16 getUint16(int offset) {
return *((uint16*)(this->buffer->pData + (this->byteOffset + offset)));
}
};

37
main.cpp

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

Loading…
Cancel
Save