mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-04-08 07:37:07 +00:00
simplify bonelocking, add Lua functions
- does no longer depend on collision mask - remove global Game::lastCollideMaskIndex - remove the horribly convoluted and now unused RenderObject::getInvRotPosition() + Lua func entity_getBoneLockDelay() + Lua func entity_setBoneLockDelay()
This commit is contained in:
parent
7e93956e9c
commit
640f08af13
8 changed files with 46 additions and 118 deletions
|
@ -3139,9 +3139,6 @@ void Avatar::onSetBoneLock()
|
|||
skeletalSprite.transitionAnimate("wallLookUp", 0.2f, -1);
|
||||
lockToWallCommon();
|
||||
state.lockedToWall = 1;
|
||||
wallNormal = boneLock.localOffset;
|
||||
wallNormal.normalize2D();
|
||||
rotateToVec(wallNormal, 0.1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -100,40 +100,36 @@ void Entity::generateCollisionMask(int ovrCollideRadius)
|
|||
|
||||
|
||||
|
||||
bool Entity::setBoneLock(const BoneLock &boneLock)
|
||||
bool Entity::setBoneLock(const BoneLock &bl)
|
||||
{
|
||||
if (!canSetBoneLock()) return false;
|
||||
|
||||
if (boneLock.on && boneLockDelay > 0) return false;
|
||||
if (this->boneLock.on && boneLock.on) return false;
|
||||
if (bl.on && boneLockDelay > 0) return false;
|
||||
if (boneLock.on && bl.on) return false;
|
||||
|
||||
if (this->boneLock.on && !boneLock.on)
|
||||
if (boneLock.on && !bl.on)
|
||||
{
|
||||
boneLockDelay = 0.1f;
|
||||
this->boneLock = boneLock;
|
||||
boneLock = bl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!boneLock.entity)
|
||||
if (!bl.entity)
|
||||
return false;
|
||||
|
||||
this->boneLock = boneLock;
|
||||
boneLock = bl;
|
||||
Quad *lockObj = bl.bone;
|
||||
if(!lockObj)
|
||||
lockObj = bl.entity;
|
||||
|
||||
if (!boneLock.bone)
|
||||
{
|
||||
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.localOffset = this->position - (boneLock.bone->getWorldPosition());
|
||||
this->boneLock.localOffset = boneLock.bone->getInvRotPosition(this->boneLock.localOffset);
|
||||
this->boneLock.origRot = boneLock.bone->getWorldRotation();
|
||||
}
|
||||
Vector posAndRot = lockObj->getWorldPositionAndRotation();
|
||||
boneLock.origRot = posAndRot.z;
|
||||
posAndRot.z = 0;
|
||||
Vector offs = position - posAndRot;
|
||||
boneLock.circleOffset = offs;
|
||||
}
|
||||
|
||||
setv(EV_BONELOCKED, boneLock.on);
|
||||
setv(EV_BONELOCKED, bl.on);
|
||||
|
||||
onSetBoneLock();
|
||||
|
||||
|
@ -1612,24 +1608,18 @@ void Entity::updateBoneLock()
|
|||
{
|
||||
if (boneLock.on)
|
||||
{
|
||||
|
||||
|
||||
Vector lastPosition = position;
|
||||
const Quad *lockObj = boneLock.bone;
|
||||
if(!lockObj)
|
||||
lockObj = boneLock.entity;
|
||||
|
||||
if (boneLock.bone)
|
||||
{
|
||||
position = boneLock.bone->transformedCollisionMask[boneLock.collisionMaskIndex];
|
||||
boneLock.wallNormal = boneLock.bone->getCollisionMaskNormal(boneLock.collisionMaskIndex);
|
||||
rotateToVec(boneLock.wallNormal, 0.01f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector currentOffset = getRotatedVector(boneLock.circleOffset, boneLock.entity->rotation.z - boneLock.origRot);
|
||||
position = boneLock.entity->getWorldPosition() + currentOffset;
|
||||
boneLock.wallNormal = currentOffset;
|
||||
boneLock.wallNormal.normalize2D();
|
||||
rotateToVec(boneLock.wallNormal, 0.01f);
|
||||
}
|
||||
Vector posAndRot = lockObj->getWorldPositionAndRotation();
|
||||
Vector currentOffset = getRotatedVector(boneLock.circleOffset, posAndRot.z - boneLock.origRot);
|
||||
posAndRot.z = 0;
|
||||
position = posAndRot + currentOffset;
|
||||
currentOffset.normalize2D();
|
||||
boneLock.wallNormal = currentOffset;
|
||||
rotateToVec(currentOffset, 0.01f);
|
||||
|
||||
if (dsq->game->collideCircleWithGrid(position, collideRadius))
|
||||
{
|
||||
|
@ -1638,12 +1628,7 @@ void Entity::updateBoneLock()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
onUpdateBoneLock();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,9 @@ struct BoneLock
|
|||
BoneLock() : entity(0), bone(0), on(false), origRot(0) {}
|
||||
Entity *entity;
|
||||
Bone *bone;
|
||||
Vector localOffset;
|
||||
bool on;
|
||||
float origRot;
|
||||
Vector wallNormal, circleOffset;
|
||||
int collisionMaskIndex;
|
||||
};
|
||||
|
||||
// The Lance is an ability that never made it into the released version of the game.
|
||||
|
@ -344,6 +342,7 @@ public:
|
|||
|
||||
void updateSoundPosition();
|
||||
void updateBoneLock();
|
||||
float boneLockDelay;
|
||||
|
||||
Vector getPushVec() const { return pushVec; }
|
||||
float getPushDamage() const { return pushDamage; }
|
||||
|
@ -358,7 +357,6 @@ protected:
|
|||
|
||||
std::vector<DamageType> ignoreShotDamageTypes;
|
||||
Timer vineDamageTimer;
|
||||
float boneLockDelay;
|
||||
virtual void onSetBoneLock(){}
|
||||
virtual void onUpdateBoneLock(){}
|
||||
BoneLock boneLock;
|
||||
|
|
|
@ -223,7 +223,6 @@ Game::Game() : StateObject()
|
|||
|
||||
loadEntityTypeList();
|
||||
|
||||
lastCollideMaskIndex = -1;
|
||||
worldPaused = false;
|
||||
|
||||
cookingScript = 0;
|
||||
|
@ -3958,7 +3957,6 @@ Bone *Game::collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius)
|
|||
{
|
||||
closest = b;
|
||||
smallestDist = dist;
|
||||
lastCollideMaskIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -382,8 +382,6 @@ public:
|
|||
bool isShuttingDownGameState() { return shuttingDownGameState; }
|
||||
void warpToSceneNode(std::string scene, std::string node);
|
||||
|
||||
int lastCollideMaskIndex;
|
||||
|
||||
void ensureLimit(Entity *e, int num, int state=0);
|
||||
|
||||
void rebuildElementUpdateList();
|
||||
|
|
|
@ -2883,8 +2883,8 @@ luaFunc(entity_getBoneLockData)
|
|||
lua_pushnumber(L, b.origRot);
|
||||
lua_pushnumber(L, b.wallNormal.x);
|
||||
lua_pushnumber(L, b.wallNormal.y);
|
||||
lua_pushnumber(L, b.localOffset.x);
|
||||
lua_pushnumber(L, b.localOffset.y);
|
||||
lua_pushnumber(L, b.circleOffset.x);
|
||||
lua_pushnumber(L, b.circleOffset.y);
|
||||
return 7;
|
||||
}
|
||||
|
||||
|
@ -2950,7 +2950,6 @@ luaFunc(entity_setBoneLock)
|
|||
bl.entity = e2;
|
||||
bl.bone = b;
|
||||
bl.on = true;
|
||||
bl.collisionMaskIndex = dsq->game->lastCollideMaskIndex;
|
||||
}
|
||||
ret = e->setBoneLock(bl);
|
||||
}
|
||||
|
@ -2989,6 +2988,21 @@ luaFunc(entity_setBoneLockOffset)
|
|||
luaReturnBool(ret);
|
||||
}
|
||||
|
||||
luaFunc(entity_setBoneLockDelay)
|
||||
{
|
||||
if(Entity *e = entity(L))
|
||||
e->boneLockDelay = lua_tonumber(L, 2);
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(entity_getBoneLockDelay)
|
||||
{
|
||||
float t = 0;
|
||||
if(Entity *e = entity(L))
|
||||
t = e->boneLockDelay;
|
||||
luaReturnNum(t);
|
||||
}
|
||||
|
||||
luaFunc(entity_setIngredient)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
|
@ -9972,6 +9986,8 @@ static const struct {
|
|||
luaRegister(entity_setBoneLock),
|
||||
luaRegister(entity_setBoneLockRotation),
|
||||
luaRegister(entity_setBoneLockOffset),
|
||||
luaRegister(entity_setBoneLockDelay),
|
||||
luaRegister(entity_getBoneLockDelay),
|
||||
luaRegister(entity_setIngredient),
|
||||
luaRegister(entity_setDeathScene),
|
||||
luaRegister(entity_isDeathScene),
|
||||
|
|
|
@ -122,69 +122,6 @@ 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();
|
||||
|
||||
std::vector<const RenderObject*>chain;
|
||||
const RenderObject *p = this;
|
||||
while(p)
|
||||
{
|
||||
chain.push_back(p);
|
||||
p = p->parent;
|
||||
}
|
||||
|
||||
for (int i = chain.size()-1; i >= 0; i--)
|
||||
{
|
||||
glRotatef(-(chain[i]->rotation.z+chain[i]->rotationOffset.z), 0, 0, 1);
|
||||
|
||||
if (chain[i]->isfh())
|
||||
{
|
||||
|
||||
glRotatef(180, 0, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (vec.x != 0 || vec.y != 0)
|
||||
{
|
||||
|
||||
glTranslatef(vec.x, vec.y, 0);
|
||||
}
|
||||
|
||||
float m[16];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
||||
float x = m[12];
|
||||
float y = m[13];
|
||||
float z = m[14];
|
||||
|
||||
glPopMatrix();
|
||||
#endif
|
||||
|
||||
return Vector(x,y,z);
|
||||
}
|
||||
|
||||
#ifdef BBGE_USE_GLM
|
||||
static glm::mat4 matrixChain(const RenderObject *ro)
|
||||
{
|
||||
|
|
|
@ -185,7 +185,6 @@ public:
|
|||
|
||||
Vector getWorldPosition() const;
|
||||
Vector getWorldCollidePosition(const Vector &vec=Vector(0,0,0)) const;
|
||||
Vector getInvRotPosition(const Vector &vec) const;
|
||||
|
||||
RenderObject *getTopParent() const;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue