summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-12-08 21:17:38 +0900
committerJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-12-08 21:17:38 +0900
commit3041e5b70d837f3aae2cee6c30054d12a6f7b1cf (patch)
tree2c5fa5bcde64a006d3d25491feada8fbb0c89782
parent72b136f3df7505d92cf9afe44dcb1d27c0803bc1 (diff)
downloadcubedbus-3041e5b70d837f3aae2cee6c30054d12a6f7b1cf.tar.gz
cubedbus-3041e5b70d837f3aae2cee6c30054d12a6f7b1cf.tar.bz2
Now does 3 passes over file. Faces can be defind before the vertices
now. Now will also recognize quads (soon it will allow for arbitrarily large polygons)
-rw-r--r--cubedbus.c1
-rw-r--r--cubedbusModel.c.in163
-rw-r--r--window3
3 files changed, 99 insertions, 68 deletions
diff --git a/cubedbus.c b/cubedbus.c
index e6d9184..74c77b1 100644
--- a/cubedbus.c
+++ b/cubedbus.c
@@ -345,6 +345,7 @@ cubedbusPaintInside (CompScreen *s,
{
CUBEDBUS_SCREEN (s);
CUBE_SCREEN (s);
+
Bool enabled;
diff --git a/cubedbusModel.c.in b/cubedbusModel.c.in
index ef06a70..c45b801 100644
--- a/cubedbusModel.c.in
+++ b/cubedbusModel.c.in
@@ -55,30 +55,29 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
modelData->rotateSpeed=getFloatOptionNamed (option, nOption, "rotateSpeed", 0);
- FILE *fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
- if(fp == NULL)
- {
- compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Failed to open model file");
- return FALSE;
- }
-
- /* read file and store info in proper location */
-
int c;
char *strline=NULL;
int n=0;
char *tmp=NULL;
- char *tmpType[4];
-
-
+ char **tmpType;
int nVertex=0;
int nNormal=0;
int nTexture=0;
- int nTri=0;
- int vertNum=0;
-
+
+
+ /* First pass - count how much data we need to store */
+
+ FILE *fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
+ if(fp == NULL)
+ {
+ compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Failed to open model file");
+ return FALSE;
+ }
+
+
+
while( (c=getc(fp) ) != EOF )
{
tmp=realloc(tmp, sizeof(char)*(n+1));
@@ -93,7 +92,9 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
strline[n]=c;
if(c=='\n') /*the line is ended, copy stuff to array, and prepare for next line */
{
- /* code to move stuff to array */
+ tmpType=malloc(sizeof (char *) );
+ if(tmpType == NULL) return FALSE;
+
tmpType[0]=strsep(&strline," ");
if(tmpType[0] == NULL)
{
@@ -114,11 +115,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
{
nTexture++;
}
-
- if(!strcmp(tmpType[0], "f"))
- {
- nTri++;
- }
+
/* prepare for next line */
// free(strline);
n=0;
@@ -129,7 +126,9 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
}
fclose (fp);
-
+
+ /* Second pass - fill arrays */
+
vect3d vertex[nVertex];
vect3d normal[nNormal];
vect2d texture[nTexture];
@@ -137,18 +136,15 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
nVertex=0;
nNormal=0;
nTexture=0;
-
-fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
+
+ fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
+
if(fp == NULL)
{
compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Failed to open model file");
return FALSE;
}
-
- modelData->dList=glGenLists (1);
- glNewList (modelData->dList, GL_COMPILE);
-
while( (c=getc(fp) ) != EOF )
{
tmp=realloc(tmp, sizeof(char)*(n+1));
@@ -164,6 +160,7 @@ fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
if(c=='\n') /*the line is ended, copy stuff to array, and prepare for next line */
{
/* code to move stuff to array */
+ tmpType = malloc ( sizeof (char *) * 4);
tmpType[0]=strsep(&strline," ");
if(tmpType[0] == NULL)
{
@@ -204,47 +201,85 @@ fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
nVertex++;
}
- if(!strcmp(tmpType[0], "f"))
+ /* prepare for next line */
+ // free(strline);
+ n=0;
+ tmp=NULL;
+ continue;
+ }
+ n++;
+ }
+
+ fclose (fp);
+
+ int vertNum=0;
+ int polyCount;
+ char *tempPtr;
+
+
+ /* Final (third) pass - use data */
+
+ fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
+ if(fp == NULL)
+ {
+ compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Failed to open model file");
+ return FALSE;
+ }
+
+
+ modelData->dList=glGenLists (1);
+ glNewList (modelData->dList, GL_COMPILE);
+
+ while( (c=getc(fp) ) != EOF )
+ {
+ tmp=realloc(tmp, sizeof(char)*(n+1));
+ if(tmp == NULL)
+ {
+ compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file - out of mem");
+ free(strline);
+ return FALSE;
+ }
+ strline=tmp; /* The strline array should now be big enough to hold all characters read so far, plus the one being read */
+
+ strline[n]=c;
+ if(c=='\n') /*the line is ended, copy stuff to array, and prepare for next line */
+ {
+
+ tmpType = malloc ( sizeof(char *) * 5); /* XXX need dynamically resizing array - makes assumption that quad is highest polygon */
+ tmpType[0]=strsep(&strline," ");
+ if(tmpType[0] == NULL)
{
- tmpType[1]=strsep(&strline," ");
- if(tmpType[1] == NULL)
+ compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file...");
+ free(strline);
+ return FALSE;
+ }
+ if(!strcmp(tmpType[0], "f"))
+ {
+ glBegin(GL_POLYGON);
+
+ polyCount=1;
+
+ while(1)
{
- compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file...");
- free(strline);
- return FALSE;
- }
+ tmpType[polyCount]=strsep(&strline," ");
- tmpType[2]=strsep(&strline," ");
- if(tmpType[2] == NULL)
- {
- compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file...");
- free(strline);
- return FALSE;
- }
-
- tmpType[3]=strsep(&strline," ");
- if(tmpType[3] == NULL)
- {
- compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file...");
- free(strline);
- return FALSE;
- }
+ tempPtr=strsep(&tmpType[polyCount],"/");
+ if(tempPtr == NULL) break;
+
+ vertNum=atoi(tempPtr);
- /* tmpType[1,2,3] are the "coord/texCoord/normal" number for the point in triangle */
-
-
- glBegin(GL_TRIANGLES);
- vertNum=atoi(strsep(&tmpType[1],"/"));
- glVertex3f (vertex[vertNum-1].x,vertex[vertNum-1].y,vertex[vertNum-1].z);
- /* also need to do normal and tex coord */
- vertNum=atoi(strsep(&tmpType[2],"/"));
+ /* XXX also need to do normal and tex coord */
glVertex3f (vertex[vertNum-1].x,vertex[vertNum-1].y,vertex[vertNum-1].z);
- vertNum=atoi(strsep(&tmpType[3],"/"));
- glVertex3f (vertex[vertNum-1].x,vertex[vertNum-1].y,vertex[vertNum-1].z);
- glEnd();
- }
+
+ polyCount++ ;
+ }
+
+ glEnd();
+ }
+
+
/* prepare for next line */
- // free(strline);
+ // free(strline) (cannot free lines that have been strsep'd?);
n=0;
tmp=NULL;
continue;
@@ -256,8 +291,6 @@ fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
glEndList();
-
-
return TRUE;
}
diff --git a/window b/window
deleted file mode 100644
index 0e7aa08..0000000
--- a/window
+++ /dev/null
@@ -1,3 +0,0 @@
-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.photowheel' 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 }'`
-
-#Run this in terminal - then click on a window to draw it in cube