-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRain.cpp
More file actions
161 lines (132 loc) · 4.89 KB
/
Rain.cpp
File metadata and controls
161 lines (132 loc) · 4.89 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "stdafx.h"
#include "Rain.h"
classRain::classRain(vpObserver *_observer, vsChannel::Subscriber *_subscriber):classBase(_observer,_subscriber,ENABLE_KEY|ENABLE_DRAWEVENT),RainLevel(classRain::GREEN)
{
pParticleSystem = new ParticleSystem();
init_flag = false;
if(_subscriber != NULL) //添加事件只能在app->configure函数中进行,这里兼顾了通过classDve导入和单独导入的情况
addEvent(vsChannel::EVENT_POST_DRAW);
pParticleSystem->environmentData.total = 200;
pParticleSystem->environmentData.tex = 0;
pParticleSystem->environmentData.areaRange = 200;
pParticleSystem->environmentData.areaCenter = vuVec3d(0.0, 0.0, 0.0);
pParticleSystem->environmentData.rotate = vuVec3d(0.0, 0.0, 0.0);
pParticleSystem->particleData.life = 800;
pParticleSystem->particleData.fade = 1;
pParticleSystem->particleData.scale = vuVec3d(1.0, 1.0, 1.0);
pParticleSystem->particleData.a = vuVec3d(0.0, 0.0, 0.0);
pParticleSystem->particleData.dimension = vuVec3d(1.0, 1.0, 1.0);
setRainLevel(RainLevel);
}
classRain::classRain(const char* _name, vsChannel::Subscriber *_subscriber):classBase(_name,_subscriber,ENABLE_KEY|ENABLE_DRAWEVENT),RainLevel(classRain::GREEN)
{
pParticleSystem = new ParticleSystem();
init_flag = false;
if(_subscriber != NULL) //添加事件只能在app->configure函数中进行,这里兼顾了通过classDve导入和单独导入的情况
addEvent(vsChannel::EVENT_POST_DRAW);
pParticleSystem->environmentData.total = 4000;
pParticleSystem->environmentData.tex = 0;
pParticleSystem->environmentData.areaRange = 200;
pParticleSystem->environmentData.areaCenter = vuVec3d(0.0, 0.0, 0.0);
pParticleSystem->environmentData.rotate = vuVec3d(0.0, 0.0, 0.0);
pParticleSystem->particleData.life = 800;
pParticleSystem->particleData.fade = 1;
pParticleSystem->particleData.scale = vuVec3d(1.0, 1.0, 1.0);
pParticleSystem->particleData.a = vuVec3d(0.0, 0.0, 0.0);
pParticleSystem->particleData.dimension = vuVec3d(1.0, 1.0, 1.0);
setRainLevel(RainLevel);
}
classRain::~classRain()
{
delete pParticleSystem;
if(pSubscriber != NULL)
removeEvent(vsChannel::EVENT_POST_DRAW);
}
void classRain::setRainLevel(weatherLevel _rainLevel)
{
RainLevel = _rainLevel;
switch(_rainLevel)
{
case GREEN:
pParticleSystem->particleData.scale = vuVec3d(0.1, 0.1, 0.3);
pParticleSystem->particleData.v = vuVec3d(0.0, 0.0, 0.0);
break;
case BLUE:
{
pParticleSystem->particleData.scale = vuVec3d(0.1, 0.1, 0.3);
pParticleSystem->particleData.v = vuVec3d(0.0, 0.0, -2.0);
pParticleSystem->particleData.life = 100;
}
break;
case YELLOW:
{
pParticleSystem->particleData.scale = vuVec3d(0.15, 0.15, 0.45);
pParticleSystem->particleData.v = vuVec3d(0.0, 0.0, -3.0);
pParticleSystem->particleData.life = 66;
}
break;
case ORANGE:
{
pParticleSystem->particleData.scale = vuVec3d(0.20, 0.20, 0.60);
pParticleSystem->particleData.v = vuVec3d(0.0, 0.0, -4.0);
pParticleSystem->particleData.life = 50;
}
break;
case RED:
{
pParticleSystem->particleData.scale = vuVec3d(0.25, 0.25, 0.75);
pParticleSystem->particleData.v = vuVec3d(0.0, 0.0, -5.0);
pParticleSystem->particleData.life = 40;
}
break;
}
}
void classRain::handleKey(vrWindow::Key _key, int _mod)
{
switch(_key)
{
case vrWindow::KEY_F3:
if(RainLevel == GREEN)
RainLevel = BLUE;
else if(RainLevel == BLUE)
RainLevel = YELLOW;
else if(RainLevel == YELLOW)
RainLevel = ORANGE;
else if(RainLevel == ORANGE)
RainLevel = RED;
else
RainLevel = GREEN;
setRainLevel(RainLevel);
break;
}
}
void classRain::handleDrawEvent(vsChannel::Event _event, const vsChannel *_channel, vrDrawContext *_context)
{
if(RainLevel == GREEN || _channel != pChannel || _event != vsChannel::EVENT_POST_DRAW)
return ;
if(init_flag == false)
{
pParticleSystem->initData();
init_flag = true;
}
vrTransform::ElementProjection projectionElement; //投影矩阵
projectionElement.m_matrix = _channel->getVrChannel()->getProjectionMatrix();
vrTransform::ElementModelView modelViewElement; //视图矩阵
modelViewElement.m_matrix = _channel->getVrChannel()->getViewMatrixInverse();
_context->pushElements(true); //将其他当前的图形状态压入堆栈
vuVec3d position,rotation;
pObserver->getPosition(&position[0],&position[1],&position[2]);
pObserver->getRotate(&rotation[0],&rotation[1],&rotation[2]);
_context->setElement(vrTransform::ElementProjection::Id,&projectionElement);
vuMatrixf rotMat1;
rotMat1.makeRotate(0,-90,0); //h、p、r
modelViewElement.m_matrix.postMultiply(rotMat1);//坐标系转换
_context->setElement(vrTransform::ElementModelView::Id,&modelViewElement);
position[0] = position[0]+180.0f*vuSin(vuDeg2Rad(-rotation[0]));
position[1] = position[1]+180.0f*vuCos(vuDeg2Rad(-rotation[0]));
position[2] = position[2]+60.0f;
pParticleSystem->environmentData.areaCenter = position;
pParticleSystem->environmentData.rotate = rotation;
pParticleSystem->draw();
_context->popElements(false);
}