mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Particle Struct
This commit is contained in:
parent
27c914d132
commit
8a54b8810d
@ -72,6 +72,8 @@ namespace
|
||||
bool active;
|
||||
};
|
||||
|
||||
std::vector<std::vector<Particle>> particleSystems;
|
||||
|
||||
ToolAnimation swing;
|
||||
|
||||
int currentPoint = 0; // VERY lazy way of tracking light balls
|
||||
@ -246,7 +248,7 @@ void Viewer::draw()
|
||||
root.accept(*this);
|
||||
|
||||
drawParticles();
|
||||
drawUi();
|
||||
drawUi();
|
||||
|
||||
sunRotate.setToIdentity();
|
||||
//float rotAngle = (frame * angle_mult) % 360;
|
||||
@ -330,6 +332,31 @@ void Viewer::drawUi(){
|
||||
|
||||
}
|
||||
|
||||
std::vector<Particle> Viewer::createParticleSystem(QMatrix4x4 parentModel) {
|
||||
std::vector<Particle> pSys;
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
Particle p;
|
||||
|
||||
float x = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
float y = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
float z = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
float w = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
float ts = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
|
||||
p.pos = parentModel * QVector3D();
|
||||
p.accel = QVector3D(0.5 * x, 0.5 * y, 0.5 * z);
|
||||
p.pos = QVector3D(x, y, z);
|
||||
p.weight = w;
|
||||
p.size = ts/2;
|
||||
p.life = rand() % 1000;
|
||||
|
||||
pSys.push_back(p);
|
||||
}
|
||||
|
||||
return pSys;
|
||||
}
|
||||
|
||||
void Viewer::drawParticles(){
|
||||
m_program->bind();
|
||||
|
||||
@ -338,22 +365,34 @@ void Viewer::drawParticles(){
|
||||
camera()->getProjectionMatrix(projectionMatrix);
|
||||
camera()->getModelViewMatrix(modelViewMatrix);
|
||||
|
||||
glBindVertexArray(m_VAOs[VAO_Particle]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle_Positions);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle_Colors);
|
||||
modelViewMatrix.scale(4);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
TexturePrograms[1]->bind();
|
||||
// glBindVertexArray(m_VAOs[VAO_Particle]);
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle);
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle_Positions);
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle_Colors);
|
||||
|
||||
m_program->setUniformValue(m_isSkyLoc, true);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255));
|
||||
m_program->setUniformValue(m_drawTextLoc, false);
|
||||
m_program->setUniformValue(m_isLightLoc, true);
|
||||
// glActiveTexture(GL_TEXTURE0);
|
||||
// TexturePrograms[1]->bind();
|
||||
|
||||
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, particleLimit);
|
||||
// m_program->setUniformValue(m_isSkyLoc, false);
|
||||
// m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
// m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
// m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255));
|
||||
// m_program->setUniformValue(m_drawTextLoc, false);
|
||||
// m_program->setUniformValue(m_isLightLoc, true);
|
||||
|
||||
// for(int )
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
TexturePrograms[0]->bind();
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, particleLimit);
|
||||
|
||||
glEnable( GL_CULL_FACE );
|
||||
}
|
||||
|
||||
void Viewer::mouseMoveEvent(QMouseEvent* e) {
|
||||
|
||||
@ -43,6 +43,11 @@ struct PickedGeom {
|
||||
QMatrix4x4 position;
|
||||
};
|
||||
|
||||
struct Particle {
|
||||
QVector3D pos, speed, accel;
|
||||
double life, size, weight;
|
||||
};
|
||||
|
||||
class Viewer : public QGLViewer,
|
||||
protected QOpenGLFunctions_4_0_Core,
|
||||
public Visitor
|
||||
@ -111,6 +116,7 @@ private:
|
||||
void deselect();
|
||||
void loadToolObj();
|
||||
void startSwingAnimation();
|
||||
std::vector<Particle> createParticleSystem(QMatrix4x4 parent);
|
||||
PickedGeom pickGeom(int, int);
|
||||
|
||||
void animate();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user