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

make RenderObject::rotation not modified during rendering, simplify duplicated code

This commit is contained in:
fgenesis 2023-03-02 02:31:16 +01:00
parent f4147b99c4
commit 76ba2b1211
2 changed files with 21 additions and 26 deletions

View file

@ -462,26 +462,25 @@ void RenderObject::render(const RenderState& rs) const
if (MotionBlurData *mb = this->motionBlur) if (MotionBlurData *mb = this->motionBlur)
{ {
RenderState rx(rs); RenderState rx(rs);
const float oldRotZ = rotation.z;
const size_t sz = mb->positions.size(); const size_t sz = mb->positions.size();
const float m = 1.0f / float(sz); const float m = 1.0f / float(sz);
const float m2 = alpha.x * 0.5f * (mb->transition ? mb->transitionTimer : 1.0f); const float m2 = alpha.x * 0.5f * (mb->transition ? mb->transitionTimer : 1.0f);
for (size_t i = 0; i < sz; i++) for (size_t i = 0; i < sz; i++)
{ {
const Vector& renderAt = mb->positions[i].position; const Vector& renderAt = mb->positions[i].position;
rotation.z = mb->positions[i].rotz; const float renderRotation = mb->positions[i].rotz;
rx.alpha = (1.0f-(float(i) * m)) * m2; rx.alpha = (1.0f-(float(i) * m)) * m2;
renderCall(rx, renderAt); renderCall(rx, renderAt, renderRotation);
} }
rotation.z = oldRotZ;
} }
renderCall(rs, position); renderCall(rs, position, rotation.z);
} }
void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt) const void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt, float renderRotation) const
{ {
const Vector renderPos = renderAt + offset; const Vector renderPos = renderAt + offset;
renderRotation += rotationOffset.z;
glPushMatrix(); glPushMatrix();
@ -501,26 +500,24 @@ void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt) con
glLoadIdentity(); glLoadIdentity();
glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0); glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
glTranslatef(renderPos.x, renderPos.y, renderPos.z); glTranslatef(renderPos.x, renderPos.y, renderPos.z);
if (isfh())
{
glRotatef(180, 0, 1, 0);
}
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
} }
else else
{ {
Vector pos = getFollowCameraPosition(); Vector pos = getFollowCameraPosition();
glTranslatef(pos.x, pos.y, pos.z); glTranslatef(pos.x, pos.y, pos.z);
if (isfh())
{
glRotatef(180, 0, 1, 0);
}
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
} }
// FIXME: this is the reason why tiles on parallax layers rotate in the wrong direction!
// Unfortunately the maps were built with this in mind, so before this can be taken out
// and replaced with the correct version (below), the rotation needs to be fixed up somehow.
// Not sure yet how to do this. Fix maps on load?
// Add a map flag "hasCorrectParallaxRotation" and an editor feature to rotate tiles and set this flag?
// Probably want editor compatibility with old versions so the incorrect behavior
// needs to be the default if nothing is specified.
// What a mess. Sigh. -- FG
if (isfh())
glRotatef(180, 0, 1, 0);
glRotatef(renderRotation, 0, 0, 1);
} }
else else
{ {
@ -558,12 +555,10 @@ void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt) con
glEnd(); glEnd();
} }
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); // This is the correct way to rotate things.
glRotatef(renderRotation, 0, 0, 1);
if (isfh()) if (isfh())
{
glRotatef(180, 0, 1, 0); glRotatef(180, 0, 1, 0);
}
} }
glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, beforeScaleOffset.z); glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, beforeScaleOffset.z);

View file

@ -255,7 +255,7 @@ public:
InterpolatedVector position; InterpolatedVector position;
InterpolatedVector scale; InterpolatedVector scale;
InterpolatedVector color, alpha; InterpolatedVector color, alpha;
mutable InterpolatedVector rotation; InterpolatedVector rotation;
InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset; InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset;
InterpolatedVector velocity, gravity; InterpolatedVector velocity, gravity;
@ -301,7 +301,7 @@ protected:
// Is this object or any of its children rendered in pass "pass"? // Is this object or any of its children rendered in pass "pass"?
bool hasRenderPass(const int pass) const; bool hasRenderPass(const int pass) const;
inline void renderCall(const RenderState& rs, const Vector& renderAt) const; inline void renderCall(const RenderState& rs, const Vector& renderAt, float renderRotation) const;
virtual void renderCollision(const RenderState& rs) const; virtual void renderCollision(const RenderState& rs) const;
typedef std::list<RenderObject*> RenderObjectList; typedef std::list<RenderObject*> RenderObjectList;