summaryrefslogtreecommitdiff
path: root/snowglobe-internal.h
blob: ca9682984ea844600f1369fa6d2489539b182645 (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
#ifndef _SNOWGLOBE_INTERNAL_H
#define _SNOWGLOBE_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 snowglobeDisplayPrivateIndex;
extern int cubeDisplayPrivateIndex;

#define GET_SNOWGLOBE_DISPLAY(d) \
    ((SnowglobeDisplay *) (d)->base.privates[snowglobeDisplayPrivateIndex].ptr)
#define SNOWGLOBE_DISPLAY(d) \
    SnowglobeDisplay *ad = GET_SNOWGLOBE_DISPLAY(d);

#define GET_SNOWGLOBE_SCREEN(s, ad) \
    ((SnowglobeScreen *) (s)->base.privates[(ad)->screenPrivateIndex].ptr)
#define SNOWGLOBE_SCREEN(s) \
    SnowglobeScreen *as = GET_SNOWGLOBE_SCREEN(s, GET_SNOWGLOBE_DISPLAY(s->display))


typedef struct _snowflakeRec
{
    float x, y, z;
    float theta, psi;
    float dpsi, dtheta;
    float speed, size;
}
snowflakeRec;

typedef struct _Vertex
{
    float v[3];
    float n[3];
}
Vertex;

typedef struct _Water
{
    int      size;
    float    distance;
    int      sDiv;

    float  bh;
    float  wa;
    float  swa;
    float  wf;
    float  swf;

    Vertex       *vertices;
    unsigned int *indices;

    unsigned int nVertices;
    unsigned int nIndices;

    unsigned int nSVer;
    unsigned int nSIdx;
    unsigned int nWVer;
    unsigned int nWIdx;

    float    wave1;
    float    wave2;
}
Water;

typedef struct _SnowglobeDisplay
{
    int screenPrivateIndex;
}
SnowglobeDisplay;

typedef struct _SnowglobeScreen
{
    DonePaintScreenProc donePaintScreen;
    PreparePaintScreenProc preparePaintScreen;

    CubeClearTargetOutputProc clearTargetOutput;
    CubePaintInsideProc       paintInside;

    Bool damage;

    int numSnowflakes;
    
    snowflakeRec *snow;
    
    Water *water;
    Water *ground;
    
    GLuint snowflakeDisplayList;
    
    float xRotate;
    float vRotate;
}
SnowglobeScreen;

void
updateWater (CompScreen *s, float time);

void
updateGround (CompScreen *s, float time);

void
updateHeight (Water *w);

void
freeWater (Water *w);

void
drawWater (Water *w, Bool full, Bool wire);

void
drawGround (Water *w, Water *g);

void
drawBottomGround (int size, float distance, float bottom);

Bool
isInside (CompScreen *s, float x, float y, float z);

float
getHeight (Water *w, float x, float z);



void SnowflakeTransform(snowflakeRec *);
void newSnowflakePosition(SnowglobeScreen *, int);
void SnowflakeDrift (CompScreen *, int);

void initializeWorldVariables(int, float);
void updateSpeedFactor(float);
void RenderWater(int, float, Bool, Bool);

void DrawSnowflake (int);
void initDrawSnowflake(void);
void finDrawSnowflake(void);

void DrawSnowman (int);

//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!
float symmDistr(void); //symmetric distribution

//maybe define a struct for these values
float speedFactor; // global variable (fish/crab speeds multiplied by this value)
float radius;//radius on which the hSize points lie
float distance;//perpendicular distance to wall from centre
float waterHeight; //water surface height
int waveGridSize;
float waveAmplitude;
float waveFrequency;
float smallWaveAmplitude;
float smallWaveFrequency;
Bool renderGround;




//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 hSize; // horizontal desktop size
float q;   // equal to float version of hSize (replace with hSizef some time)


#endif