-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasedefine3d.h
97 lines (83 loc) · 2.47 KB
/
basedefine3d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include"basedefine.h"
#ifndef BASE_DEFINE_3D
#define BASE_DEFINE_3D
#else
#error has been defined 'BASE_DEFINE_3D'
#endif // !BASE_DEFINE_3D
namespace My3D
{
class Vertex3f;
class Normal;
//空间点
class Vertex3f
{
private:
float *data=new float[3];
public:
float &x = data[0];
float &y = data[1];
float &z = data[2];
Vertex3f();
Vertex3f(float x,float y,float z);
Vertex3f(Vector3<float>&v);
Vertex3f(float *arr);
Vertex3f(Vertex3f&v);
virtual~Vertex3f();
float* getDataArray();
Normal* operator-(Vertex3f&v);
void operator+=(Vertex3f&v);
void operator-=(Vertex3f&v);
void operator=(Vertex3f&v);
bool operator==(Vertex3f&v);
Vertex3f* getNagtive();
void toNagtive();
};
//空间矢量
class Normal:public Vertex3f
{
public:
Normal();
Normal(float x, float y, float z);
Normal(Vector3<float>&v);
Normal(float *arr);
Normal(Normal&nor);
~Normal() { };
//点乘
float operator*(Normal&nor);
//叉乘
Normal* operator*(Normal* n);
Normal* operator+(Normal&v);
Normal* operator-(Normal&v);
void operator+=(Normal&v);
void operator-=(Normal&v);
void operator=(Normal&n);
bool operator==(Normal&n);
Normal* getNagtive();
void toIdentity();
Normal* getIdentity();
float length();
float cos(Normal&n);
};
//坐标轴 单位方向向量
const static Normal identityNormalX(1.0f,0.0f,0.0f);
const static Normal identityNormalXNag(-1.0f, 0.0f, 0.0f);
const static Normal identityNormalY(0.0f, 1.0f, 0.0f);
const static Normal identityNormalYNag(0.0f, -1.0f, 0.0f);
const static Normal identityNormalZ(0.0f, 0.0f, 1.0f);
const static Normal identityNormalZNag(0.0f, 0.0f, -1.0f);
//opengl 坐标系 右手坐标 单位方向向量
const static Normal& glUpNormal = identityNormalY;
const static Normal& glDownNormal = identityNormalYNag;
const static Normal& glFrontNoraml = identityNormalZNag;
const static Normal& glBackNormal = identityNormalZ;
const static Normal& glLeftNormal = identityNormalXNag;
const static Normal& glRightNormal = identityNormalX;
//directx 坐标系 左手坐标 单位方向向量
const static Normal& dirUpNormal = identityNormalY;
const static Normal& dirDownNormal = identityNormalYNag;
const static Normal& dirLeftNormal = identityNormalXNag;
const static Normal& dirRightNormal = identityNormalX;
const static Normal& dirBackNoraml = identityNormalZNag;
const static Normal& dirFrontNormal = identityNormalZ;
}