1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-04 10:34:01 +00:00

Make Game::fillGridFromQuad() and RenderObject::getInvRotPosition() use glm instead of the GL matrix stack

This commit is contained in:
fgenesis 2022-06-20 18:36:49 +02:00
parent baa1170e6f
commit 614f987df2
3 changed files with 49 additions and 9 deletions

View file

@ -102,25 +102,19 @@ bool Entity::setBoneLock(const BoneLock &boneLock)
if (!boneLock.entity)
return false;
if (boneLock.entity && !boneLock.bone)
this->boneLock = boneLock;
if (!boneLock.bone)
{
this->boneLock = boneLock;
this->boneLock.circleOffset = this->position - (boneLock.entity->getWorldPosition());
this->boneLock.circleOffset.setLength2D(boneLock.entity->collideRadius);
this->boneLock.origRot = boneLock.entity->rotation.z;
}
else
{
this->boneLock = boneLock;
this->boneLock.localOffset = this->position - (boneLock.bone->getWorldPosition());
this->boneLock.localOffset = boneLock.bone->getInvRotPosition(this->boneLock.localOffset);
this->boneLock.origRot = boneLock.bone->getWorldRotation();
}
}

View file

@ -47,6 +47,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Beam.h"
#include "Hair.h"
#ifdef BBGE_USE_GLM
#include "glm/glm.hpp"
#include "glm/gtx/transform.hpp"
#endif
static const float MENUPAGETRANSTIME = 0.2f;
@ -497,6 +502,24 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim)
}
#ifdef BBGE_USE_GLM
const float w2f = float(w2);
const float h2f = float(h2);
for (size_t i = 0; i < obs.size(); i++)
{
glm::mat4 transformMatrix = glm::rotate(q->rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
if(q->isfh())
transformMatrix *= glm::rotate(180.0f, glm::vec3(0.0f, 1.0f, 0.0f));
transformMatrix *= glm::translate(float(obs[i].x)-w2f, float(obs[i].y)-h2f, 0.0f);
float x = transformMatrix[3][0];
float y = transformMatrix[3][1];
TileVector tvec(tpos.x+w2+x, tpos.y+h2+y);
if (!dsq->game->isObstructed(tvec))
dsq->game->addGrid(tvec, obsType);
}
#else
glPushMatrix();
for (size_t i = 0; i < obs.size(); i++)
@ -524,6 +547,7 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim)
}
glPopMatrix();
#endif
}
}

View file

@ -122,9 +122,29 @@ RenderObject* RenderObject::getTopParent() const
return lastp;
}
#ifdef BBGE_USE_GLM
static glm::mat4 getInvRotation(const RenderObject *p)
{
glm::mat4 m = glm::rotate(-(p->rotation.z + p->rotationOffset.z), glm::vec3(0.0f, 0.0f, 1.0f));
if(p->isfh())
m *= glm::rotate(180.0f, glm::vec3(0.0f, 1.0f, 0.0f));
return m;
}
#endif
Vector RenderObject::getInvRotPosition(const Vector &vec) const
{
#ifdef BBGE_USE_GLM
glm::mat4 m = getInvRotation(this);
for(RenderObject *p = parent; p; p = p->parent)
m *= getInvRotation(p);
m *= glm::translate(vec.x, vec.y, 0.0f);
float x = m[3][0];
float y = m[3][1];
float z = m[3][2];
#else
glPushMatrix();
glLoadIdentity();
@ -160,6 +180,8 @@ Vector RenderObject::getInvRotPosition(const Vector &vec) const
float z = m[14];
glPopMatrix();
#endif
return Vector(x,y,z);
}