1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

Move members related to collision mask from RenderObject to Bone

This commit is contained in:
fgenesis 2022-05-18 02:15:19 +02:00
parent e33bde0a89
commit 111cd43805
8 changed files with 81 additions and 87 deletions

View file

@ -2923,9 +2923,9 @@ void DSQ::doSaveSlotMenu(SaveSlotMode ssm, const Vector &position)
std::string DSQ::getEntityFlagName(Entity *e)
{
if (!dsq->game) return "";
if (!game) return "";
std::ostringstream os;
os << dsq->game->sceneName << e->startPos.x << e->startPos.y;
os << game->sceneName << e->startPos.x << e->startPos.y;
return os.str();
}
@ -2947,13 +2947,6 @@ void doAlphabetInputKey(int d, char c, char map[], std::string *text, char upper
}
}
void DSQ::generateCollisionMask(RenderObject *r)
{
Quad *q = dynamic_cast<Quad*>(r);
if (q)
game->generateCollisionMask(q);
}
void DSQ::onConfirmYes()
{
dsq->confirmDone = 1;

View file

@ -258,7 +258,6 @@ public:
void takeScreenshotKey();
void generateCollisionMask(RenderObject *r);
void toggleRenderCollisionShapes();
void voice(const std::string &file, float volMod = -1);

View file

@ -1067,7 +1067,7 @@ void Game::setTimerText(float time)
timerText->setText(os.str());
}
void Game::generateCollisionMask(Quad *q, float overrideCollideRadius /* = 0 */)
void Game::generateCollisionMask(Bone *q, float overrideCollideRadius /* = 0 */)
{
if (q->texture)
{

View file

@ -304,7 +304,7 @@ public:
void setTimerTextAlpha(float a, float t);
void setTimerText(float time);
void generateCollisionMask(Quad *q, float overrideCollideRadius=0);
void generateCollisionMask(Bone *q, float overrideCollideRadius=0);
std::string fromScene, toNode;
int toFlip;
char fromWarpType;

View file

@ -136,7 +136,6 @@ RenderObject::RenderObject()
overrideCullRadiusSqr = 0;
repeatTexture = false;
alphaMod = 1;
collisionMaskRadius = 0;
collideRadius = 0;
motionBlurTransition = false;
motionBlurFrameOffsetCounter = 0;
@ -770,44 +769,7 @@ void RenderObject::renderCall()
void RenderObject::renderCollision()
{
if (!collisionMask.empty())
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, 0);
glLoadIdentity();
core->setupRenderPositionAndScale();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,0,0.5);
for (size_t i = 0; i < transformedCollisionMask.size(); i++)
{
Vector collide = this->transformedCollisionMask[i];
glTranslatef(collide.x, collide.y, 0);
RenderObject *parent = this->getTopParent();
if (parent)
drawCircle(collideRadius*parent->scale.x, 45);
glTranslatef(-collide.x, -collide.y, 0);
}
glDisable(GL_BLEND);
glPopMatrix();
glPopAttrib();
}
else if (collideRadius > 0)
if (collideRadius > 0)
{
glPushMatrix();
glLoadIdentity();
@ -818,8 +780,6 @@ void RenderObject::renderCollision()
glTranslatef(internalOffset.x, internalOffset.y, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,0,0,0.5);
drawCircle(collideRadius, 8);
@ -840,34 +800,6 @@ void RenderObject::deathNotify(RenderObject *r)
deathNotifications.remove(r);
}
Vector RenderObject::getCollisionMaskNormal(size_t index)
{
Vector sum;
size_t num=0;
for (size_t i = 0; i < this->transformedCollisionMask.size(); i++)
{
if (i != index)
{
Vector diff = transformedCollisionMask[index] - transformedCollisionMask[i];
if (diff.isLength2DIn(128))
{
sum += diff;
num++;
}
}
}
if (!sum.isZero())
{
sum /= num;
sum.normalize2D();
}
return sum;
}
void RenderObject::lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset)
{
Vector myPos = this->getWorldPosition();

View file

@ -217,8 +217,6 @@ public:
virtual void unloadDevice();
virtual void reloadDevice();
Vector getCollisionMaskNormal(size_t index);
//-------------------------------- Methods above, fields below
static bool renderCollisionShape;
@ -271,10 +269,7 @@ public:
float collideRadius;
std::vector<Vector> collisionMask;
std::vector<Vector> transformedCollisionMask;
float collisionMaskRadius;
float alphaMod;
@ -311,7 +306,7 @@ protected:
bool hasRenderPass(const int pass);
inline void renderCall();
void renderCollision();
virtual void renderCollision();
bool repeatTexture;
unsigned char pm; // unsigned char to save space

View file

@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "MathFunctions.h"
#include "SimpleIStringStream.h"
#include "ReadXML.h"
#include "RenderBase.h"
#include <tinyxml2.h>
using namespace tinyxml2;
@ -77,6 +78,7 @@ Bone::Bone() : Quad()
boneIdx = pidx = -1;
rbp = false;
segmentChain = 0;
collisionMaskRadius = 0;
minDist = maxDist = 128;
reverse = false;
@ -295,6 +297,72 @@ void Bone::spawnParticlesFromCollisionMask(const char *p, unsigned intv, int lay
}
}
void Bone::renderCollision()
{
if (!collisionMask.empty())
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, 0);
glLoadIdentity();
core->setupRenderPositionAndScale();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,0,0.5);
for (size_t i = 0; i < transformedCollisionMask.size(); i++)
{
Vector collide = this->transformedCollisionMask[i];
glTranslatef(collide.x, collide.y, 0);
RenderObject *parent = this->getTopParent();
if (parent)
drawCircle(collideRadius*parent->scale.x, 45);
glTranslatef(-collide.x, -collide.y, 0);
}
glDisable(GL_BLEND);
glPopMatrix();
glPopAttrib();
}
else
Quad::renderCollision();
}
Vector Bone::getCollisionMaskNormal(size_t index)
{
Vector sum;
size_t num=0;
for (size_t i = 0; i < this->transformedCollisionMask.size(); i++)
{
if (i != index)
{
Vector diff = transformedCollisionMask[index] - transformedCollisionMask[i];
if (diff.isLength2DIn(128))
{
sum += diff;
num++;
}
}
}
if (!sum.isZero())
{
sum /= num;
sum.normalize2D();
}
return sum;
}
bool BoneCommand::parse(Bone *b, SimpleIStringStream &is)
{

View file

@ -92,11 +92,18 @@ public:
int originalRenderPass; // stores the render pass originally set in the XML file. For AC_RESET_PASS.
void spawnParticlesFromCollisionMask(const char *p, unsigned intv, int layer, float rotz = 0);
Vector getCollisionMaskNormal(size_t index);
virtual void renderCollision();
protected:
std::vector<ParticleEffect*> emitters;
int minDist, maxDist, reverse;
std::vector<Bone*> segments;
public:
std::vector<Vector> collisionMask;
std::vector<Vector> transformedCollisionMask;
float collisionMaskRadius;
};
class BoneCommand