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

make RenderObject::position not modified during rendering; small cleanup

This commit is contained in:
fgenesis 2023-03-02 02:12:32 +01:00
parent 01295cda7a
commit 7a5a5feb39
3 changed files with 40 additions and 38 deletions

View file

@ -462,28 +462,26 @@ void RenderObject::render(const RenderState& rs) const
if (MotionBlurData *mb = this->motionBlur)
{
RenderState rx(rs);
const Vector oldPos = position;
const float oldRotZ = rotation.z;
const size_t sz = mb->positions.size();
const float m = 1.0f / float(sz);
const float m2 = alpha.x * 0.5f * (mb->transition ? mb->transitionTimer : 1.0f);
for (size_t i = 0; i < sz; i++)
{
position = mb->positions[i].position;
const Vector& renderAt = mb->positions[i].position;
rotation.z = mb->positions[i].rotz;
rx.alpha = (1.0f-(float(i) * m)) * m2;
renderCall(rx);
renderCall(rx, renderAt);
}
position = oldPos;
rotation.z = oldRotZ;
}
renderCall(rs);
renderCall(rs, position);
}
void RenderObject::renderCall(const RenderState& rs) const
void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt) const
{
position += offset;
const Vector renderPos = renderAt + offset;
glPushMatrix();
@ -502,7 +500,7 @@ void RenderObject::renderCall(const RenderState& rs) const
{
glLoadIdentity();
glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
glTranslatef(position.x, position.y, position.z);
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
if (isfh())
{
@ -527,34 +525,38 @@ void RenderObject::renderCall(const RenderState& rs) const
else
{
glTranslatef(position.x, position.y, position.z);
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
if (RenderObject::renderPaths && position.data && position.data->path.getNumPathNodes() > 0)
{
glLineWidth(4);
glEnable(GL_BLEND);
size_t i = 0;
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_LINES);
for (i = 0; i < position.data->path.getNumPathNodes()-1; i++)
// TODO: move this to debug render
if (RenderObject::renderPaths && position.data)
if(size_t N = position.data->path.getNumPathNodes())
{
glVertex2f(position.data->path.getPathNode(i)->value.x-position.x, position.data->path.getPathNode(i)->value.y-position.y);
glVertex2f(position.data->path.getPathNode(i+1)->value.x-position.x, position.data->path.getPathNode(i+1)->value.y-position.y);
}
glEnd();
glLineWidth(4);
glEnable(GL_BLEND);
glPointSize(20);
glBegin(GL_POINTS);
glColor4f(0.5,0.5,1,1);
for (i = 0; i < position.data->path.getNumPathNodes(); i++)
{
glVertex2f(position.data->path.getPathNode(i)->value.x-position.x, position.data->path.getPathNode(i)->value.y-position.y);
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_LINES);
for (size_t i = 0; i < N-1; i++)
{
const VectorPathNode a = position.data->path[i];
const VectorPathNode b = position.data->path[i+1];
glVertex2f(a.value.x-position.x, a.value.y-position.y);
glVertex2f(b.value.x-position.x, b.value.y-position.y);
}
glEnd();
glPointSize(20);
glBegin(GL_POINTS);
glColor4f(0.5,0.5,1,1);
for (size_t i = 0; i < N; i++)
{
const VectorPathNode& a = position.data->path[i];
glVertex2f(a.value.x-position.x, a.value.y-position.y);
}
glEnd();
}
glEnd();
}
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
if (isfh())
@ -620,9 +622,6 @@ void RenderObject::renderCall(const RenderState& rs) const
glPopMatrix();
position -= offset;
}
void RenderObject::renderCollision(const RenderState& rs) const

View file

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

View file

@ -375,9 +375,11 @@ public:
void clear();
void addPathNode(Vector v, float p);
Vector getValue(float percent);
size_t getNumPathNodes() { return pathNodes.size(); }
inline size_t getNumPathNodes() { return pathNodes.size(); }
void resizePathNodes(size_t sz) { pathNodes.resize(sz); }
VectorPathNode *getPathNode(size_t i) { if (i<getNumPathNodes()) return &pathNodes[i]; return 0; }
inline VectorPathNode& operator[](size_t i) { return pathNodes[i]; }
inline const VectorPathNode& operator[](size_t i) const { return pathNodes[i]; }
void cut(int n);
void splice(const VectorPath &path, int sz);
void prepend(const VectorPath &path);