projects
/
xscreensaver
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver]
/
hacks
/
glx
/
topblock.c
diff --git
a/hacks/glx/topblock.c
b/hacks/glx/topblock.c
index eed2fd54f775fa0522bbb19a2fcf54ed88613b02..9161d38d16d6f364c1e38e2a9770b367f5277f82 100644
(file)
--- a/
hacks/glx/topblock.c
+++ b/
hacks/glx/topblock.c
@@
-28,7
+28,7
@@
History
#include <math.h>
#include <math.h>
-# define re
fresh
_topBlock 0
+# define re
lease
_topBlock 0
#define DEFAULTS "*delay: 10000 \n" \
"*count: 30 \n" \
#define DEFAULTS "*delay: 10000 \n" \
"*count: 30 \n" \
@@
-55,6
+55,10
@@
typedef struct
{
GLXContext *glx_context;
trackball_state *trackball;
{
GLXContext *glx_context;
trackball_state *trackball;
+ GLfloat rotateSpeed;
+ GLfloat dropSpeed;
+ int maxFalling;
+ int resolution;
Bool button_down_p;
int numFallingBlocks;
GLfloat highest,highestFalling;
Bool button_down_p;
int numFallingBlocks;
GLfloat highest,highestFalling;
@@
-154,7
+158,14
@@
ENTRYPOINT void
reshape_topBlock (ModeInfo *mi, int width, int height)
{
GLfloat h = (GLfloat) height / (GLfloat) width;
reshape_topBlock (ModeInfo *mi, int width, int height)
{
GLfloat h = (GLfloat) height / (GLfloat) width;
- glViewport (0, 0, (GLint) width, (GLint) height);
+ int y = 0;
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width*1.5;
+ y = -height*0.2;
+ h = height / (GLfloat) width;
+ }
+ glViewport (0, y, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (60.0, 1/h, 1.0, 1000.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (60.0, 1/h, 1.0, 1000.0);
@@
-165,7
+176,7
@@
reshape_topBlock (ModeInfo *mi, int width, int height)
/* clean up on exit, not required ... */
ENTRYPOINT void
/* clean up on exit, not required ... */
ENTRYPOINT void
-
releas
e_topBlock(ModeInfo *mi)
+
fre
e_topBlock(ModeInfo *mi)
{
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
NODE *llCurrent, *llOld;
{
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
NODE *llCurrent, *llOld;
@@
-184,11
+195,7
@@
init_topBlock (ModeInfo *mi)
topBlockSTATE *tb;
int wire = MI_IS_WIREFRAME(mi);
topBlockSTATE *tb;
int wire = MI_IS_WIREFRAME(mi);
- if (!tbs) {
- tbs = (topBlockSTATE *)
- calloc (MI_NUM_SCREENS(mi), sizeof (topBlockSTATE));
- if (!tbs) abort();
- }
+ MI_INIT (mi, tbs);
tb = &tbs[MI_SCREEN(mi)];
tb = &tbs[MI_SCREEN(mi)];
@@
-204,27
+211,31
@@
init_topBlock (ModeInfo *mi)
tb->carpetWidth = 8 * size;
tb->carpetLength = tb->carpetWidth;
tb->carpetWidth = 8 * size;
tb->carpetLength = tb->carpetWidth;
- maxFalling*=size;
+ tb->maxFalling = maxFalling;
+ tb->maxFalling*=size;
if (spawn<4) { spawn=4; }
if (spawn>1000) { spawn=1000; }
if (spawn<4) { spawn=4; }
if (spawn>1000) { spawn=1000; }
- if (rotateSpeed<1) {rotateSpeed=1; }
- if (rotateSpeed>1000) {rotateSpeed=1000;}
- rotateSpeed /= 100;
+ tb->rotateSpeed = rotateSpeed;
+ if (tb->rotateSpeed<1) {tb->rotateSpeed=1; }
+ if (tb->rotateSpeed>1000) {tb->rotateSpeed=1000;}
+ tb->rotateSpeed /= 100;
- if (resolution<4) {resolution=4;}
- if (resolution>20) {resolution=20;}
- resolution*=2;
+ tb->resolution = resolution;
+ if (tb->resolution<4) {tb->resolution=4;}
+ if (tb->resolution>20) {tb->resolution=20;}
+ tb->resolution*=2;
if (maxColors<1) {maxColors=1;}
if (maxColors>8) {maxColors=8;}
if (maxColors<1) {maxColors=1;}
if (maxColors>8) {maxColors=8;}
- if (dropSpeed<1) {dropSpeed=1;}
- if (dropSpeed>9) {dropSpeed=9;} /* 10+ produces blocks that can pass through each other */
+ tb->dropSpeed = dropSpeed;
+ if (tb->dropSpeed<1) {tb->dropSpeed=1;}
+ if (tb->dropSpeed>9) {tb->dropSpeed=9;} /* 10+ produces blocks that can pass through each other */
-
dropSpeed = 80/
dropSpeed;
- dropSpeed = (blockHeight/dropSpeed);
+
tb->dropSpeed = 80/tb->
dropSpeed;
+ tb->dropSpeed = (blockHeight/tb->dropSpeed);
reshape_topBlock (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
glClearDepth(1.0f);
reshape_topBlock (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
glClearDepth(1.0f);
@@
-303,7
+314,7
@@
draw_topBlock (ModeInfo *mi)
generateNewBlock(mi);
generateNewBlock(mi);
- if (rotate && (!tb->button_down_p)) { tb->rotation +=
rotateSpeed; }
+ if (rotate && (!tb->button_down_p)) { tb->rotation +=
tb->rotateSpeed; }
if (tb->rotation>=360) { tb->rotation=tb->rotation-360; }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* clear current */
if (tb->rotation>=360) { tb->rotation=tb->rotation-360; }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* clear current */
@@
-409,7
+420,7
@@
draw_topBlock (ModeInfo *mi)
spcN2y = 0;
if (llCurrent->height>tb->highestFalling) {tb->highestFalling=llCurrent->height;}
/* all blocks fall at the same rate to avoid mid air collisions */
spcN2y = 0;
if (llCurrent->height>tb->highestFalling) {tb->highestFalling=llCurrent->height;}
/* all blocks fall at the same rate to avoid mid air collisions */
- llCurrent->height-=dropSpeed;
+ llCurrent->height-=
tb->
dropSpeed;
if (llCurrent->height<=0) {
llCurrent->falling=0;
if (tb->highest==0) {
if (llCurrent->height<=0) {
llCurrent->falling=0;
if (tb->highest==0) {
@@
-498,7
+509,7
@@
draw_topBlock (ModeInfo *mi)
if (mi->fps_p) do_fps (mi);
glFinish();
if (mi->fps_p) do_fps (mi);
glFinish();
- if (tb->highest>(5*maxFalling)) { drawCarpet=False; }
+ if (tb->highest>(5*
tb->
maxFalling)) { drawCarpet=False; }
glXSwapBuffers(dpy, window);
}
glXSwapBuffers(dpy, window);
}
@@
-584,7
+595,7
@@
static void generateNewBlock(ModeInfo *mi)
llTail = llCurrent;
tb->blockNodeRoot = llCurrent;
} else {
llTail = llCurrent;
tb->blockNodeRoot = llCurrent;
} else {
- if (tb->numFallingBlocks>=maxFalling) {
+ if (tb->numFallingBlocks>=
tb->
maxFalling) {
/* recycle */
llCurrent=llTail->next;
tb->blockNodeRoot=llCurrent->next;
/* recycle */
llCurrent=llTail->next;
tb->blockNodeRoot=llCurrent->next;
@@
-622,7
+633,7
@@
static void generateNewBlock(ModeInfo *mi)
llCurrent->y=(startOffy-(tb->carpetLength/2)) + getLocation(random() % ((tb->carpetLength/2)+endOffy) );
llCurrent->color=(random() % maxColors);
llCurrent->height=getHeight(tb->plusheight+tb->highest);
llCurrent->y=(startOffy-(tb->carpetLength/2)) + getLocation(random() % ((tb->carpetLength/2)+endOffy) );
llCurrent->color=(random() % maxColors);
llCurrent->height=getHeight(tb->plusheight+tb->highest);
- if (tb->numFallingBlocks>=maxFalling) {
+ if (tb->numFallingBlocks>=
tb->
maxFalling) {
tb->numFallingBlocks--;
tb->numFallingBlocks--;
}
tb->numFallingBlocks--;
tb->numFallingBlocks--;
}
@@
-702,7
+713,7
@@
static void buildCarpet(ModeInfo *mi)
tb->carpet_polys += tube(0, 0, -0.1,
0, 0, 0.26,
cylSize, 0,
tb->carpet_polys += tube(0, 0, -0.1,
0, 0, 0.26,
cylSize, 0,
- resolution, True, True,
+
tb->
resolution, True, True,
wire);
glRotatef(180, 0.0f, 1.0f, 0.0f); /* they are upside down */
glRotatef(180, 0.0f, 1.0f, 0.0f); /* recover */
wire);
glRotatef(180, 0.0f, 1.0f, 0.0f); /* they are upside down */
glRotatef(180, 0.0f, 1.0f, 0.0f); /* recover */
@@
-758,7
+769,7
@@
static void buildBlock(ModeInfo *mi)
tb->block_polys += tube(0, 0, 0,
0, 0, 0.25,
cylSize, 0,
tb->block_polys += tube(0, 0, 0,
0, 0, 0.25,
cylSize, 0,
- resolution, True, True,
+ tb->resolution, True, True,
wire);
glTranslatef(0.0f,0.0f,0.25f); /* move to the cylinder cap */
glTranslatef(0.0f,0.0f,-0.25f); /* move back from the cylinder cap */
wire);
glTranslatef(0.0f,0.0f,0.25f); /* move to the cylinder cap */
glTranslatef(0.0f,0.0f,-0.25f); /* move back from the cylinder cap */
@@
-778,7
+789,7
@@
static void buildBlock(ModeInfo *mi)
tb->block_polys += tube(0, 0, 0.1,
0, 0, 1.4,
uddSize, 0,
tb->block_polys += tube(0, 0, 0.1,
0, 0, 1.4,
uddSize, 0,
- resolution, True, True, wire);
+
tb->
resolution, True, True, wire);
glTranslatef(0.0f,-1.0f,0.0f); /* move to the center */
}
}
glTranslatef(0.0f,-1.0f,0.0f); /* move to the center */
}
}
@@
-798,11
+809,11
@@
static void buildBlobBlock(ModeInfo *mi)
glNewList(tb->block,GL_COMPILE);
glPushMatrix();
glScalef(1.4,1.4,1.4);
glNewList(tb->block,GL_COMPILE);
glPushMatrix();
glScalef(1.4,1.4,1.4);
- unit_sphere (
resolution/2,
resolution, wire);
+ unit_sphere (
tb->resolution/2,tb->
resolution, wire);
glPopMatrix();
glTranslatef(0.0f,-2.0f,0.0f);
glScalef(1.4,1.4,1.4);
glPopMatrix();
glTranslatef(0.0f,-2.0f,0.0f);
glScalef(1.4,1.4,1.4);
- unit_sphere (
resolution/2,
resolution, wire);
+ unit_sphere (
tb->resolution/2,tb->
resolution, wire);
glEndList();
}
glEndList();
}