-
Notifications
You must be signed in to change notification settings - Fork 7
/
ParticleSystem.h
133 lines (120 loc) · 3.7 KB
/
ParticleSystem.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
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
//
// ParticleSystem.hpp
// pubg
//
// Created by Candy on 15/01/2018.
// Copyright © 2018 Candy. All rights reserved.
//
#ifndef ParticleSystem_h
#define ParticleSystem_h
#define M_PI 3.14159265358979323846
#define DEGTORAD(d) ((d * (double)M_PI) / 180.0f);
#define RADTODEG(r) ((r * 180.0f) /(double)M_PI);
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <math.h>
#include <ctime>
#include <iostream>
#include <GL/glew.h>
#include "shader.h"
//#include "model.h"
//#include <stdlib.h>
//#include <glut/glut.h>
//#include <time.h>
class mVector3d{
public:
mVector3d():x(0), y(0), z(0){}
mVector3d(double x1, double y1, double z1):x(x1), y(y1), z(z1){}
mVector3d(const mVector3d &v){ x = v.x; y = v.y; z = v.z; }
~mVector3d(){}
void operator=(const mVector3d &v){ x = v.x; y = v.y; z = v.z; }
mVector3d operator+(const mVector3d &v){ return mVector3d(x+v.x, y+v.y, z+v.z); }
mVector3d operator-(const mVector3d &v){ return mVector3d(x-v.x, y-v.y, z-v.z); }
mVector3d operator+(double d){ return mVector3d(x+d, y+d, z+d); }
mVector3d operator-(double d){ return mVector3d(x-d, y-d, z-d); }
mVector3d operator*(double d){ return mVector3d(x*d, y*d, z*d); }
public:
double x, y, z;
};
struct tParticle{
tParticle *prev,*next;
mVector3d pos;
mVector3d direction;
int restLife;
void draw(GLuint VAO, mVector3d location, Shader& bloodShader);
};
class tEmitter
{
public:
tEmitter();
~tEmitter();
void addParticle();
void updateParticle(tParticle *particle);
public:
mVector3d pos; //发射器位置
mVector3d direction; //发射器喷射主方向
// 通过球坐标系随机产生指定方向范围内的速度分量
double voy_max, voy_min;
double vox_max, vox_min;
double speed_max, speed_min;
//粒子设置信息
tParticle *ptcPool;
tParticle *ptc; //指向当前活跃粒子链表
int totalPtc; // 粒子库粒子总数
int curPtc; // 当前粒子数
int pfPtc_max, pfPtc_min; // 每一帧添加粒子数变化范围
int life_max, life_min; // 粒子初始生命值变化范围
mVector3d force; // 三坐标轴速度变化率
};
class ParticleSystem
{
public:
void addEmitter(mVector3d pos, mVector3d direction);
void updateEmitter(tEmitter * emitter);
void renderEmitter(Shader &bloodShader);
void load();
public:
std::vector<tEmitter> emitters;
GLuint VAO, VBO;
GLfloat vertices[108] = {
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f
};
};
void TransAndRotate(mVector3d pos, mVector3d destiny);
#endif /* ParticleSystem_h */