mirror of
https://github.com/love2d/love.git
synced 2026-08-19 04:06:17 +02:00
user can now manually set the offset for particle rotation
This commit is contained in:
@@ -47,7 +47,8 @@ namespace opengl
|
|||||||
gravityMax(0), radialAccelerationMin(0), radialAccelerationMax(0),
|
gravityMax(0), radialAccelerationMin(0), radialAccelerationMax(0),
|
||||||
tangentialAccelerationMin(0), tangentialAccelerationMax(0),
|
tangentialAccelerationMin(0), tangentialAccelerationMax(0),
|
||||||
sizeStart(1), sizeEnd(1), sizeVariation(0), rotationMin(0), rotationMax(0),
|
sizeStart(1), sizeEnd(1), sizeVariation(0), rotationMin(0), rotationMax(0),
|
||||||
spinStart(0), spinEnd(0), spinVariation(0)
|
spinStart(0), spinEnd(0), spinVariation(0), offsetX(sprite->getWidth()*0.5f),
|
||||||
|
offsetY(sprite->getHeight()*0.5f)
|
||||||
{
|
{
|
||||||
this->sprite = sprite;
|
this->sprite = sprite;
|
||||||
sprite->retain();
|
sprite->retain();
|
||||||
@@ -308,6 +309,12 @@ namespace opengl
|
|||||||
memcpy(colorEnd, end, 4);
|
memcpy(colorEnd, end, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ParticleSystem::setOffset(float x, float y)
|
||||||
|
{
|
||||||
|
offsetX = x;
|
||||||
|
offsetY = y;
|
||||||
|
}
|
||||||
|
|
||||||
float ParticleSystem::getX() const
|
float ParticleSystem::getX() const
|
||||||
{
|
{
|
||||||
return position.getX();
|
return position.getX();
|
||||||
@@ -328,6 +335,16 @@ namespace opengl
|
|||||||
return spread * LOVE_M_TODEG;
|
return spread * LOVE_M_TODEG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ParticleSystem::getOffsetX() const
|
||||||
|
{
|
||||||
|
return offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ParticleSystem::getOffsetY() const
|
||||||
|
{
|
||||||
|
return offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
int ParticleSystem::count() const
|
int ParticleSystem::count() const
|
||||||
{
|
{
|
||||||
return (int)(pLast - pStart);
|
return (int)(pLast - pStart);
|
||||||
@@ -393,7 +410,7 @@ namespace opengl
|
|||||||
glTranslatef(p->position[0],p->position[1],0.0f);
|
glTranslatef(p->position[0],p->position[1],0.0f);
|
||||||
glRotatef(p->rotation * 57.29578f, 0.0f, 0.0f, 1.0f); // rad * (180 / pi)
|
glRotatef(p->rotation * 57.29578f, 0.0f, 0.0f, 1.0f); // rad * (180 / pi)
|
||||||
glScalef(p->size,p->size,1.0f);
|
glScalef(p->size,p->size,1.0f);
|
||||||
glTranslatef(sprite->getWidth()*-0.5f,sprite->getHeight()*-0.5f,0.0f);
|
glTranslatef(-offsetX,-offsetY,0.0f);
|
||||||
sprite->draw(0,0, 0, 1, 1, 0, 0);
|
sprite->draw(0,0, 0, 1, 1, 0, 0);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|||||||
@@ -140,6 +140,10 @@ namespace opengl
|
|||||||
float spinEnd;
|
float spinEnd;
|
||||||
float spinVariation;
|
float spinVariation;
|
||||||
|
|
||||||
|
// Offsets
|
||||||
|
float offsetX;
|
||||||
|
float offsetY;
|
||||||
|
|
||||||
// Color.
|
// Color.
|
||||||
unsigned char colorStart[4];
|
unsigned char colorStart[4];
|
||||||
unsigned char colorEnd[4];
|
unsigned char colorEnd[4];
|
||||||
@@ -341,6 +345,13 @@ namespace opengl
|
|||||||
**/
|
**/
|
||||||
void setColor(unsigned char * color);
|
void setColor(unsigned char * color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the particles' offsets for rotation.
|
||||||
|
* @param x The x offset.
|
||||||
|
* @param y The y offset.
|
||||||
|
**/
|
||||||
|
void setOffset(float x, float y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color of the particles.
|
* Sets the color of the particles.
|
||||||
* @param start The color of the particle when created.
|
* @param start The color of the particle when created.
|
||||||
@@ -368,6 +379,16 @@ namespace opengl
|
|||||||
**/
|
**/
|
||||||
float getSpread() const;
|
float getSpread() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the X offset of the particles.
|
||||||
|
**/
|
||||||
|
float getOffsetX() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Y offset of the particles.
|
||||||
|
**/
|
||||||
|
float getOffsetY() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the amount of particles that are currently active in the system.
|
* Returns the amount of particles that are currently active in the system.
|
||||||
**/
|
**/
|
||||||
|
|||||||
@@ -214,6 +214,15 @@ namespace opengl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_ParticleSystem_setOffset(lua_State * L)
|
||||||
|
{
|
||||||
|
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||||
|
float x = (float)luaL_checknumber(L, 2);
|
||||||
|
float y = (float)luaL_checknumber(L, 3);
|
||||||
|
t->setOffset(x, y);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int w_ParticleSystem_getX(lua_State * L)
|
int w_ParticleSystem_getX(lua_State * L)
|
||||||
{
|
{
|
||||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||||
@@ -242,6 +251,20 @@ namespace opengl
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_ParticleSystem_getOffsetX(lua_State * L)
|
||||||
|
{
|
||||||
|
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||||
|
lua_pushnumber(L, t->getOffsetX());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_ParticleSystem_getOffsetY(lua_State * L)
|
||||||
|
{
|
||||||
|
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||||
|
lua_pushnumber(L, t->getOffsetY());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_ParticleSystem_count(lua_State * L)
|
int w_ParticleSystem_count(lua_State * L)
|
||||||
{
|
{
|
||||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||||
@@ -326,10 +349,13 @@ namespace opengl
|
|||||||
{ "setSpin", w_ParticleSystem_setSpin },
|
{ "setSpin", w_ParticleSystem_setSpin },
|
||||||
{ "setSpinVariation", w_ParticleSystem_setSpinVariation },
|
{ "setSpinVariation", w_ParticleSystem_setSpinVariation },
|
||||||
{ "setColor", w_ParticleSystem_setColor },
|
{ "setColor", w_ParticleSystem_setColor },
|
||||||
|
{ "setOffset", w_ParticleSystem_setOffset },
|
||||||
{ "getX", w_ParticleSystem_getX },
|
{ "getX", w_ParticleSystem_getX },
|
||||||
{ "getY", w_ParticleSystem_getY },
|
{ "getY", w_ParticleSystem_getY },
|
||||||
{ "getDirection", w_ParticleSystem_getDirection },
|
{ "getDirection", w_ParticleSystem_getDirection },
|
||||||
{ "getSpread", w_ParticleSystem_getSpread },
|
{ "getSpread", w_ParticleSystem_getSpread },
|
||||||
|
{ "getOffsetX", w_ParticleSystem_getOffsetX },
|
||||||
|
{ "getOffsetY", w_ParticleSystem_getOffsetY },
|
||||||
{ "count", w_ParticleSystem_count },
|
{ "count", w_ParticleSystem_count },
|
||||||
{ "start", w_ParticleSystem_start },
|
{ "start", w_ParticleSystem_start },
|
||||||
{ "stop", w_ParticleSystem_stop },
|
{ "stop", w_ParticleSystem_stop },
|
||||||
|
|||||||
@@ -52,10 +52,13 @@ namespace opengl
|
|||||||
int w_ParticleSystem_setSpin(lua_State * L);
|
int w_ParticleSystem_setSpin(lua_State * L);
|
||||||
int w_ParticleSystem_setSpinVariation(lua_State * L);
|
int w_ParticleSystem_setSpinVariation(lua_State * L);
|
||||||
int w_ParticleSystem_setColor(lua_State * L);
|
int w_ParticleSystem_setColor(lua_State * L);
|
||||||
|
int w_ParticleSystem_setOffset(lua_State * L);
|
||||||
int w_ParticleSystem_getX(lua_State * L);
|
int w_ParticleSystem_getX(lua_State * L);
|
||||||
int w_ParticleSystem_getY(lua_State * L);
|
int w_ParticleSystem_getY(lua_State * L);
|
||||||
int w_ParticleSystem_getDirection(lua_State * L);
|
int w_ParticleSystem_getDirection(lua_State * L);
|
||||||
int w_ParticleSystem_getSpread(lua_State * L);
|
int w_ParticleSystem_getSpread(lua_State * L);
|
||||||
|
int w_ParticleSystem_getOffsetX(lua_State * L);
|
||||||
|
int w_ParticleSystem_getOffsetY(lua_State * L);
|
||||||
int w_ParticleSystem_count(lua_State * L);
|
int w_ParticleSystem_count(lua_State * L);
|
||||||
int w_ParticleSystem_start(lua_State * L);
|
int w_ParticleSystem_start(lua_State * L);
|
||||||
int w_ParticleSystem_stop(lua_State * L);
|
int w_ParticleSystem_stop(lua_State * L);
|
||||||
|
|||||||
Reference in New Issue
Block a user