Page 1 of 1

pseudo z axis on 2d scaling

Posted: January 2nd, 2018, 7:59 pm
by MrGodin
Hey folks, I am working on a particle emitter and i want to do a z axis scaling where i get a random z value between - 1 and 1. I want to scale the positive from 1 to 2 or n size and negative from 1 to near 0.
Particle update. I diffuse transparency by life / lifespan which gives me a value between 0 and 1.
I should be able to use this to get from 1 to 0 and 1 to 2 ?.
What i am trying to achieve is a pseudo 3d look

Code: Select all

void Particle::Update(const float & dt)
{
	if (!done)
	{
		if ((life -= dt) > 0.0f)
		{

			if (diffuse)
			{
				Get<Animation>().SetTransparency(life / lifeSpan);
			}
			Get<Transform>().velocity.y += gravity;
			Get<Transform>().Update(dt);
			if (doRotate)
			{
				Vec2f v = Get<Transform>().velocity;
				Get<Transform>().rotation_angle = v.Normalize().Angle();
				Get<Transform>().Rotate();
			}
                      /// here
                      Vec2f scale = { Zscaler,Zscaler };
			scale.Normalize();
			Get<Transform>().Scale({ scale.x + (life / lifeSpan),scale.y + (life / lifeSpan) });
		}
		else
		{
			done = true;
			Get<Transform>().Scale({ 1.0f,1.0f });
			
		}
	}
}
any suggestions ?

Re: pseudo z axis on 2d scaling

Posted: January 2nd, 2018, 8:12 pm
by MrGodin
hmm i think this has fixed it

Code: Select all

if (doScale)
	{
	float sign = Sign<float>(Zscaler);
	float scaler = (1.0f - (life / lifeSpan));
	if (sign < 0)
		Get<Transform>().Scale({ 1.0f + scaler,1.0f + scaler });
	else
	       Get<Transform>().Scale({ 1.0f - scaler,1.0f - scaler });
	}

Re: pseudo z axis on 2d scaling

Posted: January 2nd, 2018, 8:25 pm
by MrGodin
Now the trick is to render the -Zscalers ones before the tiles to give the illusion of going away behind the tiles and other objects

Re: pseudo z axis on 2d scaling

Posted: January 2nd, 2018, 9:46 pm
by MrGodin
Yes!! did it, particles that scale small get drawn first, then tiles, then larger scaled particles last .