summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Bosveld <joel@joel-desktop.(none)>2008-01-19 15:42:49 +0900
committerJoel Bosveld <joel@joel-desktop.(none)>2008-01-19 15:42:49 +0900
commit31f81c893b20a53443c5575b39480cbeba8160be (patch)
tree6e4e19a57993497530864b80fe4c87bd14289c3b
parent100c434d9daad13584c997c1474b3eb1649ab6a2 (diff)
downloadcubedbus-31f81c893b20a53443c5575b39480cbeba8160be.tar.gz
cubedbus-31f81c893b20a53443c5575b39480cbeba8160be.tar.bz2
Added basic particle system
The 'link' to cubefx is just made for testing, also the way data is stored in particles is soon to be changed. I also will be doing some work on the emitters (as it is only hard coded at the moment for testing)
-rw-r--r--cubedbus.c23
-rw-r--r--cubedbusModel.c.in1
-rw-r--r--cubedbusParticle.c.in109
-rw-r--r--cubedbusStd.c.in9
-rw-r--r--particleFx/death.c.in46
-rw-r--r--particleFx/draw.c.in22
-rw-r--r--particleFx/emitter.c.in109
-rw-r--r--particleFx/move.c.in20
-rw-r--r--particleFx/particleFxPrework76
-rwxr-xr-xscripts/model.sh2
-rwxr-xr-xscripts/window.sh3
11 files changed, 417 insertions, 3 deletions
diff --git a/cubedbus.c b/cubedbus.c
index 776ea4d..5d4d7a5 100644
--- a/cubedbus.c
+++ b/cubedbus.c
@@ -67,6 +67,7 @@ CubedbusScreen;
#define CUBEDBUS_SCREEN(s) \
CubedbusScreen *gs = GET_CUBEDBUS_SCREEN(s, GET_CUBEDBUS_DISPLAY(s->display)) /* Macros to get the gs pointer to CubedbusScreen struct */
+#include "cubedbusParticle.c.in"
#include "cubedbusModel.c.in"
#include "cubedbusWindow.c.in"
#include "cubedbusTexture.c.in"
@@ -360,6 +361,28 @@ cubedbusPaintInside (CompScreen *s,
glPushMatrix();
glLoadMatrixf (mT.m);
+
+ FILE *fp=fopen("/tmp/compiz.matrix","w");
+ fprintf(fp, "%f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n %f \n",
+ mT.m[0],
+ mT.m[1],
+ mT.m[2],
+ mT.m[3],
+ mT.m[4],
+ mT.m[5],
+ mT.m[6],
+ mT.m[7],
+ mT.m[8],
+ mT.m[9],
+ mT.m[10],
+ mT.m[11],
+ mT.m[12],
+ mT.m[13],
+ mT.m[14],
+ mT.m[15]);
+
+ fclose(fp);
+
glTranslatef (cs->outputXOffset, -cs->outputYOffset, 0.0f); /* OpenGL stuff to set correct transformation due to cube rotation? */
glScalef (cs->outputXScale, cs->outputYScale, 1.0f);
diff --git a/cubedbusModel.c.in b/cubedbusModel.c.in
index dd40f8b..190c5bc 100644
--- a/cubedbusModel.c.in
+++ b/cubedbusModel.c.in
@@ -644,4 +644,3 @@ findPath (char *object, char *file)
return filePath;
}
-
diff --git a/cubedbusParticle.c.in b/cubedbusParticle.c.in
new file mode 100644
index 0000000..4eecd7d
--- /dev/null
+++ b/cubedbusParticle.c.in
@@ -0,0 +1,109 @@
+#define CUBEDBUS_PARTICLE_OBJECT 6
+
+typedef struct _CubedbusParticleObject CubedbusParticleObject;
+
+#include "particleFx/particleFxPrework"
+
+static bool cubedbusDrawParticleObject (CubedbusObject *obj);
+static bool cubedbusDeleteParticleObject (CubedbusObject *obj);
+static bool cubedbusModifyParticleObject (CubedbusObject *obj, CompOption *option, int nOption);
+static bool cubedbusAddParticleObject (CubedbusObject *obj, CompOption *option, int nOption);
+
+struct _CubedbusParticleObject
+{
+CompFxParticleEmitter *emitter;
+bool order;
+float rotate[4], translate[3], scale[3];
+float rotateSpeed;
+};
+
+
+static bool
+cubedbusDrawParticleObject (CubedbusObject *obj)
+{
+ glShadeModel (GL_SMOOTH);
+
+ CubedbusParticleObject *data=obj->data;
+
+ if(data->order) glTranslatef (data->translate[0], data->translate[1], data->translate[2]);
+ glRotatef ( data->rotate[0], data->rotate[1], data->rotate[2], data->rotate[3]);
+ if(!(data->order)) glTranslatef (data->translate[0], data->translate[1], data->translate[2]);
+
+ glScalef( data->scale[0],data->scale[1], data->scale[2]); /* Rotate, translate and scale */
+
+
+ (data->emitter->compFxParticleEmitterStepProc) (data->emitter);
+
+ CompFxParticle *particle;
+ CompFxParticle *nextPart;
+
+ for(particle=data->emitter->head; particle != NULL; particle=nextPart)
+ {
+ nextPart=particle->next;
+
+ glPushMatrix();
+ (particle->compFxParticleDrawProc) (particle);
+ (particle->compFxParticleMoveProc) (particle);
+ (particle->compFxParticleDeathProc) (particle);
+ glPopMatrix();
+ }
+
+ data->rotate[0]+=data->rotateSpeed;
+ if(data->rotate[0]>360) data->rotate[0]=0;
+ if(data->rotate[0]<0) data->rotate[0]=360;
+
+
+ return TRUE;
+}
+
+static bool
+cubedbusDeleteParticleObject (CubedbusObject *obj)
+{
+
+ return TRUE;
+}
+
+static bool
+cubedbusModifyParticleObject (CubedbusObject *obj, CompOption *option, int nOption)
+{
+ return TRUE;
+}
+
+static bool
+cubedbusAddParticleObject (CubedbusObject *obj, CompOption *option, int nOption)
+{
+ obj->data= malloc( sizeof(CubedbusParticleObject) );
+ if(obj->data == NULL) return FALSE;
+
+ CubedbusParticleObject *particleData=obj->data;
+
+ particleData->rotate[0]=getFloatOptionNamed (option,nOption, "rotateAngle", 0.0);
+ particleData->rotate[1]=getFloatOptionNamed (option,nOption, "rotateX", 0.0);
+ particleData->rotate[2]=getFloatOptionNamed (option,nOption, "rotateY", 0.0);
+ particleData->rotate[3]=getFloatOptionNamed (option,nOption, "rotateZ", 0.0);
+ particleData->translate[0]=getFloatOptionNamed (option,nOption, "translateX", 0.0);
+ particleData->translate[1]=getFloatOptionNamed (option,nOption, "translateY", 0.0);
+ particleData->translate[2]=getFloatOptionNamed (option,nOption, "translateZ", 0.0);
+ particleData->scale[0]=getFloatOptionNamed (option,nOption, "scaleX", 1.0);
+ particleData->scale[1]=getFloatOptionNamed (option,nOption, "scaleY", 1.0);
+ particleData->scale[2]=getFloatOptionNamed (option,nOption, "scaleZ", 1.0);
+ particleData->order=getBoolOptionNamed (option, nOption, "order", TRUE);
+ particleData->rotateSpeed= getFloatOptionNamed (option, nOption, "rotateSpeed", 0);
+
+ particleData->emitter = malloc (sizeof (CompFxParticleEmitter));
+ if(particleData->emitter == NULL)
+ {
+ compLogMessage (NULL, "cubeFX", CompLogLevelWarn, "Failed to init emitter");
+ return FALSE;
+ }
+
+ particleData->emitter->next = NULL;
+ particleData->emitter->prev = NULL;
+ particleData->emitter->head = particleData->emitter->tail = NULL;
+ particleData->emitter->nParticles=0;
+ particleData->emitter->compFxParticleEmitterStepProc = &compFxParticleCreateEmitterColour;
+
+
+ return TRUE;
+}
+
diff --git a/cubedbusStd.c.in b/cubedbusStd.c.in
index f2325a1..2cadaef 100644
--- a/cubedbusStd.c.in
+++ b/cubedbusStd.c.in
@@ -103,6 +103,15 @@ cubedbusAddStdObject (CompOption *option, int nOption, CubedbusObject *head, Com
return (objptr->addfunc) (objptr, option, nOption);
}
+ case CUBEDBUS_PARTICLE_OBJECT:
+ {
+ objptr->func =&cubedbusDrawParticleObject; /* function called when drawing */
+ objptr->delfunc=&cubedbusDeleteParticleObject; /* function called when deleting */
+ objptr->modfunc=&cubedbusModifyParticleObject; /* function called when modifying */
+ objptr->addfunc=&cubedbusAddParticleObject; /* function called when adding */
+
+ return (objptr->addfunc) (objptr, option, nOption);
+ }
default:
return FALSE;
}
diff --git a/particleFx/death.c.in b/particleFx/death.c.in
new file mode 100644
index 0000000..6ceb6c0
--- /dev/null
+++ b/particleFx/death.c.in
@@ -0,0 +1,46 @@
+/* Destroy particle */
+
+static void
+compFxParticleDestroy (CompFxParticle *particle)
+{
+ particle->emitter->nParticles--;
+
+ free(particle->baseData);
+ free(particle->drawData);
+ free(particle->moveData);
+ free(particle->deathData);
+
+ if(particle->prev == NULL) particle->emitter->head = particle->next;
+ else particle->prev->next = particle->next;
+
+ if(particle->next == NULL) particle->emitter->tail = particle->prev;
+ else particle->next->prev = particle->prev;
+}
+
+/***************************************\
+* Particle dies after a set time period *
+\***************************************/
+
+typedef struct _CompFxParticleDeathTimeoutData CompFxParticleDeathTimeoutData;
+
+struct _CompFxParticleDeathTimeoutData
+{
+ long timeout;
+};
+
+static void
+compFxParticleDeathTimeout (CompFxParticle *particle)
+{
+ CompFxParticleBaseData *baseData = particle->baseData;
+ CompFxParticleDeathTimeoutData *deathData = particle->deathData;
+
+ baseData->lifetime++;
+
+ if (baseData->lifetime >= deathData->timeout)
+ {
+ compFxParticleDestroy (particle);
+ free(particle);
+ }
+}
+
+
diff --git a/particleFx/draw.c.in b/particleFx/draw.c.in
new file mode 100644
index 0000000..0f09b9f
--- /dev/null
+++ b/particleFx/draw.c.in
@@ -0,0 +1,22 @@
+/* Data and functions for a standard coloured particle */
+
+typedef struct _CompFxParticleDrawColourData CompFxParticleDrawColourData;
+
+struct _CompFxParticleDrawColourData
+{
+ GLuint dList;
+ GLfloat r, g, b;
+};
+
+static void
+compFxParticleDrawColour (CompFxParticle *particle)
+{
+ CompFxParticleBaseData *baseData = particle->baseData;
+ CompFxParticleDrawColourData *drawData = particle->drawData;
+
+ glTranslatef (baseData->x, baseData->y, baseData->z);
+ glColor3f (drawData->r, drawData->g, drawData->b);
+
+ glCallList(drawData->dList);
+}
+
diff --git a/particleFx/emitter.c.in b/particleFx/emitter.c.in
new file mode 100644
index 0000000..c20f7db
--- /dev/null
+++ b/particleFx/emitter.c.in
@@ -0,0 +1,109 @@
+/* Emitter functions */
+
+static CompFxParticle
+*compFxParticleCreate (CompFxParticleEmitter *emitter)
+{
+ if(emitter->head == NULL)
+ {
+ emitter->head = malloc (sizeof (CompFxParticle));
+ if(emitter->head == NULL) return NULL;
+
+ emitter->tail = emitter->head;
+ emitter->tail->prev = NULL;
+ }
+ else
+ {
+ emitter->tail->next = malloc (sizeof (CompFxParticle));
+ if(emitter->tail->next == NULL) return NULL;
+
+ emitter->tail->next->prev = emitter->tail;
+ emitter->tail = emitter->tail->next;
+ }
+
+ emitter->tail->next = NULL;
+ emitter->tail->emitter = emitter;
+
+ emitter->tail->baseData = malloc (sizeof (CompFxParticleBaseData));
+ if(emitter->tail->baseData == NULL)
+ {
+ if(emitter->tail->prev == NULL)
+ {
+ emitter->head = NULL;
+ free(emitter->tail);
+ emitter->tail = NULL;
+ }
+ else
+ {
+ emitter->tail = emitter->tail->prev;
+ free(emitter->tail->next);
+ emitter->tail->next = NULL;
+ }
+
+ return NULL;
+ }
+ emitter->tail->baseData->x=0;
+ emitter->tail->baseData->y=0;
+ emitter->tail->baseData->z=0;
+ emitter->tail->baseData->lifetime=0;
+
+ return emitter->tail;
+}
+
+/* Hardcoded emitter - XXX - for testing only */
+static void
+compFxParticleCreateEmitterColour (CompFxParticleEmitter *emitter)
+{
+ CompFxParticle *particle = NULL;
+
+ if(emitter->nParticles >= 1000)
+ {
+ }
+ else if( (particle = compFxParticleCreate (emitter)) == NULL) /* this function sets up the emitter, next, prev and baseData fields */
+ {
+ compLogMessage (NULL, "particleFX", CompLogLevelWarn, "Creating particle failed - memory error");
+ }
+ else
+ {
+ emitter->nParticles++;
+
+ particle->compFxParticleDrawProc = &compFxParticleDrawColour;
+ particle->drawData = malloc (sizeof (CompFxParticleDrawColourData));
+
+ particle->compFxParticleMoveProc = &compFxParticleMoveLinear;
+ particle->moveData = malloc (sizeof (CompFxParticleMoveLinearData));
+
+ particle->compFxParticleDeathProc = &compFxParticleDeathTimeout;
+ particle->deathData = malloc (sizeof (CompFxParticleDeathTimeoutData));
+
+ CompFxParticleDrawColourData *draw = particle->drawData;
+ CompFxParticleMoveLinearData *move = particle->moveData;
+ CompFxParticleDeathTimeoutData *death = particle->deathData;
+
+ /* XXX Generate dList XXX*/
+
+ draw->dList=glGenLists (1);
+ glNewList (draw->dList, GL_COMPILE);
+
+ glBegin(GL_TRIANGLES);
+
+ glVertex3f (0,0,0);
+ glVertex3f (0,0.01,0);
+ glVertex3f (0.01,0,0);
+
+ glEnd();
+ glEndList();
+
+ draw->r=(double) rand() / ((double) RAND_MAX+1);
+ draw->g=(double) rand() / ((double) RAND_MAX+1);
+ draw->b=(double) rand() / ((double) RAND_MAX+1);
+
+ move->vx= .00125-(0.0025 * (double) rand() / ((double) RAND_MAX+1));
+ move->vy= (0.0050 * (double) rand() / ((double) RAND_MAX+1));
+ move->vz= .00125-(0.0025 * (double) rand() / ((double) RAND_MAX+1));
+
+ death->timeout = 600;
+ }
+}
+
+
+
diff --git a/particleFx/move.c.in b/particleFx/move.c.in
new file mode 100644
index 0000000..56dc97e
--- /dev/null
+++ b/particleFx/move.c.in
@@ -0,0 +1,20 @@
+/* Some movement patterns */
+
+typedef struct _CompFxParticleMoveLinearData CompFxParticleMoveLinearData;
+
+struct _CompFxParticleMoveLinearData
+{
+ GLfloat vx, vy, vz;
+};
+
+static void
+compFxParticleMoveLinear (CompFxParticle *particle)
+{
+ CompFxParticleBaseData *baseData = particle->baseData;
+ CompFxParticleMoveLinearData *moveData = particle->moveData;
+
+ baseData->x += moveData->vx;
+ baseData->y += moveData->vy;
+ baseData->z += moveData->vz;
+}
+
diff --git a/particleFx/particleFxPrework b/particleFx/particleFxPrework
new file mode 100644
index 0000000..3729bd3
--- /dev/null
+++ b/particleFx/particleFxPrework
@@ -0,0 +1,76 @@
+/* Structs for particle system */
+
+typedef struct _CompFxParticle CompFxParticle;
+typedef struct _CompFxParticleBaseData CompFxParticleBaseData;
+typedef struct _CompFxParticleEmitter CompFxParticleEmitter;
+
+struct _CompFxParticle
+{
+ CompFxParticleEmitter *emitter;
+
+ CompFxParticle *next;
+ CompFxParticle *prev;
+
+ void (*compFxParticleDrawProc) (CompFxParticle *particle);
+ void (*compFxParticleMoveProc) (CompFxParticle *particle);
+ void (*compFxParticleDeathProc) (CompFxParticle *particle);
+
+ CompFxParticleBaseData *baseData;
+
+ void *drawData;
+ void *moveData;
+ void *deathData;
+};
+
+struct _CompFxParticleBaseData
+{
+ GLfloat x, y, z;
+ long lifetime;
+};
+
+
+
+
+/* Particle emmiter structs and functions */
+
+
+
+struct _CompFxParticleEmitter
+{
+ CompFxParticleEmitter *next;
+ CompFxParticleEmitter *prev;
+
+ CompFxParticle *head;
+ CompFxParticle *tail;
+
+ int nParticles;
+
+ void (*compFxParticleEmitterStepProc) (CompFxParticleEmitter *emitter); /* This is where we create particles */
+};
+
+/**********************************************************/
+#include "death.c.in" /* Death functions and structs */
+#include "move.c.in" /* Move functions and structs */
+#include "draw.c.in" /* Draw functions and structs */
+/******************************************************/
+
+#include "emitter.c.in"
+
+
+
+typedef union
+{
+ int i;
+ long l;
+ float f;
+ double d;
+ void *p;
+} CompFxParticleData;
+
+typedef struct _CompFxParticleDataSet
+{
+ char *name;
+ CompFxParticleData *data; /* array containing data union */
+}
+
+
diff --git a/scripts/model.sh b/scripts/model.sh
index 67df481..d13c40d 100755
--- a/scripts/model.sh
+++ b/scripts/model.sh
@@ -1,3 +1,3 @@
-dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/cubedbus/allscreens/add org.freedesktop.compiz.activate string:'root' int32:`xwininfo -root | grep id: | awk '{ print $4 }'` string:'type' int32:5 string:'name' string:'root.model' string:'file' string:$1
+dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/cubedbus/allscreens/add org.freedesktop.compiz.activate string:'root' int32:`xwininfo -root | grep id: | awk '{ print $4 }'` string:'type' int32:5 string:'name' string:'root.model' string:'file' string:$1 string:'rotateY' double:1.0 string:'rotateSpeed' double:1.0
#Run this in terminal - accepts as argument 1 .obj file
diff --git a/scripts/window.sh b/scripts/window.sh
index 228a4b8..5b309dd 100755
--- a/scripts/window.sh
+++ b/scripts/window.sh
@@ -1,3 +1,4 @@
-dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/cubedbus/allscreens/add org.freedesktop.compiz.activate string:'root' int32:`xwininfo -root | grep id: | awk '{ print $4 }'` string:'type' int32:4 string:'name' string:'root.window' string:'x0' double:-0.5 string:'y0' double:0.5 string:'z0' double:-0.5 string:'x1' double:-0.5 string:'y1' double:0.5 string:'z1' double:0.5 string:'x2' double:-0.5 string:'y2' double:-0.5 string:'z2' double:0.5 string:'x3' double:-0.5 string:'y3' double:-0.5 string:'z3' double:-0.5 string:'win' int32:` xwininfo | grep id: | awk '{ print $4 }'`
+dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/cubedbus/allscreens/add org.freedesktop.compiz.activate string:'root' int32:`xwininfo -root | grep id: | awk '{ print $4 }'` string:'type' int32:4 string:'name' string:'root.window' string:'x0' double:-0.5 string:'y0' double:0.5 string:'z0' double:-0.5 string:'x1' double:-0.5 string:'y1' double:0.5 string:'z1' double:0.5 string:'x2' double:-0.5 string:'y2' double:-0.5 string:'z2' double:0.5 string:'x3' double:-0.5 string:'y3' double:-0.5 string:'z3' double:-0.5 string:'win' int32:` xwininfo | grep id: | awk '{ print $4 }'` string:'rotateY' double:1.0 string:'rotateSpeed' double:1.0
+
#Run this in terminal - then click on a window to draw it in cube