-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDust.cpp
More file actions
122 lines (106 loc) · 2.71 KB
/
Dust.cpp
File metadata and controls
122 lines (106 loc) · 2.71 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "stdafx.h"
#include "Dust.h"
classDust::classDust(vpObserver *_observer, vsChannel::Subscriber *_subscriber):classBase(_observer,_subscriber,ENABLE_KEY|ENABLE_RUNLOOP)
{
initDust();
}
classDust::classDust(const char* _name, vsChannel::Subscriber *_subscriber):classBase(_name,_subscriber,ENABLE_KEY|ENABLE_RUNLOOP)
{
initDust();
}
classDust::~classDust(void)
{
pFxParticleSystem->setEnable(false);
pFxParticleSystem->unref();
pIsectorHAT->setEnable(false);
pIsectorHAT->setTarget(NULL);
pIsectorHAT->unref();
density = 0;
isEnable = false;
}
void classDust::initDust(void)
{
pIsectorHAT = NULL;
pIsectorHAT = vpIsectorHAT::find("myIsector");
if (pIsectorHAT == NULL)
{std::cout << "Dust: pIsectorHAT(\"myIsector\") is NULL!" << std::endl;system("pause");}
pIsectorHAT->setEnable(false);
pIsectorHAT->setTarget(pObject);
pIsectorHAT->ref();
pFxParticleSystem = NULL;
pFxParticleSystem = vpFxParticleSystem::find("myFx");
if (pFxParticleSystem == NULL)
{std::cout << "Dust: pFxParticleSystem(\"myFx\") is NULL!" << std::endl;system("pause");}
pFxParticleSystem->setEnable(false);
pFxParticleSystem->ref();
density = 0;
isEnable = false;
}
void classDust::dustGo(void)
{
if(isEnable == true)
{
pFxParticleSystem->setRenderMask(1);
if (!pIsectorHAT->getEnable())
pIsectorHAT->setEnable(true);
pObserver->getPosition(&position[0],&position[1],&position[2]);
pIsectorHAT->setTranslate(position[0], position[1], position[2]);
double height = 1000.0f;
if(pIsectorHAT->getHit())
height = pIsectorHAT->getHAT();
if(height <= 50.0f)
{
float offset = 0 - height - height - (19 - density)*2; //density影响粒子团的位置,利用地形的遮挡而影响场景中的例子数量
pFxParticleSystem->setTranslate(position[0],position[1],position[2] + offset);
if (!pFxParticleSystem->getEnable())
pFxParticleSystem->setEnable(true);
}
else
pFxParticleSystem->setEnable(false);
}
else
{
if (pFxParticleSystem->getEnable())
pFxParticleSystem->setEnable(false);
if (pIsectorHAT->getEnable())
pIsectorHAT->setEnable(false);
}
}
void classDust::handleKey(vrWindow::Key _key, int _mod)
{
switch (_key)
{
case vrWindow::KEY_x:
isEnable = !isEnable;
if (density == 0) isEnable = false;
std::cout << "Dust Enable: " << isEnable << std::endl;
break;
case vrWindow::KEY_a:
density = density > 19 ? 19 : (density + 1);
break;
case vrWindow::KEY_z:
density = density <= 0 ? 0 : (density - 1);
break;
}
}
void classDust::handleRunLoop(void)
{
dustGo();
}
void classDust::dustSwitch(bool _enable)
{
isEnable = _enable;
}
void classDust::setDensity(float _density)
{
if (_density <= 0)
{
dustSwitch(false);
_density = 0;
}
else
{
dustSwitch(true);
density = _density;
}
}