summaryrefslogtreecommitdiff
path: root/rubik-internal.h
blob: 6758d36a3613365ededf82c4faaeae1dd6b732f9 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef _RUBIK_INTERNAL_H
#define _RUBIK_INTERNAL_H

#define RAD 57.296
#define RRAD 0.01745

/* some constants */
#define PI     3.14159265358979323846
#define PIdiv2 1.57079632679489661923
#define toDegrees 57.2957795130823208768
#define toRadians 0.01745329251994329577


#define LRAND()                 ((long) (random() & 0x7fffffff))
#define NRAND(n)                ((int) (LRAND() % (n)))
#define MAXRAND                 (2147483648.0) /* unsigned 1<<31 as a float */


#include <math.h>
#include <float.h>

#include <math.h>
#include <compiz-core.h>
#include <compiz-cube.h>

extern int rubikDisplayPrivateIndex;
extern int cubeDisplayPrivateIndex;

#define GET_RUBIK_DISPLAY(d) \
    ((RubikDisplay *) (d)->base.privates[rubikDisplayPrivateIndex].ptr)
#define RUBIK_DISPLAY(d) \
    RubikDisplay *rd = GET_RUBIK_DISPLAY(d);

#define GET_RUBIK_SCREEN(s, rd) \
    ((RubikScreen *) (s)->base.privates[(rd)->screenPrivateIndex].ptr)
#define RUBIK_SCREEN(s) \
    RubikScreen *rs = GET_RUBIK_SCREEN(s, GET_RUBIK_DISPLAY(s->display))

#define GET_RUBIK_WINDOW(w, rs) \
    ((RubikWindow *) (w)->base.privates[(rs)->windowPrivateIndex].ptr)

#define RUBIK_WINDOW(w) \
    RubikWindow *rw = GET_RUBIK_WINDOW  (w, \
                       GET_RUBIK_SCREEN  (w->screen, \
                       GET_RUBIK_DISPLAY (w->screen->display)))

#define WIN_REAL_X(w) (w->attrib.x - w->input.left)
#define WIN_REAL_Y(w) (w->attrib.y - w->input.top)

#define WIN_REAL_W(w) (w->width + w->input.left + w->input.right)
#define WIN_REAL_H(w) (w->height + w->input.top + w->input.bottom)


#define NRAND(n)                ((int) (LRAND() % (n)))

#define RANDOMCOLOR	1
#define BLACK		2
#define BLUE		3
#define BROWN		4
#define CYAN		5
#define GREEN		6
#define GREY		7
#define ORANGE		8
#define PINK		9
#define PURPLE		10
#define RED			11
#define YELLOW		12
#define WHITE		13

typedef struct _RubikDisplay
{
    int screenPrivateIndex;
}
RubikDisplay;


typedef struct _squareRec
{
	int side;
	int x;
	int y;
	int psi;
}
squareRec;


typedef struct _faceRec
{
	float  color[4];
	
	squareRec *square;
}
faceRec;



typedef struct _RubikScreen
{
    int windowPrivateIndex;
    
	DonePaintScreenProc donePaintScreen;
    PreparePaintScreenProc preparePaintScreen;

    CubeClearTargetOutputProc clearTargetOutput;
    CubePaintInsideProc       paintInside;

    PaintOutputProc paintOutput;
    PaintWindowProc paintWindow;
    DrawWindowProc drawWindow;
    PaintTransformedOutputProc paintTransformedOutput;

    DrawWindowTextureProc drawWindowTexture;
    
    DamageWindowRectProc damageWindowRect;
    
    DisableOutputClippingProc disableOutputClipping;

    AddWindowGeometryProc addWindowGeometry;
    
	CubeGetRotationProc	getRotation;

	
    Bool initiated;
    
    Bool damage;
    
    CompTransform * tempTransform;
    
	float *th;
	float *oldTh;

	float *psi;
	float *oldPsi;

	CompWindow ** w;
	
    Box * oldClip;

    faceRec *faces;
    
    int hsize;
    float distance;    //perpendicular distance to wall from centre
    float radius;      //radius on which the hSize points lie
    
    float speedFactor; // multiply rotation speed by this value
    
}
RubikScreen;

typedef struct _RubikWindow{
    DrawWindowGeometryProc drawWindowGeometry;
}
RubikWindow;


void rubikGetRotation( CompScreen *s, float *x, float *v );

void initializeWorldVariables(CompScreen *s);
void initFaces( CompScreen *s);
void updateSpeedFactor(float);



//utility methods
float randf(float); //random float
float minimum(float,float); //my compiler at home didn't have min or fminf!
float maximum(float,float); //nor did it have max or fmaxf!
void setColor(float *, float, float, float, float, float, float);
void setSpecifiedColor (float *, int);
void rotateClockwise (squareRec * square);
void rotateAnticlockwise (squareRec * square);


//All calculations that matter with angles are done clockwise from top.
//I think of it as x=radius, y=0 being the top (towards 1st desktop from above view)
//and the z coordinate as height.


int vStrips;
int currentVStrip; 

int hStrips;
int currentHStrip;

float currentStripCounter;
int currentStripDirection;

int rotationAxis; //0 - horizontal
				  //1 - vertical from 1st viewport
				  //2 - vertical from 2nd viewport

#endif