summaryrefslogtreecommitdiff
path: root/cubedbusObject.c.in
blob: 70cfc3522d7a86b12e7b477e75d860bbbb5ce448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#define CUBEDBUS_OBJECT 1

typedef struct _CubedbusObj CubedbusObj;


static bool cubedbusDrawObj (CubedbusObject *obj);
static bool cubedbusDeleteObj (CubedbusObject *obj);
static bool cubedbusModifyObj (CubedbusObject *obj, CompOption *option, int nOption);
static bool cubedbusAddObj (CubedbusObject *obj, CompOption *option, int nOption);

struct _CubedbusObj
{
bool order;
float rotate[4], translate[3], scale[3];
float rotateSpeed;

CubedbusObject *firstChild;
};

static bool
cubedbusDrawObj (CubedbusObject *obj)
{
		CubedbusObj *data=obj->data;
		
		glPushMatrix();
		
			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->rotate[0]+=data->rotateSpeed;
    	if(data->rotate[0]>360) data->rotate[0]=0;
    	if(data->rotate[0]<0) data->rotate[0]=360;
		
		CubedbusObject *objptr=data->firstChild;
		
		while(1)
			{
			glColor4usv (defaultColor);
					
			if(objptr == NULL) break;
								
			glPushMatrix();

				if(! (objptr->func) (objptr) ) return false;
				objptr=objptr->next;
			glPopMatrix();
			}	
		glPopMatrix();	
	return TRUE;
}

static bool
cubedbusDeleteObj (CubedbusObject *obj)
{
	CubedbusObj *data=obj->data;
	
	CubedbusObject *objptr=data->firstChild;
		
		while(1)
			{
			if(objptr == NULL) break;
			if(! (objptr->delfunc) (objptr) ) return false;
			objptr=objptr->next;
			}	
	
	free(obj->data);
	free(obj);
			
	return TRUE;
}

static bool
cubedbusModifyObj (CubedbusObject *obj, CompOption *option, int nOption)
{
	return TRUE;
}

static bool
cubedbusAddObj (CubedbusObject *obj, CompOption *option, int nOption)
{
	obj->data= malloc( sizeof(CubedbusObj) );
		if(obj->data == NULL) return FALSE;
		
	CubedbusObj *data=obj->data;	
	
	data->rotate[0]=getFloatOptionNamed (option,nOption, "rotateAngle", 0.0);
	data->rotate[1]=getFloatOptionNamed (option,nOption, "rotateX", 0.0);
	data->rotate[2]=getFloatOptionNamed (option,nOption, "rotateY", 0.0);
	data->rotate[3]=getFloatOptionNamed (option,nOption, "rotateZ", 0.0);
	data->translate[0]=getFloatOptionNamed (option,nOption, "translateX", 0.0);
	data->translate[1]=getFloatOptionNamed (option,nOption, "translateY", 0.0);
	data->translate[2]=getFloatOptionNamed (option,nOption, "translateZ", 0.0);
	data->scale[0]=getFloatOptionNamed (option,nOption, "scaleX", 1.0);
	data->scale[1]=getFloatOptionNamed (option,nOption, "scaleY", 1.0);
	data->scale[2]=getFloatOptionNamed (option,nOption, "scaleZ", 1.0);
	data->order=getBoolOptionNamed (option, nOption, "order", TRUE);
	data->rotateSpeed=getFloatOptionNamed (option, nOption, "rotateSpeed", 0);
	data->firstChild=NULL;
	
	return TRUE;
}