Skip to content

Instantly share code, notes, and snippets.

@jose-villegas
Created November 16, 2015 04:30
Show Gist options
  • Save jose-villegas/1ec41657e7b39bc60800 to your computer and use it in GitHub Desktop.
Save jose-villegas/1ec41657e7b39bc60800 to your computer and use it in GitHub Desktop.
almost40fpswat
#include <glm/gtc/matrix_inverse.hpp>
#include "transform_matrices.h"
#include "frustum.h"
TransformMatrices::TransformMatrices() : matrices(), matricesChanged(None)
{
}
TransformMatrices::~TransformMatrices()
{
}
void TransformMatrices::UpdateModelMatrix(const glm::mat4x4 &rModel)
{
if (rModel == matrices.model) { return; }
matrices.model = rModel;
matricesChanged = static_cast<Changed>(matricesChanged | ModelChanged);
}
void TransformMatrices::UpdateViewMatrix(const glm::mat4x4 &rView)
{
if (rView == matrices.model) { return; }
matrices.view = rView;
matricesChanged = static_cast<Changed>(matricesChanged | ViewChanged);
}
void TransformMatrices::UpdateProjectionMatrix(const glm::mat4x4 &rProjection)
{
if (rProjection == matrices.projection) { return; }
matrices.projection = rProjection;
matricesChanged = static_cast<Changed>(matricesChanged | ProjectionChanged);
}
void TransformMatrices::RecalculateMatrices(bool useInverseTranspose)
{
if (matricesChanged & (ViewChanged | ModelChanged))
{
matrices.modelView = matrices.view * matrices.model;
}
if (matricesChanged & (ViewChanged | ModelChanged | ProjectionChanged))
{
matrices.modelViewProjection = matrices.projection * matrices.modelView;
}
matrices.normal = useInverseTranspose
? inverseTranspose(matrices.modelView)
: matrices.modelView;
matricesChanged = None;
}
void TransformMatrices::UpdateFrustumPlanes(Frustum &fUpdate) const
{
// can recalculate frustum in this case
if (matricesChanged & (ViewChanged | ProjectionChanged))
{
fUpdate.CalculatePlanes(matrices.projection * matrices.view);
}
}
#include <glm/gtc/matrix_inverse.hpp>
#include "transform_matrices.h"
#include "frustum.h"
TransformMatrices::TransformMatrices()
{
}
TransformMatrices::~TransformMatrices()
{
}
void TransformMatrices::UpdateModelMatrix(const glm::mat4x4 &rModel)
{
if (matrices.model != rModel)
{
matrices.model = rModel;
modelMatrixChanged = true;
}
else
{
modelMatrixChanged = false;
}
}
void TransformMatrices::UpdateViewMatrix(const glm::mat4x4 &rView)
{
if (matrices.view != rView)
{
matrices.view = rView;
viewMatrixChanged = true;
}
else
{
viewMatrixChanged = false;
}
}
void TransformMatrices::UpdateProjectionMatrix(const glm::mat4x4 &rProjection)
{
if (matrices.projection != rProjection)
{
matrices.projection = rProjection;
projectionMatrixChanged = true;
}
else
{
projectionMatrixChanged = false;
}
}
void TransformMatrices::RecalculateMatrices(bool useInverseTranspose)
{
if (viewMatrixChanged || modelMatrixChanged)
{
matrices.modelView = matrices.view * matrices.model;
modelViewMatrixChanged = true;
}
if (modelViewMatrixChanged || projectionMatrixChanged)
{
matrices.modelViewProjection = matrices.projection * matrices.modelView;
}
if (modelViewMatrixChanged)
{
matrices.normal = useInverseTranspose
? inverseTranspose(matrices.modelView)
: matrices.modelView;
}
}
void TransformMatrices::UpdateFrustumPlanes(Frustum &fUpdate)
{
// can recalculate frustum in this case
if (viewMatrixChanged || projectionMatrixChanged)
{
fUpdate.CalculatePlanes(matrices.projection * matrices.view);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment