Flames can now be skewed.
This commit is contained in:
parent
1c25df78d5
commit
09f4e3655a
17
flame.cc
17
flame.cc
@ -24,13 +24,24 @@ Flame::Flame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Flame::render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix, float time,
|
void Flame::render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix, float time,
|
||||||
bool withColor) {
|
bool withColor, glm::vec2 skewing) {
|
||||||
glm::mat4 modelMatrix;
|
glm::mat4 modelMatrix;
|
||||||
|
// matrix is column major
|
||||||
|
glm::mat4 skewMatrixX =
|
||||||
|
glm::mat4(1.0f, tan(skewing.x), 0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
glm::mat4 skewMatrixZ =
|
||||||
|
glm::mat4(1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, tan(skewing.y), 1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if (!withColor) {
|
if (!withColor) {
|
||||||
modelMatrix = glm::scale<float>(size * glm::vec3(1.1f));
|
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size * glm::vec3(1.1f));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
modelMatrix = glm::scale<float>(size);
|
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size);
|
||||||
}
|
}
|
||||||
glm::mat4 modelViewProjectionMatrix = viewProjectionMatrix * modelMatrix;
|
glm::mat4 modelViewProjectionMatrix = viewProjectionMatrix * modelMatrix;
|
||||||
shader->setUniform("modelViewProjectionMatrix", modelViewProjectionMatrix);
|
shader->setUniform("modelViewProjectionMatrix", modelViewProjectionMatrix);
|
||||||
|
2
flame.hh
2
flame.hh
@ -9,7 +9,7 @@ class Flame : public Entity {
|
|||||||
Flame(glm::vec3 position, glm::vec3 color, glm::vec3 size);
|
Flame(glm::vec3 position, glm::vec3 color, glm::vec3 size);
|
||||||
Flame();
|
Flame();
|
||||||
void render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix,
|
void render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix,
|
||||||
float time, bool withColor);
|
float time, bool withColor, glm::vec2 skewing);
|
||||||
private:
|
private:
|
||||||
glm::vec3 color;
|
glm::vec3 color;
|
||||||
glm::vec3 size;
|
glm::vec3 size;
|
||||||
|
@ -282,6 +282,9 @@ void Graphics::render(double time)
|
|||||||
framebuffer_light->bind();
|
framebuffer_light->bind();
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
//wind
|
||||||
|
glm::vec2 wind = glm::vec2(-0.4f, 0.3f);
|
||||||
|
|
||||||
//set view and projection matrix
|
//set view and projection matrix
|
||||||
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
|
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
|
||||||
|
|
||||||
@ -332,7 +335,7 @@ void Graphics::render(double time)
|
|||||||
// set Material Parameters
|
// set Material Parameters
|
||||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||||
lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition());
|
lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition());
|
||||||
lightingShader->setUniform("movement", glm::vec2(-0.3f, -0.4f));
|
lightingShader->setUniform("movement", wind);
|
||||||
lightingShader->setUniform("time", (float) time);
|
lightingShader->setUniform("time", (float) time);
|
||||||
|
|
||||||
// render the level
|
// render the level
|
||||||
@ -346,7 +349,7 @@ void Graphics::render(double time)
|
|||||||
|
|
||||||
// draw with colors
|
// draw with colors
|
||||||
for(unsigned int i = 0; i<closestFlames.size(); i++) {
|
for(unsigned int i = 0; i<closestFlames.size(); i++) {
|
||||||
closestFlames.at(i)->render(flameShader, lightingViewProjectionMatrix, float(time), true);
|
closestFlames.at(i)->render(flameShader, lightingViewProjectionMatrix, float(time), true, wind);
|
||||||
}
|
}
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
@ -358,7 +361,7 @@ void Graphics::render(double time)
|
|||||||
glClear(GL_STENCIL_BUFFER_BIT);//clear stencil buffer
|
glClear(GL_STENCIL_BUFFER_BIT);//clear stencil buffer
|
||||||
|
|
||||||
for(unsigned int i = 0; i<closestFlames.size(); i++) {
|
for(unsigned int i = 0; i<closestFlames.size(); i++) {
|
||||||
closestFlames.at(i)->render(flameShader, lightingViewProjectionMatrix, float(time), false);
|
closestFlames.at(i)->render(flameShader, lightingViewProjectionMatrix, float(time), false, wind);
|
||||||
}
|
}
|
||||||
|
|
||||||
glStencilFunc(GL_EQUAL, 1, 0xFF); //Pass test if stencil value is 1
|
glStencilFunc(GL_EQUAL, 1, 0xFF); //Pass test if stencil value is 1
|
||||||
|
Loading…
Reference in New Issue
Block a user