mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 11:31:20 +00:00
Particle Struct
This commit is contained in:
parent
27c914d132
commit
8a54b8810d
@ -72,6 +72,8 @@ namespace
|
|||||||
bool active;
|
bool active;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<std::vector<Particle>> particleSystems;
|
||||||
|
|
||||||
ToolAnimation swing;
|
ToolAnimation swing;
|
||||||
|
|
||||||
int currentPoint = 0; // VERY lazy way of tracking light balls
|
int currentPoint = 0; // VERY lazy way of tracking light balls
|
||||||
@ -246,7 +248,7 @@ void Viewer::draw()
|
|||||||
root.accept(*this);
|
root.accept(*this);
|
||||||
|
|
||||||
drawParticles();
|
drawParticles();
|
||||||
drawUi();
|
drawUi();
|
||||||
|
|
||||||
sunRotate.setToIdentity();
|
sunRotate.setToIdentity();
|
||||||
//float rotAngle = (frame * angle_mult) % 360;
|
//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(){
|
void Viewer::drawParticles(){
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
|
|
||||||
@ -338,22 +365,34 @@ void Viewer::drawParticles(){
|
|||||||
camera()->getProjectionMatrix(projectionMatrix);
|
camera()->getProjectionMatrix(projectionMatrix);
|
||||||
camera()->getModelViewMatrix(modelViewMatrix);
|
camera()->getModelViewMatrix(modelViewMatrix);
|
||||||
|
|
||||||
glBindVertexArray(m_VAOs[VAO_Particle]);
|
modelViewMatrix.scale(4);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle_Positions);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_Particle_Colors);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
// glBindVertexArray(m_VAOs[VAO_Particle]);
|
||||||
TexturePrograms[1]->bind();
|
// 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);
|
// glActiveTexture(GL_TEXTURE0);
|
||||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
// TexturePrograms[1]->bind();
|
||||||
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);
|
|
||||||
|
|
||||||
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) {
|
void Viewer::mouseMoveEvent(QMouseEvent* e) {
|
||||||
|
|||||||
@ -43,6 +43,11 @@ struct PickedGeom {
|
|||||||
QMatrix4x4 position;
|
QMatrix4x4 position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Particle {
|
||||||
|
QVector3D pos, speed, accel;
|
||||||
|
double life, size, weight;
|
||||||
|
};
|
||||||
|
|
||||||
class Viewer : public QGLViewer,
|
class Viewer : public QGLViewer,
|
||||||
protected QOpenGLFunctions_4_0_Core,
|
protected QOpenGLFunctions_4_0_Core,
|
||||||
public Visitor
|
public Visitor
|
||||||
@ -111,6 +116,7 @@ private:
|
|||||||
void deselect();
|
void deselect();
|
||||||
void loadToolObj();
|
void loadToolObj();
|
||||||
void startSwingAnimation();
|
void startSwingAnimation();
|
||||||
|
std::vector<Particle> createParticleSystem(QMatrix4x4 parent);
|
||||||
PickedGeom pickGeom(int, int);
|
PickedGeom pickGeom(int, int);
|
||||||
|
|
||||||
void animate();
|
void animate();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user