Flames can now be skewed.
This commit is contained in:
parent
b90f03c397
commit
bd584c3ce4
17
flame.cc
17
flame.cc
@ -24,13 +24,24 @@ Flame::Flame() {
|
||||
}
|
||||
|
||||
void Flame::render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix, float time,
|
||||
bool withColor) {
|
||||
bool withColor, glm::vec2 skewing) {
|
||||
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) {
|
||||
modelMatrix = glm::scale<float>(size * glm::vec3(1.1f));
|
||||
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size * glm::vec3(1.1f));
|
||||
}
|
||||
else {
|
||||
modelMatrix = glm::scale<float>(size);
|
||||
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size);
|
||||
}
|
||||
glm::mat4 modelViewProjectionMatrix = viewProjectionMatrix * modelMatrix;
|
||||
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();
|
||||
void render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix,
|
||||
float time, bool withColor);
|
||||
float time, bool withColor, glm::vec2 skewing);
|
||||
private:
|
||||
glm::vec3 color;
|
||||
glm::vec3 size;
|
||||
|
@ -282,6 +282,9 @@ void Graphics::render(double time)
|
||||
framebuffer_light->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//wind
|
||||
glm::vec2 wind = glm::vec2(-0.4f, 0.3f);
|
||||
|
||||
//set view and projection matrix
|
||||
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
|
||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||
lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition());
|
||||
lightingShader->setUniform("movement", glm::vec2(-0.3f, -0.4f));
|
||||
lightingShader->setUniform("movement", wind);
|
||||
lightingShader->setUniform("time", (float) time);
|
||||
|
||||
// render the level
|
||||
@ -346,7 +349,7 @@ void Graphics::render(double time)
|
||||
|
||||
// draw with colors
|
||||
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);
|
||||
|
||||
@ -358,7 +361,7 @@ void Graphics::render(double time)
|
||||
glClear(GL_STENCIL_BUFFER_BIT);//clear stencil buffer
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user