-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.hpp
82 lines (71 loc) · 2.06 KB
/
target.hpp
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
#include "DxLib.h"
#include <time.h>
#include "parameter.h"
class TARGET{
private:
int ModelHandle;
bool dflag;
float x, y, z;
float rotate;
//inline--start
void getRand();
//inline--end
public:
//inline--start
TARGET(void);
~TARGET();
void newTarget();
void delTarget();
void display();
int getModelHandle();
bool collision(VECTOR pos, VECTOR rotate);
//inline--end
};
//private--start
inline void TARGET :: getRand(){
x = (float)(((MAX_X-500.0f)-(MIN_X+500.0f)+1.0f)*((double)rand()/(double)(RAND_MAX+0.1f))+(MIN_X+500.0f));
y = (float)(((MAX_Y-150.0f)-MIN_Y+1.0f)*((double)rand()/(double)(RAND_MAX+0.1f))+MIN_Y+50);
z = (float)(((MAX_Z-500.0f)-(MIN_Z+500.0f)+1.0f)*((double)rand()/(double)(RAND_MAX+0.1f))+(MIN_Z+500.0f));
rotate = (float)((2*PI+1.0f)*((double)rand()/(double)(RAND_MAX+0.1f)));
}
//private--end
//public--start
inline TARGET :: TARGET(void){
srand((unsigned)time(NULL));
ModelHandle = MV1LoadModel("model\\target\\target.mqo");
MV1SetScale(ModelHandle, VGet(3.0f, 3.0f, 3.0f));
}
inline TARGET :: ~TARGET(){
MV1TerminateCollInfo(ModelHandle, -1);
MV1DeleteModel(ModelHandle);
}
inline void TARGET :: newTarget(){
dflag = true;
getRand();
MV1SetPosition(ModelHandle, VGet(x, y, z));
MV1SetRotationXYZ(ModelHandle, VGet(0, rotate, 0));
MV1SetupCollInfo(ModelHandle, -1, 8, 8, 8);
}
inline void TARGET :: delTarget(){
dflag = false;
MV1TerminateCollInfo(ModelHandle, -1);
}
inline void TARGET :: display(){
if(dflag)
MV1DrawModel(ModelHandle);
}
inline int TARGET :: getModelHandle(){
return ModelHandle;
}
inline bool TARGET :: collision(VECTOR pos, VECTOR rotate){
VECTOR pos1 = VGet(pos.x+600*sinf(rotate.y), pos.y+100.0f+200.0f-500*sinf(rotate.x), pos.z+600*cosf(rotate.y));
VECTOR pos2 = VGet(pos.x-200*sinf(rotate.y), pos.y+100.0f+200.0f+500*sinf(rotate.x), pos.z-200*cosf(rotate.y));
MV1_COLL_RESULT_POLY_DIM result = MV1CollCheck_Capsule(ModelHandle, -1, pos1, pos2, 210.0f);
if(result.HitNum > 0){
MV1CollResultPolyDimTerminate(result);
return true;
}
MV1CollResultPolyDimTerminate(result);
return false;
}
//public--end