From 016c66c96e8beb2d8c906880811ce75fa2eed50a Mon Sep 17 00:00:00 2001 From: Pierce Brooks Date: Mon, 30 Dec 2024 02:05:04 -0500 Subject: [PATCH] initial commit --- #Makefile# | 80 ++ Asserts.C | 33 + Asserts.h | 25 + Board.C | 458 +++++++++++ Board.h | 46 ++ CornerPiece.C | 85 ++ CoverSheet.txt | 18 + CubePiece.C | 84 ++ DList.C | 167 ++++ DList.h | 67 ++ Description.txt | 4 + FourD.C | 124 +++ FourD.h | 40 + GenPiece.C | 273 +++++++ GenPiece.h | 46 ++ Hyper.C | 470 +++++++++++ Hyper.h | 48 ++ LPiece.C | 84 ++ Main.C | 869 ++++++++++++++++++++ Makefile | 52 ++ Pieces.h | 76 ++ README | 215 +++++ README-VERSION | 80 ++ Refrences.txt | 22 + Rotor.C | 155 ++++ Rotor.h | 36 + SPiece.C | 83 ++ Shared.C | 44 + Shared.h | 76 ++ SharedFunctions.h | 50 ++ SimplePiece.C | 47 ++ StraightPiece.C | 84 ++ TPiece.C | 84 ++ ThreeLinePiece.C | 73 ++ TriPiece.C | 76 ++ TwistyPiece.C | 84 ++ TwoPiece.C | 72 ++ ZPiece.C | 89 ++ appenda1_3soj.htm | 1856 ++++++++++++++++++++++++++++++++++++++++++ cpp.mf | 24 + ht.mf | 49 ++ htetris.mf | 52 ++ htetris.test | 54 ++ htetristest.makefile | 50 ++ ml.c | 551 +++++++++++++ ml3.gkf | 474 +++++++++++ pulled.txt | 354 ++++++++ skel.c | 309 +++++++ slevy.mf | 52 ++ so_locations | 3 + unknown.txt | 32 + website.txt | 1 + 52 files changed, 8380 insertions(+) create mode 100644 #Makefile# create mode 100644 Asserts.C create mode 100644 Asserts.h create mode 100644 Board.C create mode 100644 Board.h create mode 100644 CornerPiece.C create mode 100644 CoverSheet.txt create mode 100644 CubePiece.C create mode 100644 DList.C create mode 100644 DList.h create mode 100644 Description.txt create mode 100644 FourD.C create mode 100644 FourD.h create mode 100644 GenPiece.C create mode 100644 GenPiece.h create mode 100644 Hyper.C create mode 100644 Hyper.h create mode 100644 LPiece.C create mode 100644 Main.C create mode 100644 Makefile create mode 100644 Pieces.h create mode 100644 README create mode 100644 README-VERSION create mode 100644 Refrences.txt create mode 100644 Rotor.C create mode 100644 Rotor.h create mode 100644 SPiece.C create mode 100644 Shared.C create mode 100644 Shared.h create mode 100644 SharedFunctions.h create mode 100644 SimplePiece.C create mode 100644 StraightPiece.C create mode 100644 TPiece.C create mode 100644 ThreeLinePiece.C create mode 100644 TriPiece.C create mode 100644 TwistyPiece.C create mode 100644 TwoPiece.C create mode 100644 ZPiece.C create mode 100644 appenda1_3soj.htm create mode 100755 cpp.mf create mode 100755 ht.mf create mode 100755 htetris.mf create mode 100755 htetris.test create mode 100755 htetristest.makefile create mode 100644 ml.c create mode 100644 ml3.gkf create mode 100644 pulled.txt create mode 100644 skel.c create mode 100755 slevy.mf create mode 100644 so_locations create mode 100644 unknown.txt create mode 100644 website.txt diff --git a/#Makefile# b/#Makefile# new file mode 100644 index 0000000..f325b02 --- /dev/null +++ b/#Makefile# @@ -0,0 +1,80 @@ +OBJS = Main.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + + +#************************************************************************** +# Change this line if you don't like 'a.out'. + +EXENAME = a.out + + +#************************************************************************** +# Macros defining the C/C++ compiler and linker. + +CC = CC +CCOPTS = +w +LINK = CC +LINKOPTS = /usr/lib/libgl_s.a /usr/lib/libc_s.a /usr/lib/libm.a /usr/lib/libX11_s.a + +# don't remove /usr/lib/libgl_s.a from linkopts, the compiler doesn't +# know what it's talking about + +GLINC = -I/usr/local/include +GLUTINC = -I/usr/local/include/GL +GLUTINC = -I/afs/ncsa.uiuc.edu/projects/MATH428/illiMath/glut + +#GLUTLIB = -L/usr/local/lib -lglut +GLUTLIB = -L/afs/ncsa.uiuc.edu/projects/MATH428/illiMath/glut -lglut +GLLIB = -L/usr/local/lib -lGL -lGLU +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + +OPT = -o32 +CFLAGS = ${OPT} ${GLINC} ${GLUTINC} +LDFLAGS = ${OPT} ${GLUTLIB} ${GLLIB} ${SYSLIBS} +#LDFLAGS = ${OPT} ${GLUTLIB} + + +#************************************************************************** +# Rules for building EXENAME from OBJS and OBJS from your source. + +$(EXENAME): $(OBJS) + $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJS) + +clean: + -rm *.o $(EXENAME) +# -rm -rf Templates.DB +.C.o: + $(CC) $(CFLAGS) $(LDFLAGS) -c $< + +.cc.o: + $(CC) $(CFLAGS) $(LDFLAGS) -c $< + +.c.o: + $(CC) $(CFLAGS) $(LDFLAGS) -c $< + + + + + + + + + diff --git a/Asserts.C b/Asserts.C new file mode 100644 index 0000000..67d8594 --- /dev/null +++ b/Asserts.C @@ -0,0 +1,33 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Asserts.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Asserts.h" + +// Given: A SafeCondition, in the form of a boolean expression, and a ErrMsg +// Task: If the SafeCondition isn't true, then the ErrMsg is displayed to +// to the screen as an error and the program is terminated +// Return: Nothing +void Assert(int SafeCondition, char* ErrMsg) +{ + if (!SafeCondition) { + cerr << "***Error: " << ErrMsg << endl; + exit(1); + } +} + +// Given: A SafeCondition, in the form of a boolean expression, and a ErrMsg +// Task: If the SafeCondition isn't true, then the ErrMsg is displayed to +// to the screen as a warning +// Return: Nothing +void Warn(int SafeCondition, char* ErrMsg) +{ + if (!SafeCondition) + cerr << "***Warning: " << ErrMsg << endl; +} diff --git a/Asserts.h b/Asserts.h new file mode 100644 index 0000000..c978326 --- /dev/null +++ b/Asserts.h @@ -0,0 +1,25 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Asserts.h +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +////////////////////////////////////////////////////////////////////////////// +// Note: For descriptions of the functions, look at Asserts.C // +////////////////////////////////////////////////////////////////////////////// + +#ifndef ASSERTS_H +#define ASSERTS_H + +#include // for the exit(1) +#include + +void Assert(int SafeCondition, char* ErrMsg); + +void Warn(int SafeCondition, char* ErrMsg); + +#endif diff --git a/Board.C b/Board.C new file mode 100644 index 0000000..32f4aff --- /dev/null +++ b/Board.C @@ -0,0 +1,458 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Board.C +// Last modified: May 8th, 2001 - Benjamin Bernard +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Board.h" + +extern float *LEN; +extern int *DIM; +extern float *botcorner; + +// Given: Nothing +// Task: Create a new board +// Return: Nothing, but the new board has been created +Board::Board() +{ + boardarray = new char***[DIM[X]]; + + for (int i = 0; i < DIM[X]; i++) { + boardarray[i] = new char**[DIM[Y]]; + for (int j = 0; j < DIM[Y]; j++) { + boardarray[i][j] = new char*[DIM[Z]]; + for (int k = 0; k < DIM[Z]; k++) { + boardarray[i][j][k] = new char[DIM[W]]; + for (int l = 0; l < DIM[W]; l++) + boardarray[i][j][k][l] = EMPTY; + } + } + } + + float *topcorner = new float[4]; + for (i = 0; i < 4; i++) + topcorner[i] = botcorner[i] + .01 + DIM[i] * LEN[i]; + + float temp[16][4]; + for (i = 0; i < 16; i++) { + for (int j = 0; j < 4; j++) + temp[i][j] = ((i & (1<<(3-j))) ? (botcorner[j] - .01) : topcorner[j]); + } + + delete topcorner; + + bottom = new FourD*[8]; + for (i = 0; i < 8; i++) + bottom[i] = new FourD(temp[(15 - 2 * i)]); + + + top = new FourD*[8]; + for (i = 0; i < 8; i++) + top[i] = new FourD(temp[14 - 2*i]); + + fallen = new DList(); +} + + +// Given: Nothing +// Task: Free all of the memory used by this board object +// Return: Nothing, but the memory has been freed +Board::~Board() +{ + for (int i = 0; i < DIM[X]; i++) { + for (int j = 0; j < DIM[Y]; j++) { + for (int k = 0; k < DIM[Z]; k++) + delete boardarray[i][j][k]; + delete boardarray[i][j]; + } + delete boardarray[i]; + } + delete boardarray; + + delete fallen; + + for (i = 0; i < 8; i++) { + delete bottom[i]; + delete top[i]; + } + + delete bottom; + delete top; +} + + +// Given: An integer pointer with a position +// Task: Assume the position is within the board, and simply check +// to see if it is FILLED +// Return: 0 if it is FILLED, 1 if it is not +int Board::GoodSpotShort(int *pos) +{ +#ifdef DEBUG_BOARD + cout << "Begin Board::GoodSpotShort(...)" << endl; +#endif + + if (pos[W] >= DIM[W]) + return 1; + + return ((boardarray[pos[0]][pos[1]][pos[2]][pos[3]] == FILLED) ? 0 : 1); +} + + +// Given: An integer pointer with a position +// Task: Deterime if the position is within the board, and if it +// is, whether or not it is FILLED +// Return: 0 if off of board or FILLED, 1 if the position is EMPTY +int Board::GoodSpot(int *pos) +{ + if ((pos[X] >= DIM[X]) || (pos[X] < 0) || (pos[Y] >= DIM[Y]) || + (pos[Y] < 0) || (pos[Z] >= DIM[Z]) || (pos[Z] < 0) || (pos[W] < 0)) + return 0; + + if (pos[W] >= DIM[W]) + return 1; + + return (boardarray[pos[0]][pos[1]][pos[2]][pos[3]] == EMPTY); +} + + +// Given: An integer pointer with a position +// Task: Make the given board position EMPTY +// Return: Nothing (but the position is now EMPTY) +void Board::EmptySpot(int *pos) +{ + boardarray[pos[0]][pos[1]][pos[2]][pos[3]] = EMPTY; +} + + +// Given: An integer pointer with a position +// Task: Make the given board position FILLED +// Return: Nothing (but the position in now FILLED) +void Board::FillSpot(int *pos) +{ + boardarray[pos[0]][pos[1]][pos[2]][pos[3]] = FILLED; +} + + +// Given: A list of hypercubes, with the number that are in the list +// Task: Add each hypercube to the fallen list, and dim its color +// Return: 0 if any of these hypercubes are off of the board, 1 if +// all of them are on the board +int Board::DonePiece(Hyper **newcubes, int numcubes) +{ +#ifdef DEBUG_BOARD + cout << "Begin Board::DonePiece(..., "<GetPos()[W] >= DIM[W]) + return 0; + FillSpot(newcubes[i]->GetPos()); + newcubes[i]->DimColor(); + fallen->InsertAfter(newcubes[i]); + } + + return 1; + +#ifdef DEBUG_BOARD + cout << "End Board::DonePiece(..., "<= 0; ww--) { + int boolean = 0; + int xx = 0; + while (boolean && (xx < DIM[X])) { + int yy = 0; + while (boolean && (yy < DIM[Y])) { + int zz = 0; + while (boolean && (zz < DIM[Z])) { + boolean = boardarray[xx][yy][zz][ww] == FILLED; + zz++; + } + yy++; + } + xx++; + } + + if (boolean) { + numremoved++; + RemoveCube(ww); + } + } + + return numremoved; +} + + +// Given: An integer axes which tell of the projection for the drawing +// Task: Draw the outline of the board, and any fallen hypercubes +// Return: Nothing, but the board has been drawn +void Board::Drawit(int axes) +{ + // draw the cubes that have fallen + if (fallen->NotEmpty()) { + fallen->Head(); + fallen->Get()->Drawit(axes); + while (!fallen->EndOfList()) { + (*fallen)++; + fallen->Get()->Drawit(axes); + } + } + + // now draw the "background" which has the bottom, a line, and two sides + if (axes != 7) { + //int *axis = new int[3]; + int axis[3]; + + switch (axes) { + case 11: + axis[0] = W; + axis[1] = X; + axis[2] = Y; + break; + + case 13: + axis[0] = Z; + axis[1] = W; + axis[2] = X; + break; + + case 14: + axis[0] = Y; + axis[1] = Z; + axis[2] = W; + break; + } + + //float *dist = new float[3]; + float dist[3]; + + for (int i = 0; i < 3; i++) + dist[i] = 0.0; + + switch (axes) { + case 11: + cpack(0xff990000); // needs alpha set to ff to be shown, I guess + bgnline(); + bottom[6]->Plot(axis, dist); + top[6]->Plot(axis, dist); + endline(); + break; + + case 13: + cpack(0xff009900); + bgnline(); + bottom[5]->Plot(axis, dist); + top[5]->Plot(axis, dist); + endline(); + break; + + case 14: + cpack(0xff000099); + bgnline(); + bottom[3]->Plot(axis, dist); + top[3]->Plot(axis, dist); + endline(); + break; + } + glEnable(GL_BLEND); + blendfunction(BF_SA, BF_MSA); + // cpack(0x66ffffff); + glColor4f(.6, .6, .6, (float)66/255); + // cout << "alpha is: " << (float)66/255 << endl; + // cout << "Number is: " << 0x66ffffff << endl; + + bgntmesh(); + for (i = 4; i < 4; i++) + bottom[i]->Plot(axis, dist); + endtmesh(); + + bgntmesh(); + for (i = 4; i < 8; i++) + bottom[i]->Plot(axis, dist); + endtmesh(); + + bgntmesh(); + for (i = 0; i < 2; i++) + bottom[i]->Plot(axis, dist); + for (i = 4; i < 6; i++) + bottom[i]->Plot(axis, dist); + endtmesh(); + + bgntmesh(); + for (i = 2; i < 4; i++) + bottom[i]->Plot(axis, dist); + for (i = 6; i < 8; i++) + bottom[i]->Plot(axis, dist); + endtmesh(); + + bgntmesh(); + for (i = 0; i < 8; i += 2) + bottom[i]->Plot(axis, dist); + endtmesh(); + + bgntmesh(); + for (i = 1; i < 8; i += 2) + bottom[i]->Plot(axis, dist); + endtmesh(); + + // negative == 99, positive == ff + // x is red + // y is green + // z is blue + + switch (axes) { + case 11: //wxy + // cpack(0x33000099); + glColor4f((float)99/255, 0,0, (float)33/255); + bgntmesh(); + bottom[0]->Plot(axis, dist); + top[0]->Plot(axis, dist); + bottom[2]->Plot(axis, dist); + top[2]->Plot(axis, dist); + endtmesh(); + + // cpack(0x33009900); + glColor4f(0,(float)99/255,0, (float)33/255); + bgntmesh(); + bottom[0]->Plot(axis, dist); + top[0]->Plot(axis, dist); + bottom[4]->Plot(axis, dist); + top[4]->Plot(axis, dist); + endtmesh(); + break; + + case 13: //zwx + // cpack(0x33000099); + glColor4f((float)99/255, 0,0, (float)33/255); + bgntmesh(); + bottom[0]->Plot(axis, dist); + top[0]->Plot(axis, dist); + bottom[1]->Plot(axis, dist); + top[1]->Plot(axis, dist); + endtmesh(); + + // cpack(0x33990000); + glColor4f(0,0,(float)99/255, (float)33/255); + bgntmesh(); + bottom[0]->Plot(axis, dist); + top[0]->Plot(axis, dist); + bottom[4]->Plot(axis, dist); + top[4]->Plot(axis, dist); + endtmesh(); + break; + + case 14: //yzw + // cpack(0x33009900); + glColor4f(0, (float)99/255,0, (float)33/255); + bgntmesh(); + bottom[0]->Plot(axis, dist); + top[0]->Plot(axis, dist); + bottom[1]->Plot(axis, dist); + top[1]->Plot(axis, dist); + endtmesh(); + + // cpack(0x33990000); + glColor4f(0, 0,(float)99/255, (float)33/255); + bgntmesh(); + bottom[0]->Plot(axis, dist); + top[0]->Plot(axis, dist); + bottom[2]->Plot(axis, dist); + top[2]->Plot(axis, dist); + endtmesh(); + break; + } + + // glDisable(GL_BLEND); + //delete dist; + //delete axis; + } // if (axes != 7) +} + + +// Given: A coordinate, in terms of board coordinates, in W +// Task: Remove all of the hypercubes which have this W coordinate, and +// crop all of the hypcubes above this W coordinate down one +// Return: Nothing, but the board has been taken care of +void Board::RemoveCube(int wcoord) +{ +#ifdef DEBUG_BOARD + cout << "Begin RemoveCube("<Head(); + while (FindAtW(fallen, wcoord)) { + Hyper *temp = fallen->Get(); + fallen->Remove(); + EmptySpot(temp->GetPos()); + delete temp; + } + + int boolean = 1; + fallen->Head(); + while (boolean && FindAboveW(fallen, wcoord)) { + EmptySpot(fallen->Get()->GetPos()); + fallen->Get()->Translate(W, -1); + FillSpot(fallen->Get()->GetPos()); + if (fallen->EndOfList()) + boolean = 0; + else + (*fallen)++; + } + +#ifdef DEBUG_BOARD + cout << "End RemoveCube("< *List, int wcoord) +{ + Node *Search = List->current; + while (Search != NULL) + if (Search->data->GetPos()[W] > wcoord) { + List->current = Search; + return 1; + } else + Search = Search->next; + + return 0; +} + + +// Given: A list of hypercubes and a W coordinate +// Task: Find the next cube in the list with this W coordinate, and +// point the current pointer at it +// Return: 0 if there are no such cubes in the list, 1 if there is such +// a cube in the list +int FindAtW(DList *List, int wcoord) +{ + Node *Search = List->current; + while (Search != NULL) + if (Search->data->GetPos()[W] == wcoord) { + List->current = Search; + return 1; + } else + Search = Search->next; + + return 0; +} diff --git a/Board.h b/Board.h new file mode 100644 index 0000000..ef45f0d --- /dev/null +++ b/Board.h @@ -0,0 +1,46 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Board.h +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _BOARD_H_ +#define _BOARD_H_ + +#include "Shared.h" +#include "Hyper.h" +#include "DList.h" +#include "FourD.h" + +#define FILLED (char)(1) +#define EMPTY (char)(0) + +class Board { + +public: + Board(); + ~Board(); + + int GoodSpotShort(int *pos); + int GoodSpot(int *pos); + void EmptySpot(int *pos); + void FillSpot(int *pos); + + int DonePiece(Hyper **newcubes, int numcubes); + void Drawit(int axes); + + int CheckBoard(); // checks for filled cubes + void RemoveCube(int wcoord); // deletes the cube with the wcoord + +private: + char ****boardarray; + DList *fallen; + FourD **bottom; + FourD **top; +}; + +#endif diff --git a/CornerPiece.C b/CornerPiece.C new file mode 100644 index 0000000..87bfd39 --- /dev/null +++ b/CornerPiece.C @@ -0,0 +1,85 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// CornerPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +CornerPiece::CornerPiece() : GenPiece(4) +{ + centerstat = 2; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == W) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i] + ((i == X) ? -1 : 0); + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == Y) ? -1 : 0); + + /* + for (i = 0; i < 4; i++) + for (int k = 0; k < 4; k++) + cout << "newpos["<SetColor(0x00ffff); + } + + delete dudeman; + + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/CoverSheet.txt b/CoverSheet.txt new file mode 100644 index 0000000..6b30057 --- /dev/null +++ b/CoverSheet.txt @@ -0,0 +1,18 @@ +Cover Sheet - HyperTetris + +Name: Benjamin Bernard +Date: 5/9/01 + +Project Name: +hyperTetris + +Description: +Converting Greg Kaiser's 4D Tetris from IrisGL to OpenGL, in addition to adding some functionality. Doucmentation of changes in README-VERSION + +Location: +rtica source: /afs/ncsa.uiuc.edu/projects/MATH198/bernard/public/tetris/ +rtica executable: /afs/ncsa.uiuc.edu/projects/MATH198/bernard/public/tetris/tetris + +Public Demo on: 5/9/01 +Docs submitted on: 5/9/01 + diff --git a/CubePiece.C b/CubePiece.C new file mode 100644 index 0000000..98c3022 --- /dev/null +++ b/CubePiece.C @@ -0,0 +1,84 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// CubePiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +CubePiece::CubePiece() : GenPiece(4) +{ + centerstat = -1; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 (see documentation for picture) + newpos[0][i] = dudeman[i] + ((i == X) ? -1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i] + (((i == X) || (i == W)) ? -1 : 0); + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == W) ? -1 : 0); + +/* + for (i = 0; i < 4; i++) + for (int k = 0; k < 4; k++) + cout << "newpos["<SetColor(0x0000ff); + } + + delete dudeman; + + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/DList.C b/DList.C new file mode 100644 index 0000000..1d77f91 --- /dev/null +++ b/DList.C @@ -0,0 +1,167 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// DList.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "DList.h" + +//---------------------------DList CONSTRUCTORS----------------------// +//Given: nothing +//Task: creates generic constructor, with everything NULL +//Return: nothing +template +DList::DList() +{ + head = tail = current = NULL; + Assert(head==NULL || tail==NULL || current==NULL, + "Not enough memory to create list"); +} + +//Given: one element of type T +//Task: creates constructor with that element +//Return: nothing +template +DList::DList(T *e) +{ + Node *temp = new Node; + temp->data = e; + temp->next = temp->prev = NULL; + head = tail = current = temp; +} + +template +DList::~DList() +{ + if (head != NULL) + delete head; +} + + +//-----------------------------DList MANIPULATORS------------------------// + +template +void DList::Output() +{ + Node *Temp = head; + while (Temp != NULL) { + cout << Temp->data << endl; + Temp = Temp->next; + } +} + +//Given: one element of type T +//Task: inserts a new Node after the current pointer +//Return: nothing +template +void DList::InsertAfter(T *e) +{ + Node *temp = new Node; + temp->data = e; + + if(head==NULL && tail==NULL) { //empty list + temp->next = temp->prev = NULL; + current = head = tail = temp; + } else { + temp->next = current->next; + current->next = temp; + temp->prev = current; + if(current == tail) + tail = temp; + else + temp->next->prev = temp; + current = temp; + } +} + +//Given: one element of type T +//Task: inserts a new Node before the current pointer +//Return: nothing +template +void DList::InsertBefore(T *e) +{ + Node *temp = new Node; + temp->data = e; + + if(head==NULL && tail==NULL) { //empty list + temp->prev = temp->next = NULL; + current = head = tail = temp; + } else { + temp->prev = current->prev; + current->prev = temp; + temp->next = current; + if(current = head) + head = temp; + else + temp->prev->next = temp; + current = temp; + } +} + +//Given: nothing +//Task: removes the current Node +//Return: nothing +template +void DList::Remove() +{ + if(head==NULL && tail==NULL) //empty list + return; + + if(head==tail) //one Node list + head = tail = current = NULL; + else { + if(current!=head) + current->prev->next = current->next; + else + head = current->next; + if(current!=tail) + current->next->prev = current->prev; + else + tail = current->prev; + if (current->next == NULL) + current = tail; + else + current = current->next; + } +} + +template +Node *DList::ReturnCurrent() +{ + return current; +} + +template +void DList::ChangeCurrent(Node *NewCurrent) +{ + current = NewCurrent; +} + + +//------------------------DList CURRENT POINTER ADJUSTMENT-------------------// + +//Given: nothing +//Task: move current to next Node if not the last one +//Return: the list +template +DList& DList::operator++ (int) +{ + if(current != tail) + current = current->next; + return *this; +} + +//Given: nothing +//Task: move current to previous Node if not the first one +//Return: the list +template +DList& DList::operator-- (int) +{ + if(current != head) + current = current->prev; + return *this; +} diff --git a/DList.h b/DList.h new file mode 100644 index 0000000..36cb7be --- /dev/null +++ b/DList.h @@ -0,0 +1,67 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// DList.h +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _DLIST_H_ +#define _DLIST_H_ + +#include +#include "Asserts.h" +class Hyper; + +template +struct Node +{ + Node() {next = prev = NULL;}; + ~Node() {delete data; if (next != NULL) delete next;} + Node *next, + *prev; + T *data; +}; + +template +class DList +{ +friend int FindAboveW(DList *List, int wcoord); +friend int FindAtW(DList *List, int wcoord); + +private: + Node *head, + *tail, + *current; + +public: + //constructors + DList(); + DList(T *e); + ~DList(); + + void Output(); + + //list manipulation + void InsertAfter(T *e); + void InsertBefore(T *e); + void Remove(); + + //current pointer adjustment + inline void Head() {current = head;}; + inline void Tail() {current = tail;}; + DList& operator++ (int); + DList& operator-- (int); //remember to use (*p)++, etc + + //value retrieval + inline int NotEmpty() { return (head != NULL); } + inline T *Get() {return current->data;}; + inline int EndOfList() {return current==tail;}; + + Node *ReturnCurrent(); + void ChangeCurrent(Node *NewCurrent); +}; + +#endif diff --git a/Description.txt b/Description.txt new file mode 100644 index 0000000..c17e7b8 --- /dev/null +++ b/Description.txt @@ -0,0 +1,4 @@ +I have converted Gred Kaiser's 4D Tetris (hyperTetris) from IrisGL to OpenGL and GLUT. This will allow futher development of hyperTetris with modern tools. In this vain I have also made two modifications to the RTICA, you can now use the P key to pause the game and prevent pieces from automatically falling. In addition, I have added CTRL-Middle Click to re-activate the rotation of all of the quadrants. + +My change notes are in the README-VERSION file, in addition there is an extensive step-by-step set of zips in the history directory. + diff --git a/FourD.C b/FourD.C new file mode 100644 index 0000000..4c33a0c --- /dev/null +++ b/FourD.C @@ -0,0 +1,124 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// FourD.C +// Last modified: April 24, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include // for debugging purposes only + +#include "FourD.h" + + +// Given: Nothing +// Task: Default constructor +// Return: Nothing +FourD::FourD() +{ + pt = new float[4]; +} + + +// Given: A new x, y, z, and w coordinate +// Task: Create a point with these coordinates +// Return: Nothing, but the new point has been created +FourD::FourD(float x, float y, float z, float w) +{ + pt = new float[4]; pt[X] = x; pt[Y] = y; pt[Z] = z; pt[W] = w; +} + + +// Given: A pointer to new x, y, z, and w coordinates +// Task: Create a point with these coordinates +// Return: Nothing, but the new point has been created +FourD::FourD(float *newpt) +{ + pt = new float[4]; + for (int i = 0; i < 4; i++) + pt[i] = newpt[i]; + + Assert(pt != NULL, "Ran out of memory!!!"); +} + + +// Given: Nothing +// Task: Delete the memory used by this point +// Return: Nothing, but the memory has been freed +FourD::~FourD() +{ + delete pt; +} + + +// for debugging purposes only +void FourD::Output() +{ +#ifdef DEBUG_FOURD + cout << "Begin FourD::Output()" << endl; +#endif + + for (int i =0; i < 4; i++) + cout << pt[i] << " "; + cout << endl; + +#ifdef DEBUG_FOURD + cout << "End FourD::Output()" << endl; +#endif +} + + +// Given: Three axes for projection and a distancing factor +// Task: Plot this point in the given projection using the given factor +// Return: Nothing, but the point has been plotted +void FourD::Plot(int *axis, float *dist) +{ +#ifdef DEBUG_FOURD + cout << "Begin FourD::Plot(..., ...)" << endl; +#endif + + //float *temp = new float[3]; + float temp[3]; + + for (int i = 0; i < 3; i++) + temp[i] = pt[axis[i]] - .001 * dist[i]; + + v3f(temp); + //delete temp; +} + + +// Given: A change for each of the coordinates for this point +// Task: Increment each of the corrdinates by the given increments +// Return: Nothing, but the point has been translated +void FourD::Translate(float xx, float yy, float zz, float ww) +{ + pt[X] += xx; pt[Y] += yy; pt[Z] += zz; pt[W] += ww; +} + + +// Given: A center for rotation, the two axes for the plane of rotation, +// a the sign of the rotation +// Task: Rotate this point around the given center, in the given plane, +// in the given direction +// Return: Nothing, but the point has been rotated +void FourD::Rotate(FourD *center, int dir, int dude, int sign) +{ + float temp = pt[dir]; + + pt[dir] = ((pt[dude] - (*center)[dude]) * (float)(sign)) + (*center)[dir]; + pt[dude] = ((temp - (*center)[dir]) * -(float)(sign)) + (*center)[dude]; +} + + +// Given: An integer i +// Task: This is the subscript operator for the FourD point class +// Return: The value of the i coordinate +float& FourD::operator[](int i) +{ + Assert(((i < 4) && (i > -1)), "FourD array index out of range"); + + return pt[i]; +} diff --git a/FourD.h b/FourD.h new file mode 100644 index 0000000..d416056 --- /dev/null +++ b/FourD.h @@ -0,0 +1,40 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// FourD.h +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _FOURD_H_ +#define _FOURD_H_ + +#include "Asserts.h" +#include "Shared.h" +#include + +class FourD +{ + friend class Hyper; +public: + FourD(); + FourD(float x, float y, float z, float w); + FourD(float *newpts); + ~FourD(); + + void Output(); + + void Translate(float xx, float yy, float zz, float ww); + void Rotate(FourD *center, int dir, int dude, int sign); + + void Plot(int *axis, float *dist); + + float& operator[](int i); + +private: + float *pt; +}; + +#endif diff --git a/GenPiece.C b/GenPiece.C new file mode 100644 index 0000000..c5ef0b8 --- /dev/null +++ b/GenPiece.C @@ -0,0 +1,273 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// GenPiece.C +// Last modified: April 25, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "GenPiece.h" +#include +#include + +//#define DEBUG_GENPIECE + +extern Board *board; +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +// Given: The number of hypercubes in this piece +// Task: Allocate the appropriate number of Hypers for this piece +// Return: Nothing, but the Hypers have been allocated +GenPiece::GenPiece(int cubenum) +{ + numcubes = cubenum; + cubes = new Hyper*[numcubes]; +} + + +// Given: Nothing +// Task: Delete the memory used by this piece, but preserving the +// parts that were passed on to the board +// Return: Nothing, but the memory is cleared +GenPiece::~GenPiece() +{ + // don't delete the cubes, as they will become part of the board + // after this is done + delete center; +} + + +// Given: The two axes for the plane of rotation, and the sign of rotation +// Task: Determine if this piece can be rotated in the given plane and +// and the given direction +// Return: A pointer to the new board positions of each of the cubes if +// the given rotation is possible, otherwise, a pointer to NULL +int **GenPiece::CanRotate(int dir, int dude, int sign) +{ +#ifdef DEBUG_GENPIECE + cout << "Begin GenPiece::CanRotate(" << dir << ", " << sign << ")" << endl; +#endif + + int **newpos = new int*[numcubes]; + for (int i = 0; i < numcubes; i++) + newpos[i] = new int[4]; + + i = 0; + int boolean = 1; + int dircenter, dudecenter; + + if (centerstat < 0) { // center is messed up + dircenter = (int)(ffloor((((*center)[dir] - botcorner[dir])/LEN[dir])+.5)); + dudecenter = (int)(ffloor((((*center)[dude] - botcorner[dude])/LEN[dude]) + + .5)); + + } else { // center is (0,0) + dircenter = cubes[centerstat]->GetPos()[dir]; + dudecenter = cubes[centerstat]->GetPos()[dude]; + } + + while (boolean && (i < numcubes)) { + if (centerstat < 0) { + int dircoord = cubes[i]->GetPos()[dir]; + int dudecoord = cubes[i]->GetPos()[dude]; + + int dirchange = ((dircoord >= dircenter) ? 1 : 0); + int dudechange = ((dudecoord >= dudecenter) ? 1 : 0); + + dircoord += (-dircenter) + dirchange; + dudecoord += (-dudecenter) + dudechange; + + int tempcoord = dircoord; + dircoord = dudecoord * sign; + dudecoord = tempcoord * (-sign); + + dirchange = ((dircoord >= 0) ? 1 : 0); + dudechange = ((dudecoord >= 0) ? 1 : 0); + + dircoord += dircenter - dirchange; + dudecoord += dudecenter - dudechange; + + for (int j = 0; j < 4; j++) + newpos[i][j] = ((j == dir) ? dircoord : ((j == dude) ? dudecoord : + cubes[i]->GetPos()[j])); + + } else { + int dircoord = cubes[i]->GetPos()[dir] - dircenter; + int dudecoord = cubes[i]->GetPos()[dude] - dudecenter; + + int tempcoord = dircoord; + dircoord = dudecoord * sign; + dudecoord = tempcoord * (-sign); + + dircoord += dircenter; + dudecoord += dudecenter; + + for (int j = 0; j < 4; j++) + newpos[i][j] = ((j == dir) ? dircoord : ((j == dude) ? dudecoord : + cubes[i]->GetPos()[j])); + } + + boolean = board->GoodSpot(newpos[i]); + + i++; + } + +#ifdef DEBUG_GENPIECE + cout << "End GenPiece::CanRotate(...)" << endl; +#endif + + if (boolean) + return newpos; + return NULL; +} + + +// Given: Two axes of the plane of rotation, and a sign for the direction +// Task: If possible, perform the given rotation +// Return: Nothing, but if the piece could be rotated, then it's been rotated +void GenPiece::Rotate(int dir, int dude, int sign) +{ +#ifdef DEBUG_GENPIECE + cout << "Begin GenPiece::Rotate(" << dir << ", " << sign << ")" << endl; +#endif + + int **newpos = CanRotate(dir, dude, sign); + + if (newpos != NULL) { + for (int i = 0; i < numcubes; i++) + cubes[i]->Rotate(newpos[i], center, dir, dude, sign); + + for (i = 0; i < numcubes; i++) + delete newpos[i]; + delete newpos; + } + +#ifdef DEBUG_GENPIECE + cout << "End GenPiece::Rotate(...)" << endl; +#endif +} + + +// Given: A direction and sign for translation +// Task: If possible, perform the given translation on this piece +// Return: 1 if the translation was performed, 0 if it was impossible +int GenPiece::Translate(int dir, int sign) +{ +#ifdef DEBUG_GENPIECE + cout << "Begin GenPiece::Translate(" << dir << "," << sign << ")" << endl; +#endif + + int edge = ((sign == 1) ? DIM[dir] : -1); + + int **newpos = new int*[numcubes]; + for (int i = 0; i < numcubes; i++) + newpos[i] = new int[4]; + + i = 0; + int boolean = 1; + while (boolean && (i < numcubes)) + if ((cubes[i]->GetPos()[dir] + sign) == edge) + boolean = 0; + else { + for (int j = 0; j < 4; j++) + newpos[i][j] = cubes[i]->GetPos()[j] + ((j == dir) ? sign : 0); + + boolean = board->GoodSpotShort(newpos[i]); + + i++; + } + + if (boolean) { + for (i = 0; i < numcubes; i++) + cubes[i]->Translate(dir, sign); + +/* + cout << endl; + for (i = 0; i < numcubes; i++) + for (int j = 0; j < 4; j++) + cout << "boardpos["<GetPos()[j] << endl; +*/ + + float xx = ((dir == X) ? (float)(sign)*LEN[X] : 0.0); + float yy = ((dir == Y) ? (float)(sign)*LEN[Y] : 0.0); + float zz = ((dir == Z) ? (float)(sign)*LEN[Z] : 0.0); + float ww = ((dir == W) ? (float)(sign)*LEN[W] : 0.0); + center->Translate(xx, yy, zz, ww); + } + + for (i = 0; i < numcubes; i++) + delete newpos[i]; + delete newpos; + +#ifdef DEBUG_GENPIECE + cout << "End GenPiece::Translate(" << dir << "," << sign << ")" << endl; +#endif + + return boolean; +} + + +// Given: Nothing +// Task: Drop this piece as far as possible in the negative W direction +// Return: Nothing, but the piece has been dropped +void GenPiece::Drop() +{ +#ifdef DEBUG_GENPIECE + cout << "Begin GenPiece::Drop()" << endl; +#endif + + while (Translate(W, -1)); + +#ifdef DEBUG_GENPIECE + cout << "End GenPiece::Drop()" << endl; +#endif +} + + +// Given: Nothing +// Task: Let the board know that we're done with this piece, basically by +// sending this pieces information to the board, so it can become +// part of the board (resistance is futile. you will be assimilated) +// Return: Nothing, but the piece has been assimilated to the board +int GenPiece::DonePiece() +{ +#ifdef DEBUG_GENPIECE + cout << "Begin GenPiece::DonePiece()" << endl; +#endif + + return (board->DonePiece(cubes, numcubes)); + +#ifdef DEBUG_GENPIECE + cout << "End GenPiece::DonePiece()" << endl; +#endif +} + + +// Given: Three axes for the projection +// Task: Draw this piece in the given projection, plus draw its shadow on +// the floor, if w is in the projection +// Return: Nothing, but the piee has been drawn +void GenPiece::Drawit(int axes) +{ +#ifdef DEBUG_GENPIECE +// cout << "Begin GenPiece::Drawit()" << endl; +#endif + + for (int i = 0; i < numcubes; i++) + cubes[i]->Drawit(axes); + + if (axes != 7) + for (i = 0; i < numcubes; i++) + cubes[i]->Drawit2D(axes); + +#ifdef DEBUG_GENPIECE +// cout << "End GenPiece::Drawit()" << endl; +#endif +} + + + diff --git a/GenPiece.h b/GenPiece.h new file mode 100644 index 0000000..a612e57 --- /dev/null +++ b/GenPiece.h @@ -0,0 +1,46 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// GenPiece.h +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _GENPIECE_H_ +#define _GENPIECE_H_ + +#include "Board.h" +#include "Hyper.h" +#include "Shared.h" + +class GenPiece +{ +public: + GenPiece(int cubenum); + ~GenPiece(); + + int **CanRotate(int dir, int dude, int sign); + void Rotate(int dir, int dude, int sign); + + void Drop(); + int Translate(int dir, int sign); + int DonePiece(); + + void Drawit(int axes); + +protected: + Hyper **cubes; // an array of the cubes in the piece + FourD *center; // center for rotation + int centerstat; // status of center + // < 0 => not in center of a cube + // >= 0 => in the center of cube[centerstat] + + // what about center of a cube that's not in the piece?? + +private: + int numcubes; // number of cubes in piece (is four for typical piece) +}; + +#endif diff --git a/Hyper.C b/Hyper.C new file mode 100644 index 0000000..9898b23 --- /dev/null +++ b/Hyper.C @@ -0,0 +1,470 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Hyper.C +// Last modified: April 24, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include // for debugging only + +//#define DEBUG_HYPER + +#include "Hyper.h" + +extern Board *board; +extern float *LEN; +extern int *DIM; +extern float *botcorner; +extern int SHADEUNDER; + + +// Given: Nothing +// Task: Just the default constructor +// Return: Nothing +Hyper::Hyper() +{ + pts = new FourD*[16]; +} + +// Given: A low, high, and new board position +// Task: Construct a new hypercube whose real coordinates are based +// off of high and low, and whose board position is newpos +// Return: Nothing, but the hypercube has been constructed +Hyper::Hyper(float low, float high, int *newpos) +{ + pts = new FourD*[16]; + + float temp[4]; + + for (int ii = 0; ii < 16; ii++) { + for (int jj = 0; jj < 4; jj++) + temp[jj] = ((ii & (1<<(3-jj))) ? low : high); + pts[ii] = new FourD(temp); + } + + boardpos = new int[4]; + for (ii = 0; ii < 4; ii++) { + if (ii != W) + Assert(newpos[ii] < DIM[ii], "Piece doesn't fit on board"); + boardpos[ii] = newpos[ii]; + } +} + + +// Given: A list of lows for each coordinate, a list of highs for each +// coordinate, and a new board position +// Task: Construct a new hypercube whose real coordinates are based +// off of the highs and lows, and whose board position is newpos +// Return: Nothing, but the hypercube has been constructed +Hyper::Hyper(float *low, float *high, int *newpos) +{ + pts = new FourD*[16]; + + float temp[4]; + + for (int ii = 0; ii < 16; ii++) { + for (int jj = 0; jj < 4; jj++) + temp[jj] = ((ii & (1<<(3-jj))) ? low[jj] : high[jj]); + pts[ii] = new FourD(temp); + } + + boardpos = new int[4]; + for (ii = 0; ii < 4; ii++) { + if (ii != W) + Assert((newpos[ii] < DIM[ii]) && (newpos[ii] >= 0), + "Piece doesn't fit on board"); + boardpos[ii] = newpos[ii]; + } +} + + +// Given: Nothing +// Task: Delete the memory used by this hypercube +// Return: Nothing, but the memory has been cleared +Hyper::~Hyper() +{ + for (int i = 0; i < 16; i++) + delete pts[i]; + + delete pts; + delete boardpos; +} + + +// Given: A color +// Task: Make the given color this color for this cube +// Return: Nothing, but the color of the cube has been set +void Hyper::SetColor(int newcolor) +{ + color = newcolor; +} + + +// Given: Nothing +// Task: Dim the color of the cube, by halving each of the red, green +// and blue components +// Return: Nothing, but the color of the cube has been dimmed +void Hyper::DimColor() +{ + int temp = color; + int rr = (temp & 0x000000ff) / 2; + temp = temp >> 8; + int gg = (temp & 0x000000ff) / 2; + temp = temp >> 8; + int bb = (temp & 0x000000ff) / 2; + + color = 0xff000000 + (bb << 16) + (gg << 8) + rr; +} + + +// Given: Nothing +// Task: Nothing +// Return: The board position of this hypercube +int *Hyper::GetPos() +{ + return boardpos; +} + + +// This is for debugging only +void Hyper::Output() +{ +#ifdef DEBUG_HYPER + cout << "Begin Hyper Output" << endl; +#endif + + for (int i = 0; i < 16; i++) + pts[i]->Output(); + +#ifdef DEBUG_HYPER + cout << "End Hyper Output" << endl; +#endif +} + + +// Given: A direction, and a sign +// Task: Translate this hypercube one unit (in terms of board coordinate) in +// the direction and sign designated +// Return: Nothing, but the hypercube has been translated +void Hyper::Translate(int dir, int sign) +{ + float xx = ((dir == X) ? (float)(sign)*LEN[X] : 0.0); + float yy = ((dir == Y) ? (float)(sign)*LEN[Y] : 0.0); + float zz = ((dir == Z) ? (float)(sign)*LEN[Z] : 0.0); + float ww = ((dir == W) ? (float)(sign)*LEN[W] : 0.0); + + for (int i = 0; i < 16; i++) + pts[i]->Translate(xx, yy, zz, ww); + + boardpos[dir] += sign; +} + + +// Given: The three axes to draw, in a bitmask +// Task: Draw this hypercube in the three axes projection specified +// Return: Nothing, but the cube has been drawn +void Hyper::Drawit(int axes) +{ +#ifdef DEBUG_HYPER +// cout << "Begin Hyper::Drawit()" << endl; +#endif + + if ((boardpos[W] < DIM[W]) || (axes == 7)) { + // face 1, +x, +y + bgntmesh(); Plot(0, axes); Plot(1, axes); + Plot(2, axes); Plot(3, axes); endtmesh(); + + // face 2, +x, -y + bgntmesh(); Plot(4, axes); Plot(5, axes); + Plot(6, axes); Plot(7, axes); endtmesh(); + + // face 3, -x, +y + bgntmesh(); Plot(8, axes); Plot(9, axes); + Plot(10, axes); Plot(11, axes); endtmesh(); + + // face 4, -x, -y + bgntmesh(); Plot(12, axes); Plot(13, axes); + Plot(14, axes); Plot(15, axes); endtmesh(); + + // face 5, +x, +z + bgntmesh(); Plot(0, axes); Plot(1, axes); + Plot(4, axes); Plot(5, axes); endtmesh(); + + // face 6, +x, -z + bgntmesh(); Plot(2, axes); Plot(3, axes); + Plot(6, axes); Plot(7, axes); endtmesh(); + + // face 7, -x, +z + bgntmesh(); Plot(8, axes); Plot(9, axes); + Plot(12, axes); Plot(13, axes); endtmesh(); + + // face 8, -x, -z + bgntmesh(); Plot(10, axes); Plot(11, axes); + Plot(14, axes); Plot(15, axes); endtmesh(); + + // face 9, +x, +w + bgntmesh(); Plot(0, axes); Plot(2, axes); + Plot(4, axes); Plot(6, axes); endtmesh(); + + // face 10, +x, -w + bgntmesh(); Plot(1, axes); Plot(3, axes); + Plot(5, axes); Plot(7, axes); endtmesh(); + + // face 11, -x, +w + bgntmesh(); Plot(8, axes); Plot(10, axes); + Plot(12, axes); Plot(14, axes); endtmesh(); + + // face 12, -x, -w + bgntmesh(); Plot(9, axes); Plot(11, axes); + Plot(13, axes); Plot(15, axes); endtmesh(); + + // face 13, +y, +z + bgntmesh(); Plot(0, axes); Plot(1, axes); + Plot(8, axes); Plot(9, axes); endtmesh(); + + // face 14, +y, -z + bgntmesh(); Plot(2, axes); Plot(3, axes); + Plot(10, axes); Plot(11, axes); endtmesh(); + + // face 15, -y, +z + bgntmesh(); Plot(4, axes); Plot(5, axes); + Plot(12, axes); Plot(13, axes); endtmesh(); + + // face 16, -y, -z + bgntmesh(); Plot(6, axes); Plot(7, axes); + Plot(14, axes); Plot(15, axes); endtmesh(); + + // face 17, +y, +w + bgntmesh(); Plot(0, axes); Plot(2, axes); + Plot(8, axes); Plot(10, axes); endtmesh(); + + // face 18, +y, -w + bgntmesh(); Plot(1, axes); Plot(3, axes); + Plot(9, axes); Plot(11, axes); endtmesh(); + + // face 19, -y, +w + bgntmesh(); Plot(4, axes); Plot(6, axes); + Plot(12, axes); Plot(14, axes); endtmesh(); + + // face 20, -y, -w + bgntmesh(); Plot(5, axes); Plot(7, axes); + Plot(13, axes); Plot(15, axes); endtmesh(); + + // face 21, +z, +w + bgntmesh(); Plot(0, axes); Plot(4, axes); + Plot(8, axes); Plot(12, axes); endtmesh(); + + // face 22, +z, -w + bgntmesh(); Plot(1, axes); Plot(5, axes); + Plot(9, axes); Plot(13, axes); endtmesh(); + + // face 23, -z, +w + bgntmesh(); Plot(2, axes); Plot(6, axes); + Plot(10, axes); Plot(14, axes); endtmesh(); + + // face 24, -z, -w + bgntmesh(); Plot(3, axes); Plot(7, axes); + Plot(11, axes); Plot(15, axes); endtmesh(); + } +#ifdef DEBUG_HYPER +// cout << "End Hyper::Drawit()" << endl; +#endif +} + + +// Given: The index number of a point, and the three axes for projection +// Task: Plot pt[index] in the given projection, using my cheesy shading +// scheme for the point +// Return: Nothing, but the point has been plotted +void Hyper::Plot(int index, int axes) +{ + int temp = color; + + int rr = temp & 0x000000ff; + temp = temp >> 8; + int gg = temp & 0x000000ff; + temp = temp >> 8; + int bb = temp & 0x000000ff; + + int ans = index%2; + ans += ((index+1)%4) ? 0 : 1; + ans += ((index+1)%8) ? 0 : 1; + ans += ((index+1)%16) ? 0 : 1; + + rr -= ans*rr/5; + gg -= ans*gg/5; + bb -= ans*bb/5; + + cpack((0xff000000 + (bb << 16) + (gg << 8) + rr)); + + //int *axis, notused; + //axis = new int[3]; + int axis[3], notused; + + switch (axes) { + case 7: + axis[0] = X; + axis[1] = Y; + axis[2] = Z; + notused = W; + break; + + case 11: + axis[0] = W; + axis[1] = X; + axis[2] = Y; + notused = Z; + break; + + case 13: + axis[0] = Z; + axis[1] = W; + axis[2] = X; + notused = Y; + break; + + case 14: + axis[0] = Y; + axis[1] = Z; + axis[2] = W; + notused = X; + break; + } + + //float *dist = new float[3]; + float dist[3]; + + for (int i = 0; i < 3; i++) { + dist[i] = 1.0; + if ((*pts[0])[axis[i]] > (*pts[15])[axis[i]]) { + if ((*pts[index])[axis[i]] != (*pts[0])[axis[i]]) + dist[i] = -1.0; + } else + if ((*pts[index])[axis[i]] != (*pts[15])[axis[i]]) + dist[i] = -1.0; + dist[i] *= (float)(DIM[notused] - boardpos[notused]); + } + + pts[index]->Plot(axis, dist); + + //delete axis; + //delete dist; +} + + +// Given: The three axes for projection +// Task: Draw the shadow of this cube on the floor of the playing surface +// Return: Nothing, but the shadow has been drawn +void Hyper::Drawit2D(int axes) +{ + float wcoord = botcorner[W] - .005; + float wcoord2 = botcorner[W] - .02; + float mypoints[8][3]; + int i; + + switch (axes) { + case 11: // wxy + for (i = 0; i < 4; i++) + mypoints[i][0] = wcoord; + for (i = 4; i < 8; i++) + mypoints[i][0] = wcoord2; + + for (i = 0; i < 4; i++) + mypoints[2*i][1] = (*pts[0])[X]; + for (i = 0; i < 4; i++) + mypoints[2*i+1][1] = (*pts[15])[X]; + + //mypoints[0][1] = mypoints[2][1] = (*pts[0])[X]; + //mypoints[1][1] = mypoints[3][1] = (*pts[15])[X]; + mypoints[0][2] = mypoints[1][2] = mypoints[4][2] = mypoints[5][2] = + (*pts[0])[Y]; + mypoints[2][2] = mypoints[3][2] = mypoints[6][2] = mypoints[7][2] = + (*pts[15])[Y]; + break; + + case 13: // zwx + for (i = 0; i < 4; i++) + mypoints[i][1] = wcoord; + for (i = 4; i < 8; i++) + mypoints[i][1] = wcoord2; + + for (i = 0; i < 4; i++) + mypoints[2*i][0] = (*pts[0])[Z]; + for (i = 0; i < 4; i++) + mypoints[2*i+1][0] = (*pts[15])[Z]; + + //mypoints[0][0] = mypoints[2][0] = (*pts[0])[Z]; + //mypoints[1][0] = mypoints[3][0] = (*pts[15])[Z]; + mypoints[0][2] = mypoints[1][2] = mypoints[4][2] = mypoints[5][2] = + (*pts[0])[X]; + mypoints[2][2] = mypoints[3][2] = mypoints[6][2] = mypoints[7][2] = + (*pts[15])[X]; + break; + + case 14: // yzw + for (i = 0; i < 4; i++) + mypoints[i][2] = wcoord; + for (i = 4; i < 8; i++) + mypoints[i][2] = wcoord2; + + for (i = 0; i < 4; i++) + mypoints[2*i][0] = (*pts[0])[Y]; + for (i = 0; i < 4; i++) + mypoints[2*i+1][0] = (*pts[15])[Y]; + + //mypoints[0][0] = mypoints[2][0] = (*pts[0])[Y]; + //mypoints[1][0] = mypoints[3][0] = (*pts[15])[Y]; + mypoints[0][1] = mypoints[1][1] = mypoints[4][1] = mypoints[5][1] = + (*pts[0])[Z]; + mypoints[2][1] = mypoints[3][1] = mypoints[6][1] = mypoints[7][1] = + (*pts[15])[Z]; + break; + } + + //cpack(0xff000000); + // glEnable(GL_BLEND); + // blendfunction(BF_SA, BF_MSA); + // glColor4f(.2,.2,.2,.1); + glColor4f(1,1,1,.1); + bgntmesh(); + for (i = 0; i < 4; i++) + v3f(mypoints[i]); + endtmesh(); + + if (SHADEUNDER) { + bgntmesh(); + for (i = 4; i < 8; i++) + v3f(mypoints[i]); + endtmesh(); + } + + // glDisable(GL_BLEND); + +} + + +// Given: A new board position, a center for rotation, and the two +// axes and the sign for the rotation +// Task: Set the board position to the one which was passed in, and +// change the points of the cube by rotating them about the +// given center in the given axes in the given direction +// Return: Nothing, but the rotation has been performed +void Hyper::Rotate(int *newpos, FourD *center, int dir, int dude, int sign) +{ +#ifdef DEBUG_HYPER + cout << "Begin Hyper::Rotate(newpos, center, "<Rotate(center, dir, dude, sign); + + for (i = 0; i < 4; i++) + boardpos[i] = newpos[i]; + +#ifdef DEBUG_HYPER + cout << "End Hyper::Rotate(...)" << endl; +#endif +} diff --git a/Hyper.h b/Hyper.h new file mode 100644 index 0000000..5a7ebe3 --- /dev/null +++ b/Hyper.h @@ -0,0 +1,48 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Hyper.h +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _HYPER_H_ +#define _HYPER_H_ + +#include +#include "FourD.h" +#include "Asserts.h" +#include "Board.h" + +class Hyper +{ +public: + Hyper(); + Hyper(float low, float high, int *newpos); + Hyper(float *low, float *high, int *newpos); + ~Hyper(); + + void Translate(int dir, int sign); + + int *GetPos(); + + void Output(); + + void SetColor(int newcolor); + void DimColor(); + + void Drawit(int axes); + void Drawit2D(int axes); + void Plot(int index, int axes); + + void Rotate(int *newpos, FourD *center, int dir, int dude, int sign); + +private: + FourD **pts; // the 16 points that make up the hypercube + int *boardpos; // the position of the cube in term of + // the board's "coordinates" + int color; +}; +#endif diff --git a/LPiece.C b/LPiece.C new file mode 100644 index 0000000..9274d75 --- /dev/null +++ b/LPiece.C @@ -0,0 +1,84 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// LPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +LPiece::LPiece() : GenPiece(4) +{ + centerstat = 2; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = DIM[W]; + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == W) ? 2 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i] + ((i == W) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == X) ? 1 : 0); + +/* + for (i = 0; i < 4; i++) + for (int k = 0; k < 4; k++) + cout << "newpos["<SetColor(0xff0000); + } + + delete dudeman; + + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/Main.C b/Main.C new file mode 100644 index 0000000..cf5863e --- /dev/null +++ b/Main.C @@ -0,0 +1,869 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// MATH198 with Prof. Francis +// 4D Tetris +// +// Main.C +// Last modified: April 30, 2001 by Benjamin Bernard +// +// (C) 1996 Board of Trustees University of Illinois + +#include +// #include +#include +#include +#include +#include +#include +#include "Board.h" +#include "Shared.h" +#include "GenPiece.h" +#include "Pieces.h" +#include "Rotor.h" + +#define SOAK(K) while(getbutton(K)) + +int *DIM; +float *LEN; +Board *board; +float *botcorner; +int SHADEUNDER; +int gameon; +Rotor **quadrant; +int AUTOFALL; +int *dims; +int ONE_TURN_AT_A_TIME; +int fallsec; +int fallusec; +int numpieces; +int *mypieces; +int numremoved; +GenPiece *dude; + +void InitGlobals() +{ + gameon = 1; + quadrant = new Rotor*[4]; + for (int i = 0; i < 4; i++) + quadrant[i] = new Rotor(); + + AUTOFALL = 1; + dims = new int[4]; + dims[X] = dims[Y] = dims[Z] = 4; + dims[W] = 10; + ONE_TURN_AT_A_TIME = 1; + fallsec = 4; + fallusec = 0; + mypieces = NULL; + SHADEUNDER = 0; + numremoved =0; + + DIM = new int[4]; + for (i = 0; i < 4; i++) + DIM[i] = dims[i]; + LEN = new float[4]; + LEN[X] = LEN[Y] = LEN[Z] = LEN[W] = 4.5 / (float)(DIM[W]); + botcorner = new float[4]; + for (i = 0; i < 4; i++) + botcorner[i] = -2.0 + ((4.0 - LEN[i] * DIM[i]) / 2); + board = new Board(); +} + +GenPiece *NewPiece(int numpieces, int *mypieces) +{ + int piecenum = mypieces[(random() % numpieces)]; + //cout << piecenum << endl; + + GenPiece *ans; + switch (piecenum) { + case 1: + ans = new CubePiece(); + break; + + case 2: + ans = new LPiece(); + break; + + case 3: + ans = new SPiece(); + break; + + case 4: + ans = new StraightPiece(); + break; + + case 5: + ans = new TPiece(); + break; + + case 6: + ans = new CornerPiece(); + break; + + case 7: + ans = new TwistyPiece(); + break; + + case 8: + ans = new ZPiece(); + break; + + case 9: + ans = new ThreeLinePiece(); + break; + + case 10: + ans = new TriPiece(); + break; + + case 11: + ans = new TwoPiece(); + break; + + case 12: + ans = new SimplePiece(); + break; + } + + return ans; +} +void EndGame(int endState) +{ + if (gameon == 0) + cout << "Game Over, Man!" << endl; + else + cout << "Thanks for playing" << endl; + + + //delete DIM; //program crashes when this line is run, instead of ending + + delete LEN; + delete board; + delete botcorner; + + + for(int i=0; i<4; i++) + { + delete quadrant[i]; + } + + delete quadrant; + + delete dims; + delete mypieces; + + delete dude; + + exit(endState); +} + + +void Timer(int callValue) +{//Timer called if fallsec in seconds and fallusec in microseconds has passed + if (AUTOFALL && (gameon == 1)) { + if (!(dude->Translate(W, -1))) { //if a new piece is necessary + gameon = dude->DonePiece(); + delete dude; + dude = NewPiece(numpieces, mypieces); + if(gameon !=1) + { + EndGame(0); + } + } + //reset the callback + glutTimerFunc(((fallsec*1000) + (fallusec/1000)), Timer, 1); + } +} + + + +void CleanUpGlobals() +{ + delete DIM; + delete LEN; + delete board; + delete botcorner; +} + +int MyQuad(int getx, int gety) { + int sx, sy; + + sx = glutGet(GLUT_WINDOW_WIDTH); + sy = glutGet(GLUT_WINDOW_HEIGHT); + + + if (getx <= (int)(sx / 2)) + { + if(gety <= (int)(sy /2)) + return 0; + else + return 2; + } + else + { + if(gety <= (sy / 2)) + return 1; + else + return 3; + } +} + +int StrToInt(char *changeme) { + int ans = (int)(changeme[0]) - 48; + for (int i = 1; changeme[i] != '\0'; i++) + ans = 10*ans + (int)(changeme[i]) - 48; + return ans; +} + + +void Keyboard(unsigned char key, int x, int y) +{ + if(gameon) + { + if(key == 'p') + { + if(AUTOFALL) + AUTOFALL=0; + else + { + AUTOFALL=1; + if(gameon) + glutTimerFunc(((fallsec*1000) + (fallusec/1000)), Timer, 1); + + } + + } + else if(glutGetModifiers() == GLUT_ACTIVE_ALT) + { //test for alt true, so its a rotation, find out the axies + + if(key == ('6' & '8')) + { + dude->Rotate(X, Y, 1); + } + else if(key == ('6' & '2')) + { + dude->Rotate(X, Y, -1); + } + else if(key == ('6' & '9')) + { + dude->Rotate(X, Z, 1); + } + else if(key == ('6' & '1')) + { + dude->Rotate(X, Z, -1); + } + else if(key == ('6' & '7')) + { + dude->Rotate(X, W, 1); + } + else if(key == ('6' & '3')) + { + dude->Rotate(X, W, -1); + } + else if(key == ('4' & '8')) + { + dude->Rotate(X, Y, -1); + } + else if(key == ('4' & '2')) + { + dude->Rotate(X, Y, 1); + } + else if(key == ('4' & '9')) + { + dude->Rotate(X, Z, -1); + } + else if(key == ('4' & '1')) + { + dude->Rotate(X, Z, 1); + } + else if(key == ('4' & '7')) + { + dude->Rotate(X, W, -1); + } + else if(key == ('4' & '3')) + { + dude->Rotate(X, W, 1); + } + else if(key == ('8' & '9')) + { + dude->Rotate(Y, Z, 1); + } + else if(key == ('8' & '1')) + { + dude->Rotate(Y, Z, -1); + } + else if(key == ('8' & '7')) + { + dude->Rotate(Y, W, 1); + } + else if(key == ('8' & '3')) + { + dude->Rotate(Y, W, -1); + } + else if(key == ('2' & '9')) + { + dude->Rotate(Y, Z, -1); + } + else if(key == ('2' & '1')) + { + dude->Rotate(Y, Z, 1); + } + else if(key == ('2' & '7')) + { + dude->Rotate(Y, W, -1); + } + else if(key == ('2' & '3')) + { + dude->Rotate(Y, W, 1); + } + else if(key == ('9' & '7')) + { + dude->Rotate(Z, W, 1); + } + else if(key == ('9' & '3')) + { + dude->Rotate(Z, W, -1); + } + else if(key == ('1' & '7')) + { + dude->Rotate(Z, W, -1); + } + else if(key == ('1' & '3')) + { + dude->Rotate(Z, W, 1); + } + } //test for alt false + else + { // key is not an alt-modified key, + // check for translation, drop or escape + switch(key) + {//if number, translate along that axis + case '6': {dude->Translate(X, 1); break;} + case '4': {dude->Translate(X, -1); break;} + case '8': {dude->Translate(Y, 1); break;} + case '2': {dude->Translate(Y, -1); break;} + case '9': {dude->Translate(Z, 1); break;} + case '1': {dude->Translate(Z, -1); break;} + case '7': {dude->Translate(W, 1); break;} + case '3': {dude->Translate(W, -1); break;} + case ' ': { //space pressed, so drop the piece + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = NewPiece(numpieces, mypieces); + if(gameon != 1) + { + EndGame(0); + } + break; + } + case 27: { + EndGame(0); + break; + } + } + + } + } + glutPostRedisplay(); +} + +void Mouse(int button, int state, int x, int y) +{ + for(int i=0; i<4; i++) + { + quadrant[i]->CurrentMousePosition(x,y); + } + + if(state == GLUT_UP) + { + if(button == GLUT_LEFT_BUTTON) + { + for(int i=0; i<4; i++) + { + quadrant[i]->ShiftUp(); + quadrant[i]->MouseLeftUp(); + } + } + else if(button == GLUT_RIGHT_BUTTON) + { + for(int i=0; i<4; i++) + { + quadrant[i]->ShiftUp(); + quadrant[i]->MouseRightUp(); + } + } + } + else if(glutGetModifiers() == GLUT_ACTIVE_CTRL) + { + if(button == GLUT_LEFT_BUTTON) + {//if Control-Left click, only rotate the quadrant clicked + if (ONE_TURN_AT_A_TIME) + for (int i = 0; i < 4; i++) + quadrant[i]->Deactivate(); + + quadrant[MyQuad(x, y)]->Activate(); + } + else if(button == GLUT_RIGHT_BUTTON) + {//if Control-Right click, stop rotating all quadrants + for (int i = 0; i < 4; i++) + quadrant[i]->Deactivate(); + } + else if(button == GLUT_MIDDLE_BUTTON) + { + for( int i=0; i<4; i++) + { + quadrant[i]->Activate(); + } + } + } + else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT && state == GLUT_DOWN) + { + if(button == GLUT_LEFT_BUTTON) + { + quadrant[MyQuad(x,y)]->MouseLeftDown(); + quadrant[MyQuad(x,y)]->ShiftDown(); + } + else if(button == GLUT_RIGHT_BUTTON) + { + quadrant[MyQuad(x,y)]->MouseRightDown(); + quadrant[MyQuad(x,y)]->ShiftDown(); + } + } + else if(button == GLUT_LEFT_BUTTON) + { + quadrant[MyQuad(x,y)]->MouseLeftDown(); + } + else if(button == GLUT_RIGHT_BUTTON) + { + quadrant[MyQuad(x,y)]->MouseRightDown(); + } + else if(button == GLUT_MIDDLE_BUTTON) + {//"pause" or unpause the game, i.e. no more autofall + gameon = -gameon; + if(gameon && AUTOFALL) + glutTimerFunc(((fallsec*1000) + (fallusec/1000)), Timer, 1); + + } + + if(glutGetModifiers() == GLUT_ACTIVE_SHIFT && state == GLUT_DOWN) + { + if(button == GLUT_LEFT_BUTTON) + { + quadrant[MyQuad(x,y)]->MouseLeftDown(); + quadrant[MyQuad(x,y)]->ShiftDown(); + } + else if(button == GLUT_RIGHT_BUTTON) + { + quadrant[MyQuad(x,y)]->MouseRightDown(); + quadrant[MyQuad(x,y)]->ShiftDown(); + } + } + glutPostRedisplay(); +} + +void SpecialKeyboard(int key, int x, int y) +{ + if(key == GLUT_KEY_F1) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new CubePiece(); + } + else if(key == GLUT_KEY_F2) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new LPiece(); + } + else if(key == GLUT_KEY_F3) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new SPiece(); + } + else if(key == GLUT_KEY_F4) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new StraightPiece(); + } + else if(key == GLUT_KEY_F5) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TPiece(); + } + else if(key == GLUT_KEY_F6) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new CornerPiece(); + } + else if(key == GLUT_KEY_F7) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TwistyPiece(); + } + else if(key == GLUT_KEY_F8) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new ZPiece(); + } + else if(key == GLUT_KEY_F9) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new ThreeLinePiece(); + } + else if(key == GLUT_KEY_F10) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TriPiece(); + } + else if(key == GLUT_KEY_F11) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TwoPiece(); + } + else if(key == GLUT_KEY_F12) + { + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new SimplePiece(); + } + else if(glutGetModifiers() == GLUT_ACTIVE_ALT) + { //test for alt true, so its a rotation, find out the axies, w/o numlock + + if(key == (GLUT_KEY_RIGHT & GLUT_KEY_RIGHT)) + { + dude->Rotate(X, Y, 1); + } + else if(key == (GLUT_KEY_RIGHT & GLUT_KEY_DOWN)) + { + dude->Rotate(X, Y, -1); + } + else if(key == (GLUT_KEY_RIGHT & GLUT_KEY_PAGE_UP)) + { + dude->Rotate(X, Z, 1); + } + else if(key == (GLUT_KEY_RIGHT & GLUT_KEY_END)) + { + dude->Rotate(X, Z, -1); + } + else if(key == (GLUT_KEY_RIGHT & GLUT_KEY_HOME)) + { + dude->Rotate(X, W, 1); + } + else if(key == (GLUT_KEY_RIGHT & GLUT_KEY_PAGE_DOWN)) + { + dude->Rotate(X, W, -1); + } + else if(key == (GLUT_KEY_LEFT & GLUT_KEY_UP)) + { + dude->Rotate(X, Y, -1); + } + else if(key == (GLUT_KEY_LEFT & GLUT_KEY_DOWN)) + { + dude->Rotate(X, Y, 1); + } + else if(key == (GLUT_KEY_LEFT & GLUT_KEY_PAGE_UP)) + { + dude->Rotate(X, Z, -1); + } + else if(key == (GLUT_KEY_LEFT & GLUT_KEY_END)) + { + dude->Rotate(X, Z, 1); + } + else if(key == (GLUT_KEY_LEFT & GLUT_KEY_HOME)) + { + dude->Rotate(X, W, -1); + } + else if(key == (GLUT_KEY_LEFT & GLUT_KEY_PAGE_DOWN)) + { + dude->Rotate(X, W, 1); + } + else if(key == (GLUT_KEY_UP & GLUT_KEY_PAGE_UP)) + { + dude->Rotate(Y, Z, 1); + } + else if(key == (GLUT_KEY_UP & GLUT_KEY_END)) + { + dude->Rotate(Y, Z, -1); + } + else if(key == (GLUT_KEY_UP & GLUT_KEY_HOME)) + { + dude->Rotate(Y, W, 1); + } + else if(key == (GLUT_KEY_UP & GLUT_KEY_PAGE_DOWN)) + { + dude->Rotate(Y, W, -1); + } + else if(key == (GLUT_KEY_DOWN & GLUT_KEY_PAGE_UP)) + { + dude->Rotate(Y, Z, -1); + } + else if(key == (GLUT_KEY_DOWN & GLUT_KEY_END)) + { + dude->Rotate(Y, Z, 1); + } + else if(key == (GLUT_KEY_DOWN & GLUT_KEY_HOME)) + { + dude->Rotate(Y, W, -1); + } + else if(key == (GLUT_KEY_DOWN & GLUT_KEY_PAGE_DOWN)) + { + dude->Rotate(Y, W, 1); + } + else if(key == (GLUT_KEY_PAGE_UP & GLUT_KEY_HOME)) + { + dude->Rotate(Z, W, 1); + } + else if(key == (GLUT_KEY_PAGE_UP & GLUT_KEY_PAGE_DOWN)) + { + dude->Rotate(Z, W, -1); + } + else if(key == (GLUT_KEY_END & GLUT_KEY_HOME)) + { + dude->Rotate(Z, W, -1); + } + else if(key == (GLUT_KEY_END & GLUT_KEY_PAGE_DOWN)) + { + dude->Rotate(Z, W, 1); + } + } //test for alt false + else + { // key is not an alt-modified key, + // check for translation, drop or escape + switch(key) + {//if number, translate along that axis + case GLUT_KEY_RIGHT: {dude->Translate(X, 1); break;} + case GLUT_KEY_LEFT: {dude->Translate(X, -1); break;} + case GLUT_KEY_UP: {dude->Translate(Y, 1); break;} + case GLUT_KEY_DOWN: {dude->Translate(Y, -1); break;} + case GLUT_KEY_PAGE_UP: {dude->Translate(Z, 1); break;} + case GLUT_KEY_END: {dude->Translate(Z, -1); break;} + case GLUT_KEY_HOME: {dude->Translate(W, 1); break;} + case GLUT_KEY_PAGE_DOWN: {dude->Translate(W, -1); break;} + } + } + + if(gameon ==0) + EndGame(0); + + + glutPostRedisplay(); +} + +void Idle() +{ + if (gameon == 1) { + numremoved += board->CheckBoard(); + + if (AUTOFALL && (numremoved >= 2)) { + //this code will increase the speed at which pieces fall + + int rem = fallsec % 8; + rem *= 7; + rem %= 8; + rem = (int)((float)(rem)*5000000.0/8.0); + fallsec = (int)((float)(fallsec)*7.0/8.0); + fallusec = (int)((float)(fallusec)*7.0/8.0) + rem; + + numremoved = 0; + } + } + else if(gameon ==0) + { + EndGame(0); + } + glutPostRedisplay(); +} + + + + +void Display() +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + ortho(-5.01, 5.01, -5.01, 5.01, -5.01, 5.01); + + cpack(0); + + //clear(); zclear(); replaced by the line below + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // put the x, y, z axes in the upper right hand corner (quad 1) + pushmatrix(); + translate(2.5, 2.5, 0.0); + quadrant[1]->Rotate(); + dude->Drawit(7); + board->Drawit(7); + popmatrix(); + + // put the w, x, y axes in the upper left hand corner (quadrant 0) + pushmatrix(); + translate(-2.5, 2.5, 0.0); + quadrant[0]->Rotate(); + dude->Drawit(11); + board->Drawit(11); + popmatrix(); + + // put the z, w, x axes in the lower left corner (quadrant 2) + pushmatrix(); + translate(-2.5, -2.5, 0.0); + quadrant[2]->Rotate(); + dude->Drawit(13); + board->Drawit(13); + popmatrix(); + + // put the y, z, w axes in the lower right corner (quadrant 3) + pushmatrix(); + translate(2.5, -2.5, 0.0); + quadrant[3]->Rotate(); + dude->Drawit(14); + board->Drawit(14); + popmatrix(); + + swapbuffers(); +} + +void MouseMotion(int x, int y) +{ + for(int i=0; i<4; i++) + { + quadrant[i]->CurrentMousePosition(x,y); + } +} + +void Reshape(int width, int height) +{ + glutPostRedisplay(); + glViewport(0,0,width,height); +} + + +void main(int argc, char **argv) +{ + cout << "\n\nHyperTetris\n by\nGreg Kaiser\n" << endl; + cout << "(C) 1996 Board of Trustees University of Illinois\n" << endl; + + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB); + + glutInitWindowPosition(300,0); + glutInitWindowSize(985,985); + //keepaspect(1,1); Not sure what this translates to + + + glutCreateWindow("4-D Tetris"); + // make sure you open the window BEFORE initializing + // any data structures. Otherwise, you'll dump core + + //winconstraints(); // should allow window to be resized not necessary? + + InitGlobals(); + + int i = 1; + + while (i < argc) { + if (!(strcmp(argv[i], "-NOFALL"))) + AUTOFALL = 0; + + else if (!(strcmp(argv[i], "-DIM"))) + for (int j = 0; j < 4; j++) { + i++; + dims[j] = StrToInt(argv[i]); + } + + else if (!(strcmp(argv[i], "-MULTITURN"))) + ONE_TURN_AT_A_TIME = 0; + + else if (!(strcmp(argv[i], "-FALLTIME"))) { + i++; + fallsec = StrToInt(argv[i++]); + fallusec = StrToInt(argv[i]); + + } else if (!(strcmp(argv[i], "-MYPIECES"))) { + i++; + numpieces = StrToInt(argv[i]); + mypieces = new int[numpieces]; + for (int j = 0; j < numpieces; j++) { + i++; + mypieces[j] = StrToInt(argv[i]); + } + + } else if (!(strcmp(argv[i], "-SHADEUNDER"))) + SHADEUNDER = 1; + + else { + cout << endl; + cout << "The command line argument " << argv[i] << " isn't recognized."; + cout << endl << "Please see the README file for acceptable arguments."; + cout << endl << "Thank you. Have a nice day!" << endl; + } + + i++; + } + + if (mypieces == NULL) { + numpieces = 11; + mypieces = new int[numpieces]; + for (int i = 0; i < numpieces; i++) { + mypieces[i] = i + ((i < 7) ? 1 : 2); + } + } + + dude = NewPiece(numpieces, mypieces); + //GenPiece *dude = new CubePiece(); + //GenPiece *dude = new LPiece(); + //GenPiece *dude = new SPiece(); + //GenPiece *dude = new StraightPiece(); + //GenPiece *dude = new TPiece(); + //GenPiece *dude = new CornerPiece(); + //GenPiece *dude = new TwistyPiece(); + //GenPiece *dude = new ZPiece(); + //GenPiece *dude = new ThreeLinePiece(); + //GenPiece *dude = new TriPiece(); + //GenPiece *dude = new TwoPiece(); + //GenPiece *dude = new SimplePiece(); + + if(AUTOFALL) + { + glutTimerFunc(((fallsec*1000) + (fallusec/1000)), Timer, 1); + } + + glutDisplayFunc(Display); + glutKeyboardFunc(Keyboard); + glutSpecialFunc(SpecialKeyboard); + glutMouseFunc(Mouse); + glutPassiveMotionFunc(MouseMotion); + glutMotionFunc(MouseMotion); + glutIdleFunc(Idle); + glutReshapeFunc(Reshape); + glutMainLoop(); +} + + + + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b0e2666 --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +OBJS = Main.o\ + Shared.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +#CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +#CC doesn't understand -woff +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +tetris: $(OBJS) + CC -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) +.C.o: + CC $(CFLAGS) -c $< + + + diff --git a/Pieces.h b/Pieces.h new file mode 100644 index 0000000..f2c265c --- /dev/null +++ b/Pieces.h @@ -0,0 +1,76 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Pieces.h +// Last modified: April 22, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _PIECES_H_ +#define _PIECES_H_ + +#include "GenPiece.h" + +class CubePiece : public GenPiece { +public: + CubePiece(); +}; + +class LPiece : public GenPiece { +public: + LPiece(); +}; + +class SPiece : public GenPiece { +public: + SPiece(); +}; + +class StraightPiece : public GenPiece { +public: + StraightPiece(); +}; + +class TPiece : public GenPiece { +public: + TPiece(); +}; + +class CornerPiece : public GenPiece { +public: + CornerPiece(); +}; + +class TwistyPiece : public GenPiece { +public: + TwistyPiece(); +}; + +class ZPiece : public GenPiece { +public: + ZPiece(); +}; + +class ThreeLinePiece : public GenPiece { +public: + ThreeLinePiece(); +}; + +class TriPiece : public GenPiece { +public: + TriPiece(); +}; + +class TwoPiece : public GenPiece { +public: + TwoPiece(); +}; + +class SimplePiece : public GenPiece { +public: + SimplePiece(); +}; + +#endif diff --git a/README b/README new file mode 100644 index 0000000..1bb05bb --- /dev/null +++ b/README @@ -0,0 +1,215 @@ +INTRO: +This directory contains the pre-release (don't you feel special) version +of four-dimensional Tetris. In this directory is all of the source code, +the makefile, this README file, and the game itself, HyperTetris. + +THE GAME: +The game play is the Tetris concept, with simply a couple more +dimensions added. The object is to fill as many cubes (as opposed to lines) +with pieces as possible. + + +SUGGESTIONS FOR BEGINNERS: +For those of us not raised on four-dimensional board games as children, +this game is quite difficult. Some suggestions I have for beginners: +1) Read this README file. I realize that I'm no rhetoric whiz, but this + file does contain a lot of useful information about the game. +2) The first several time you run the program, don't even try to play + the game. Use the -NOFALL option (explained later in this file) and + experiment with things. Figure out how the pieces look, how the + rotations work, etc. +2) Use the -NOFALL option the first several times you play the game. +3) Limit the pieces the first several times you play. Play with only the + one, two, and three cubed pieces before taking them all on. +4) Have patience. I wrote this game and still can't fill a single cube + without some sort of command line help. This isn't the kind of game + that anyone can master over-night. +5) Use the 'p' key to pause the game, to give yourself some time to think, + equivalent to the -NOFALL option + +CONTROL OF THE PIECES: +The control of the pieces is based off of the keypad, where the keypad +looks like this: +7 8 9 +4 5 6 +1 2 3 + +For the purposes of my game, the keypad can be seen as this: + _ ^ _ +|\ /|\ /| + \ | / + \ | / +x \|/ \ +-----*----> (I think I'm better with gl than ASCII) + /|\ / + / | \ + / | \ +z/ | \w +/ y| \ + + +And thus, 4 is the negative x direction, 7 is the positive w, etc. + +To move a piece, simply press the button for the direction you want to +move in. It should be noted if you hold down a button for a long time, +you will not move anywhere until you release it, and it will only move +your piece one spot. + +To rotate a piece. Basically, each rotation takes place in a plane. +To rotate a piece in the x-y plane, first press ALT, then 8 on the +key pad and 6 on the key pad. The best way to visualize this rotation +is to simply play the game and experiment. If you wish to do a negative +rotation in the x-y plane, make one of your x-y thingies negative, i.e. +press ALT-8-4 or ALT-2-6. + +The spacebar will drop a piece. + + +YOUR VIEW OF THE GAME: +On the screen are four three-dimensional projections of the 4D space +which the game is taking place in. In the upper right corner is the +x, y, z projection, upper left is the w, x, y projection, lower left +is the z, w, x projection, and lower right is the y, z, w projection. +You will notice that when the game first begins, you only see a piece +in the x, y, z projection. This is because the pieces start off of +the board in the w direction. If you use the default setting, then +the piece will slowly fall into the other projections. If you used +the -NOFALL option, you need to move the piece in the negative w direction +yourself (press 3 on the keypad). +There are 4 different colored walls used in the projections. Each +represent the negative barrier of a certain direction. The white +wall is the "bottom" and is the furthest something can move in -w. +The red, green, and blue walls correspond to -x, -y, and -z respectively. + + +CONTROL OF YOUR VIEW: +When you begin the game, you'll notice that all of the projections rotate +about the mouse movement. If you click the left or right mouse buttons, +(which I will refer to as LEFT CLICK and RIGHT CLICK) you will see the +projections rotate about one of their axes. If you hold down the shift +key and do this (SHIFT-LEFT CLICK or SHIFT-RIGHT CLICK), then they will +rotate much faster. If you hold down the control key and click the +left mouse button, (CTRL-LEFT CLICK) they will quit rotating. Then, if +you CTRL-RIGHT CLICK while the mouse cursor is over a certain projection, +then that projection will begin to rotate according to the mouse movements. +If you CTRL-RIGHT CLICK over a different projection, the previous projection +will freeze and this new projection will start rotating. CTRL-LEFT CLICK +will freeze any rotating projection without starting the rotation of another. +I realize that my explanation is sort of difficult to understand, but +I think that if you experiment with it, you'll see what's going on. +To reactive the rotation of all four quadrants, press CTRL-MIDDLE CLICK + +PAUSING THE GAME: +Clicking on the middle mouse button will pause the game. When the game +is paused, you can not move or rotate any piece, but you can use the +mouse to control your view and rotate the projections. Clicking the +middle mouse button again will unpause the game. + +Just added is another way to pause the game that will allow you to +manipulate the pieces while the game, is paused. Use the 'p' key to +activate this feature + + +THE PIECES: +There are presently 12 pieces in the this game. I will list them by +their piece number and piece name, and then explain them: 1-CubePiece, +2-LPiece, 3-SPiece, 4-StraightPiece, 5-TPiece, 6-CornerPiece, +7-TwistyPiece, 8-ZPiece, 9-ThreeLinePiece, 10-TriPiece, 11-TwoPiece, +12-SimplePiece. +Now, instead of attempting to describe how each of these pieces look, +I've done better. In the game, pressing one of the F# keys will drop +the present piece and give you piece number #. In other words, if you +want to look at the TPiece, simply press F5, and your present piece +will drop and you'll get a TPiece. +Suggestion: Before you start playing, start a game in -NOFALL mode and +go through each of the pieces, to get an idea of what they look like +and how they move. + + +COMMAND LINE ARGUMENTS: +-NOFALL By default the pieces fall through w automatically. It is very + useful, however, when you are first getting used to the game, + first getting used to new pieces, and such to not have these + pieces fall automatically. Thus, with the -NOFALL option, you + can simply bring the piece down through w (3 on the keypad) at + your own leisure. + +-DIM x y z w + Right now, the dimensions, in terms of hypercube side lengths, of + the playing board, is 4x4x4x10, that is, you can fit 4 hypercubes + next to each other in the x, y, and z directions, and 10 hypercubes + on top of each other in the w direction. By calling something like + HyperTetris -DIM 2 4 3 8, you will create a 2x4x3x8 playing board + for the dimensions x, y, z, and w respectively. NOTE: The game + expects that the w dimension is larger than any of the other + three dimensions, and thus a call like HyperTetris -DIM 5 5 5 4 + will probably crash the program. + +-MULTITURN + As explained in "control of your view", once you click the right + mouse button on a different projection, the projection you were + rotating will stop. If you don't want this, and would like to + rotate multiple projections at once, use this flag. When you + click the right mouse button on a projection, it will simply be + rotated along with any other projections currently rotating. + Pressing the left mouse button will freeze all projections. + +-FALLTIME sec usec + Right now, the game waits 4 seconds before dropping a piece + another step in the W direction. If you wish to change this + to make it longer or shorter, simply enter _integer_ values + for sec, which is the number of second, and usec, which is the + number of microseconds (there are 1,000,000 microseconds in a + second). Thus, if you want a fall time of 2.5 seconds, use + HyperTetris -FALLTIME 2 500000. + +-MYPIECES n piece(1) piece(2) ... piece(n) + As explained in "the pieces", each piece has a number. By default, + all pieces except piece 8 are used throughout the random cycle + of the game. If you wish to limit this, or for some sadistic + reason include piece 8, then use the -MYPIECES flag. The first + number following the flag should be the number of pieces you want + to use. Then, you should give the piece number for each of the + pieces that you wish to have. Thus, if you want to only use the + LPiece and the SPiece, call HyperTetris -MYPIECES 2 2 3. + +-SHADEUNDER + In each of the projections that have the w axis, the shadow of + the falling piece is shown on the floor. However, this shadow + is not mirrored on the underside of the floor. If you use this + flag, the shadow will be mirrored to the underside of the floor, + which one may find helpful for seeing where a piece will fall, + but can create confusion as to which side of the floor you are + looking at. Hence, the option for you. + +It should be noted that the command line parser is pretty dumb. If you +mess up a command line call, it will probably crash the program. It is +not, however, sensitive to order, so HyperTetris -NOFALL -DIM 3 4 5 10 is +the same as HyperTetris -DIM 3 4 5 10 -NOFALL, but the call HyperTetris +-DIM 3 4 -NOFALL 5 10 will probably crash the program. +Just to give you a couple of sample command line combinations, here's some +I use pretty often: +HyperTetris -DIM 2 2 2 10 -FALLTIME 1 0 -MYPIECES 1 1 +HyperTetris -MYPIECES 4 9 10 11 12 + + +FREQUENTLY ASKED QUESTIONS: +Q: Why is it that sometimes a piece will go through another piece? Is + this a bug? +A: No, since you are only looking at a three-dimensional subspace, it is + possible that the pieces share the same three coordinates that are + being displayed in that projection, but differ in their fourth + coordinate, which can be observed by looking at a different project. + The rule used when two pieces collide is that the piece which is more + positive in the fourth coordinate gets drawn over the other. + + +QUESTIONS, COMMENTS, BUGS, SUGGESTIONS, DONATIONS OF LARGE SUMS OF MONEY? +Please feel free to email me (Greg Kaiser) at gjkaiser@uiuc.edu. I would +appreciate any and all feedback, questions, bug reports, and whatever. + + + + + + diff --git a/README-VERSION b/README-VERSION new file mode 100644 index 0000000..77d164a --- /dev/null +++ b/README-VERSION @@ -0,0 +1,80 @@ +Change Notes: + +Added new controls in SpecialKeyboard in Main.C so that program will respond to keypad with or without numlock on, which was a requirement before. + +Added key 'p' to pause the game. This is sort of a cheat, but it will turn autofall OFF (or back ON if its already off). Also, added CTRL-Middle Mouse button as the "reset" so that all the quadrants will begin rotating again. + + +README-VERSION history: +This version is a intermediate version in the attempt to port tetris to OpenGL, +currently all of the "easy" conversions are implemented in Shared.h, +but there are still IrisGL windowing commands in Rotor.C and main.C, +the problem functions are documented in unknown.txt. + +About to start extracting segments from the main loop and moving the commands into the GLUT loop, in particular things like "holding" the ALT-8-2 can be redone with the keyboard callback in GLUT and key == '8' & '2' (after checking, glutGetModifiers() == GLUT_ACTIVE_ALT), i.e. with bit-wise ANDs. + +--------------------------- + +Extracted all event coding into glut approved format. Changed over window code to glut windowing code. Added CTRL-P as a command to pause the game that will let you rotate and translate pieces still, unlike a middle mouse button click, which will just freeze everything. + +New files such as keyboard.C and display.C are all intermediate files in the extraction of event code to event methods for GLUT. most things in unknown have become known. + +In order to handle the rotors (in the quad array) correctly in an event-driven style, had to re-write non-rotation code in the Rotor class, also had to add around 6 helper methods. + +Mouse in main was updated, as well, in order to implement much of the functionality found in the Rotor class. + +------------------------- + +Discovered that mouse coordinates are passed in as window-relative coordinates, this necessitated further changes in the Rotor class, as well as the MyQuad function in Main.C + +All IrisGL code should now be changed, though there are still MakeFile issues as well as the fact that I'm certain it doesn't compile due to silly coding errors on my part. + +------------------------- + +Got makefile working with the objects + +Had to rename the Rotor*[] quad to quadrant, as the quad identifer was already defined somewhere else + +imported cpack function from class01/ig2ogl/skel2.c or something like that +provded blendfucntion with two of its defines converted to GL... +two webpages of use to do that: + +http://www.austin.ibm.com/idd500/usr/share/man/info/en_US/a_doc_lib/libs/gl32tref/blendfunction.htm +and +http://www.cevis.uni-bremen.de/~uwe/opengl/glBlendFunc.html + +working now with matrix manipulations in Rotor.C +still not compiling + +---------- +More makefile problems. The .C files all compile to .o files, but then they will not link together. new attempts are represented by htetris.mf, htetris.test, cpp.mf +It appears as if the linker is not using the correct libraries. + +resolved final random compilation problems, including moving the function code from Shared.h to Shared.C allowing #ifndef to work correctly + +--------- +Got a working makefile. On re-compile, esc key should work to exit the program. + +Appears some display code is not being processed correctly, because the image disappears as soon as the program is run. File to run is tetris. + +--------- + + +Really have a working makefile now... Just type make, and it should make an executeably called "tetris" + +fixed rotation problem, was resetting aff matrix to identity everytime in Rotor.C! final conversion for code before testing interface is the transparacy issues with the board. Should already be BLENDING with glBlendFunc, but current conversion for cpack (in Shared.C) does not specify alpha values, I am working on a new conversion) + +Fixed some memroy leaks in Rotor.C and Main.C... should delete more dynamically allocated stuff now, though there are probably more memory leaks in the program. + + +-Benjamin Bernard + + + + + + + + + + diff --git a/Refrences.txt b/Refrences.txt new file mode 100644 index 0000000..1290bf8 --- /dev/null +++ b/Refrences.txt @@ -0,0 +1,22 @@ +Refrences - + +Greg Kaiser's 4D Tetris. + +The OpenGL Utility Toolkit (GLUT) Programming Interface API Version 3 + - Author: Mark J. Kilgard, Silicon Graphics, Inc. + - Resource: http://reality.sgi.com/mjk_asd/spec3/spec3.html + +The OpenGL Graphics System: A Specification (Version 1.1) + - Authors: Mark Segal, Kurt Akeley + - Editor: Chris Frazier + - Resource: http://trant.sgi.com/opengl/docs/Specs/glspec1.1/glspec.html + +OpenGL doc in HTML + - From: OpenGL Reference Manual -- The Official Reference Document for OpenGL, Release 1 + - Taken from the refrence pages + - Author: Uwe Behrens + - Resource: http://www.cevis.uni-bremen.de/~uwe/opengl/ + +OpenGL Functions and Their IRIS GL Equivalents + - Released by: Microsoft in MSDN Online Library + - Resource: http://msdn.microsoft.com/library/psdk/opengl/appenda1_3soj.htm \ No newline at end of file diff --git a/Rotor.C b/Rotor.C new file mode 100644 index 0000000..922cc3c --- /dev/null +++ b/Rotor.C @@ -0,0 +1,155 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Rotor.C +// Last modified: April 25, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include +#include "Rotor.h" + + +#define ABS(x) ((x>0)?x:-x) +#define IFSHIFT if(getbutton(LEFTSHIFTKEY)||getbutton(RIGHTSHIFTKEY)) +#define PRESS(K,A,b) if(getbutton(K)){IFSHIFT{A;}else{b;}} + +/* static float **id = {{1.,0.,0.,0.}, + {0.,1.,0.,0.}, + {0.,0.,1.,0.}, + {0.,0.,0.,1.}}; + Matrix aff = {{1.,0.,0.,0.}, + {0.,1.,0.,0.}, + {0.,0.,1.,0.}, + {0.,0.,0.,1.}}; +*/ + +Rotor::Rotor() +{ + active = 1; + mouseX = mouseY = 0; + isMouseLeftDown = isMouseRightDown = isShiftDown =0; + + aff = new float[16]; + + for(int i=0; i<16;i++) + { + if((i%5)==0) + aff[i]=1; + else + aff[i]=0; + } +} + +Rotor::~Rotor() +{ + delete aff; +} + + +void Rotor::Rotate() +{ + float dx = (active ? mouseX : 0.0); + float dy = (active ? mouseY : 0.0); + if (active) { + int xt, yt; + + //get the window size + xt = glutGet(GLUT_WINDOW_WIDTH); + yt = glutGet(GLUT_WINDOW_HEIGHT); + // getsize(&xt,&yt); + + //determine where the mose is in relation to the center or "origin" of the window + if(dx != 0.0) + dx -= xt/2; + if(dy!= 0.0) + dy -= yt/2; + + dx = ((-20 < dx) &&(20 > dx) ? 0 : dx); + dy = ((-20 < dy) &&(20 > dy) ? 0 : dy); + + dy = -dy; + } + + pushmatrix(); + glLoadIdentity(); + + // loadmatrix(id); //replaces what's there by the identity + translate(aff[12],aff[13],aff[14]); + + if (active) { + float torq = .01; + rot(dx*torq,'y'); rot(-dy*torq, 'x'); + if(isMouseRightDown) + { + if(isShiftDown) + rot(-10, 'z'); + else + rot(-1, 'z'); + } + + if(isMouseLeftDown) + { + if(isShiftDown) + rot(10, 'z'); + else + rot(1,'z'); + } + } + + translate(-aff[12],-aff[13],-aff[14]); + multmatrix(aff); getmatrix(aff); //x = x+dx aff<- daff*aff + popmatrix(); + multmatrix(aff); //replaces rotate turn tilt +} + +void Rotor::CurrentMousePosition(int x, int y) +{ + mouseX = x; + mouseY = y; +} + +void Rotor::Activate() +{ + active = 1; +} + +void Rotor::Deactivate() +{ + active = 0; +} + +void Rotor::MouseLeftDown() +{ + isMouseLeftDown =1; +} + +int Rotor::MouseLeftUp() +{ + isMouseLeftDown =0; + return isMouseRightDown; +} + +void Rotor::MouseRightDown() +{ + isMouseRightDown =1; +} + +int Rotor::MouseRightUp() +{ + isMouseRightDown =0; + return isMouseLeftDown; +} + +void Rotor::ShiftDown() +{ + isShiftDown = 1; +} + +void Rotor::ShiftUp() +{ + isShiftDown =0; +} + diff --git a/Rotor.h b/Rotor.h new file mode 100644 index 0000000..af9197d --- /dev/null +++ b/Rotor.h @@ -0,0 +1,36 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Rotor.h +// Last modified: April 25, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include +#include +#include "Shared.h" + +class Rotor { +public: + Rotor(); + ~Rotor(); + void CurrentMousePosition(int x, int y); + void Rotate(); + void Activate(); + void Deactivate(); + void MouseLeftDown(); // returns state of other mouse button + int MouseLeftUp(); + void MouseRightDown(); + int MouseRightUp(); //returns state of other mouse button + void ShiftDown(); + void ShiftUp(); + +private: + int isMouseLeftDown, isMouseRightDown, isShiftDown; + int active; + int mouseX, mouseY; + + float *aff; +}; diff --git a/SPiece.C b/SPiece.C new file mode 100644 index 0000000..c11f340 --- /dev/null +++ b/SPiece.C @@ -0,0 +1,83 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// SPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +SPiece::SPiece() : GenPiece(4) +{ + centerstat = 1; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 (see documentation for visualization) + newpos[0][i] = dudeman[i] + (((i == X) || (i == W)) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i] + ((i == X) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == W) ? -1 : 0); + +/* + for (i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + cout << "newpos["<SetColor(0x00ff00); + } + + delete dudeman; + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/Shared.C b/Shared.C new file mode 100644 index 0000000..71871ae --- /dev/null +++ b/Shared.C @@ -0,0 +1,44 @@ +//Created by: Benjamin Bernard +//for 4D Tetris a program written By Greg Kaiser +// +// Shared.C +// Last modified: May8th, 2001 - Benjamin Bernard +// + + +#include "Shared.h" + +void getmatrix(float* mat){glGetFloatv(GL_MODELVIEW_MATRIX, mat);} + +void rectcopy(int x1, int y1, int x2, int y2, int newx, int newy){ + glCopyPixels( x1, y1, x2-x1, y2-y1, GL_COLOR); +} + +void cpack(long hexad){ + float red, green, blue; + red = (hexad & 255)/255.; + green = ((hexad >> 8) & 255)/255.; + blue = ((hexad >> 16)& 255)/255.; + //alpha = ((hexad >> 32)& 255)/255.; + glColor3f(red,green,blue); + } + +void rot(int degrees, char axis) +{ + if(axis == 'x') + glRotatef(degrees, 1.,0.,0.); + else if(axis == 'y') + glRotatef(degrees, 0.,1.,0.); + else if(axis == 'z') + glRotatef(degrees, 0.,0.,1.); +} + + +void lrectwrite(int x1, int y1, int x2, int y2, unsigned long* offbase){ + int pair[2]; + pair[0]=x1; + pair[1]=y1; + glRasterPos2iv(pair) ; + glDrawPixels(x2-x1, y2-y1, GL_RGB, GL_UNSIGNED_INT, offbase); + +} diff --git a/Shared.h b/Shared.h new file mode 100644 index 0000000..e701c4b --- /dev/null +++ b/Shared.h @@ -0,0 +1,76 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// Shared.h +// Last modified: May 8th, 2001 - Benjamin Bernard +// +// (C) 1996 Board of Trustees University of Illinois + +#ifndef _SHARED_H_ +#define _SHARED_H_ + +#define X 0 +#define Y 1 +#define Z 2 +#define W 3 + + +//attempt to convert to OpenGL +#define BF_SA GL_SRC_ALPHA +#define BF_MSA GL_ONE_MINUS_SRC_ALPHA + +#define pushmatrix() {glMatrixMode(GL_MODELVIEW); glPushMatrix();} +#define loadmatrix glLoadMatrixf +#define multmatrix glMultMatrixf +#define popmatrix glPopMatrix +#define bgntmesh() glBegin(GL_TRIANGLE_STRIP) +#define endtmesh glEnd +#define bgnpolygon() glBegin(GL_POLYGON) +#define endpolygon() glEnd +#define bgnline() glBegin(GL_LINE_STRIP); +#define endline glEnd +#define linewidth +#define depthcue +#define v3f glVertex3fv +#define v2f glVertex2fv +#define translate glTranslatef +#define viewport glViewport +#define window glFrustum +#define ortho glOrtho +#define ortho2(a,b,c,d) glOrtho(a,b,c,d,10.0,-10) /* ogl has no ortho2 ?? */ +#define swapbuffers glutSwapBuffers +#define rectzoom glPixelZoom +#define blendfunction glBlendFunc +#define zbuffer(a) glEnable(GL_DEPTH_TEST) +#define doublebuffer ChoosePixelFormat +//#define clear() glClear(GL_COLOR_BUFFER_BIT) // has problems with clear in the iostream library +#define zclear() glCear(GL_DEPTH_BUFFER_BIT) + +#include + + +void getmatrix(float* mat); + +void rectcopy(int x1, int y1, int x2, int y2, int newx, int newy); + +void cpack(long hexad); + +void rot(int degrees, char axis); + + +void lrectwrite(int x1, int y1, int x2, int y2, unsigned long* offbase); + +#endif + + + + + + + + + + + diff --git a/SharedFunctions.h b/SharedFunctions.h new file mode 100644 index 0000000..6b3d2f7 --- /dev/null +++ b/SharedFunctions.h @@ -0,0 +1,50 @@ +#ifndef _SHARED_FUNCTIONS_H +#define _SHARED_FUNCTIONS_H + +#include +#include "Shared.h" + +/**********************************************************************/ +//void rotate(int angle, int axis){return;} +void getmatrix(float* mat){glGetFloatv(GL_MODELVIEW_MATRIX, mat);} +/**********************************************************************/ +//int getbutton(unsigned char key){ /* returns that keybit was set */ +// if(CLAW & (1<> 8) & 255)/255.; + blue = ((hexad >> 16)& 255)/255.; + glColor3f(red,green,blue); + } + +void rot(int degrees, char axis) +{ + if(axis == 'x') + glRotatef(degrees, 1.,0.,0.); + else if(axis == 'y') + glRotatef(degrees, 0.,1.,0.); + else if(axis == 'z') + glRotatef(degrees, 0.,0.,1.); +} + + +void lrectwrite(int x1, int y1, int x2, int y2, unsigned long* offbase){ + int pair[2]; + pair[0]=x1; + pair[1]=y1; + glRasterPos2iv(pair) ; + glDrawPixels(x2-x1, y2-y1, GL_RGB, GL_UNSIGNED_INT, offbase); + +} + + + +#endif diff --git a/SimplePiece.C b/SimplePiece.C new file mode 100644 index 0000000..76e8194 --- /dev/null +++ b/SimplePiece.C @@ -0,0 +1,47 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// SimplePiece.C +// Last modified: April 22, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +SimplePiece::SimplePiece() : GenPiece(1) +{ + centerstat = 0; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] /2); + dudeman[W] = DIM[W]; + + float *high = new float[4]; + float *low = new float[4]; + + for (i = 0; i < 4; i++) { + low[i] = botcorner[i] + dudeman[i] * LEN[i]; + high[i] = low[i] + LEN[i]; + } + + float *temp = new float[4]; + for (i = 0; i < 4; i++) + temp[i] = (low[i] + high[i]) / 2; + + center = new FourD(temp); + delete temp; + + cubes[0] = new Hyper(low, high, dudeman); + cubes[0]->SetColor(0x0066ff); + + delete dudeman; + delete low; + delete high; +} diff --git a/StraightPiece.C b/StraightPiece.C new file mode 100644 index 0000000..5ad21dc --- /dev/null +++ b/StraightPiece.C @@ -0,0 +1,84 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// StraightPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +StraightPiece::StraightPiece() : GenPiece(4) +{ + centerstat = 2; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == W) ? 2 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i] + ((i == W) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == W) ? -1 : 0); + +/* + for (i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + cout << "newpos["<SetColor(0xffff00); + } + + delete dudeman; + + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/TPiece.C b/TPiece.C new file mode 100644 index 0000000..7badea4 --- /dev/null +++ b/TPiece.C @@ -0,0 +1,84 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// TPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +TPiece::TPiece() : GenPiece(4) +{ + centerstat = 1; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == W) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i] + ((i == X) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == W) ? -1 : 0); + +/* + for (i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + cout << "newpos["<SetColor(0xff00ff); + } + + delete dudeman; + + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/ThreeLinePiece.C b/ThreeLinePiece.C new file mode 100644 index 0000000..9425327 --- /dev/null +++ b/ThreeLinePiece.C @@ -0,0 +1,73 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// ThreeLinePiece.C +// Last modified: April 22, 1996 + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +ThreeLinePiece::ThreeLinePiece() : GenPiece(3) +{ + centerstat = 1; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[3]; + for (i = 0; i < 3; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == W) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i] + ((i == W) ? -1 : 0); + + float **low = new float*[3]; + float **high = new float*[3]; + for (i = 0; i < 3; i++) { + low[i] = new float[4]; + high[i] = new float[4]; + } + + for (i = 0; i < 3; i++) + for (int j = 0; j < 4; j++) { + low[i][j] = botcorner[j] + newpos[i][j] * LEN[j]; + high[i][j] = low[i][j] + LEN[j]; + } + + float *temp = new float[4]; + for (i = 0; i < 4; i++) + temp[i] = (low[centerstat][i] + high[centerstat][i]) / 2; + + center = new FourD(temp); + delete temp; + + for (i = 0; i < 3; i++) { + cubes[i] = new Hyper(low[i], high[i], newpos[i]); + cubes[i]->SetColor(0xff6699); + } + + delete dudeman; + + for (i = 0; i < 3; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/TriPiece.C b/TriPiece.C new file mode 100644 index 0000000..9e9ea76 --- /dev/null +++ b/TriPiece.C @@ -0,0 +1,76 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// TriPiece.C +// Last modified: April 22, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +TriPiece::TriPiece() : GenPiece(3) +{ + centerstat = -1; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = DIM[W]; + + int **newpos = new int*[3]; + for (i = 0; i < 3; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i== W) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i] + ((i == X) ? 1 : 0); + + float **low = new float*[3]; + float **high = new float*[3]; + for (i = 0; i < 3; i++) { + low[i] = new float[4]; + high[i] = new float[4]; + } + + for (i = 0; i < 3; i++) + for (int j = 0; j < 4; j++) { + low[i][j] = botcorner[j] + newpos[i][j] * LEN[j]; + high[i][j] = low[i][j] + LEN[j]; + } + + float *temp = new float[4]; + for (i = 0; i < 4; i++) + temp[i] = botcorner[i] + dudeman[i]*LEN[i]+(((i == W)||(i == X))?LEN[i]:0); + + center = new FourD(temp); + delete temp; + + for (i = 0; i < 3; i++) { + cubes[i] = new Hyper(low[i], high[i], newpos[i]); + cubes[i]->SetColor(0x99ff66); + } + + delete dudeman; + + for (i = 0; i < 3; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} + diff --git a/TwistyPiece.C b/TwistyPiece.C new file mode 100644 index 0000000..73f2553 --- /dev/null +++ b/TwistyPiece.C @@ -0,0 +1,84 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// TwistyPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +TwistyPiece::TwistyPiece() : GenPiece(4) +{ + centerstat = -1; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[4]; + for (i = 0; i < 4; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == Z) ? -1 : 0); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i] + ((i == X) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + (((i == X) || (i == Y)) ? 1 : 0); + + /* + for (i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + cout << "newpos["<SetColor(0x666666); + } + + delete dudeman; + + for (i = 0; i < 4; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/TwoPiece.C b/TwoPiece.C new file mode 100644 index 0000000..1e37e09 --- /dev/null +++ b/TwoPiece.C @@ -0,0 +1,72 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// TwoPiece.C +// Last modified: April 22, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +TwoPiece::TwoPiece() : GenPiece(2) +{ + centerstat = 0; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[2]; + for (i = 0; i < 2; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i] + ((i == W) ? -1 : 0); + + float **low = new float*[2]; + float **high = new float*[2]; + for (i = 0; i < 2; i++) { + low[i] = new float[4]; + high[i] = new float[4]; + } + + for (i = 0; i < 2; i++) + for (int j = 0; j < 4; j++) { + low[i][j] = botcorner[j] + newpos[i][j] * LEN[j]; + high[i][j] = low[i][j] + LEN[j]; + } + + float *temp = new float[4]; + for (i = 0; i < 4; i++) + temp[i] = (low[centerstat][i] + high[centerstat][i]) / 2; + + center = new FourD(temp); + delete temp; + + for (i = 0; i < 2; i++) { + cubes[i] = new Hyper(low[i], high[i], newpos[i]); + cubes[i]->SetColor(0x6699ff); + } + + delete dudeman; + + for (i = 0; i < 2; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/ZPiece.C b/ZPiece.C new file mode 100644 index 0000000..bbf551b --- /dev/null +++ b/ZPiece.C @@ -0,0 +1,89 @@ +// Greg Kaiser +// +// CS290 with Prof. Francis +// 4D Tetris +// +// ZPiece.C +// Last modified: April 17, 1996 +// +// (C) 1996 Board of Trustees University of Illinois + +#include "Pieces.h" + +extern int *DIM; +extern float *LEN; +extern float *botcorner; + +ZPiece::ZPiece() : GenPiece(5) +{ + centerstat = 2; + + int *dudeman = new int[4]; + for (int i = 0; i < 3; i++) + dudeman[i] = (DIM[i] / 2); + dudeman[W] = (DIM[W] + 1); + + int **newpos = new int*[5]; + + for (i = 0; i < 5; i++) + newpos[i] = new int[4]; + + for (i = 0; i < 4; i++) // cube 0 + newpos[0][i] = dudeman[i] + ((i == Y) ? 1 : ((i == X) ? -1 : 0)); + + for (i = 0; i < 4; i++) // cube 1 + newpos[1][i] = dudeman[i] + ((i == Y) ? 1 : 0); + + for (i = 0; i < 4; i++) // cube 2 + newpos[2][i] = dudeman[i]; + + for (i = 0; i < 4; i++) // cube 3 + newpos[3][i] = dudeman[i] + ((i == Y) ? -1 : 0); + + for (i = 0; i < 4; i++) // cube 4 + newpos[4][i] = dudeman[i] + ((i == Y) ? -1 : ((i == X) ? 1 : 0)); + + /* + for (i = 0; i < 5; i++) + for (int j = 0; j < 4; j++) + cout << "newpos["<SetColor(0x1ab23c); + cubes[i]->SetColor(0x0066ff); + } + + delete dudeman; + + for (i = 0; i < 5; i++) { + delete newpos[i]; + delete low[i]; + delete high[i]; + } + + delete newpos; + delete low; + delete high; +} diff --git a/appenda1_3soj.htm b/appenda1_3soj.htm new file mode 100644 index 0000000..94d7b15 --- /dev/null +++ b/appenda1_3soj.htm @@ -0,0 +1,1856 @@ + + + + + +OpenGL Functions and Their IRIS GL Equivalents + + + + + + + + + + + + +

OpenGL Functions and Their IRIS GL Equivalents

+ +

This appendix lists IRIS GL functions and their equivalent OpenGL functions. The first column is an alphabetic list of IRIS GL functions, the second column contains the corresponding functions to use in OpenGL.

+ +

Note  The following OpenGL functions listed may behave somewhat differently from the IRIS GL commands, and the parameters may be different as well. For more information on the differences between IRIS GL and OpenGL, see I +RIS GL and OpenGL Differences.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IRIS GL functionOpenGL,GLU, or Win32 function
acbufglAccum
acsizeChoosePixelFormat
addtopupUse Win32 for menus.
afunctionglAlphaFunc
arcgluPartialDisk
backbufferglDrawBuffer(GL_BACK)
backfaceglCullFace(GL_BACK)
bbox2Not supported.
bgnclosedlineglBegin(GL_LINE_LOOP)
bgncurvegluBeginCurve
bgnlineglBegin(GL_LINE_STRIP)
bgnpointglBegin(GL_POINTS)
bgnpolygonglBegin(GL_POLYGON)
bgnqstripglBegin(GL_QUAD_STRIP)
bgnsurfacegluBeginSurface
bgntmeshglBegin(GL_TRIANGLE_STRIP)
bgntrimgluBeginTrim
blankscreenUse Win32 for windowing.
blanktimeUse Win32 for windowing.
blendfunctionglBlendFunc
blinkUse Win32 for color maps.
blkqreadUse Win32 for event handling.
c glColor
callfuncNot supported.
callobj glCallList
charstrglCallLists
chunksizeNot needed.
circgluDisk
clearglClear(GL_COLOR_BUFFER_BIT)
clearhitcodeNot supported.
clipplane glClipPlane
clkonUse Win32 for keyboard management.
clkoffUse Win32 for keyboard management.
closeobjglEndList
cmodeChoosePixelFormat
cmov
+cmov2
glRasterPos3
+glRasterPos2
colorglIndex
compactifyNot needed.
concavegluBeginPolygon
cpackglColor
crvNot supported.
crvnNot supported.
curoriginUse Win32 for cursors.
cursoffUse Win32 for cursors.
cursonUse Win32 for cursors.
curstypeUse Win32 for cursors.
curvebasisglMap1
curveitglEvalMesh1
curveprecision Not supported.
cyclemapUse Win32 for color maps.
czclearglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
dbtextNot supported.
defbasisglMap1
defcursorUse Win32 for cursors.
deflinestyleglLineStipple
defpattern glPolygonStipple
defpupUse Win32 for menus.
defrasterfont wglUseFontBitmaps
delobj glDeleteLists
deltagNot supported.
depthcueglFog
dglcloseNot needed. (OpenGL is network transparent.)
dglopenNot needed. (OpenGL is network transparent.)
ditherglEnable(GL_DITHER)
dopupUse Win32 for menus.
doublebufferChoosePixelFormat
drawglBegin(GL_LINES)
drawmodewglMakeCurrent
editobjNot supported.
endclosedlineglEnd
endcurvegluEndCurve
endfeedbackglRenderMode(GL_RENDER)
endfullscreenNot supported.
endlineglEnd
endpickglRenderMode(GL_RENDER)
endpointglEnd
endpolygonglEnd
endpupmodeUse Win32 for menus.
endqstripglEnd
endselectglRenderMode(GL_RENDER)
endsurfacegluEndSurface
endtmeshglEnd
endtrimgluEndTrim
feedbackglFeedbackBuffer
finishglFinish
fogvertex glFog
fontglListBase
foregroundUse Win32 for windowing.
freepupUse Win32 for menus.
frontbufferglDrawBuffer(GL_FRONT)
frontfaceglCullFace
fudgeUse Win32 for windowing.
fullscrnNot supported.
gammarampUse Win32 for color maps.
gbeginUse Win32 for windowing.
gconfigNo equivalent. (Not needed.)
genobjglGenLists
gentagNot supported.
getbackfaceglGet
getbufferglGet
getbuttonUse Win32 for windowing.
getcmmodewglGetCurrentContext
getcolorglGet
getcposglGet
getcursorNot supported.
getdcmglIsEnabled
getdepthglGet
getdescenderUse Win32 for fonts.
getdevNot supported.
getdisplaymodeglGet
 wglGetCurrentContext
getdrawmodewglGetCurrentContext
getfontUse Win32 for fonts.
getgdescglGet
+DescribePixelFormat
+wglGetCurrentContext
+wglGetCurrentDC
getgpos Not supported.
getheightUse Win32 for fonts.
gethitcodeNot supported.
getlsbackupNot supported.
getlsrepeatglGet
getlstyleglGet
getlwidthglGet
getmap(void)Not supported.
getmatrixglGet(GL_MODELVIEW_MATRIX)
+glGet(GL_PROJECTION_MATRIX)
getmcolorNot supported.
getmmodeglGet(GL_MATRIX_MODE)
getmonitorNot supported.
getnurbsproperty gluGetNurbsProperty
getopenobjNot supported.
getoriginUse Win32 for windowing.
getpatternglGetPolygonStipple
getplanesglGet(GL_RED_BITS)
+glGet(GL_GREEN_BITS)
+glGet(GL_BLUE_BITS)
getportUse Win32 for windowing.
getresetlsNot supported.
getscrboxNot supported.
getscrmask glGet(GL_SCISSOR_BOX)
getshadeglGet(GL_CURRENT_INDEX)
getsizeUse Win32 for windowing.
getsmglGet(GL_SHADE_MODEL)
getvaluatorUse Win32 for event handling
getvideoNot supported.
getviewportglGet(GL_VIEWPORT)
getwritemaskglGet(GL_INDEX_WRITEMASK)
getwscrnUse Win32 for windowing.
getzbufferglIsEnabled(GL_DEPTH_TEST)
gexitUse Win32 for windowing.
gflushglFlush
ginitUse Win32 for windowing.
glcompatNot supported.
gresetNot supported.
gRGBcolorglGet(GL_CURRENT_RASTER_COLOR)
gRGBcursorUse Win32 for cursors.
gRGBmaskglGet(GL_COLOR_WRITEMASK)
gselect glSelectBuffer
gsyncUse Win32 for windowing.
gversionglGetString(GL_RENDERER)
iconsizeUse Win32.
icontitleUse Win32.
imakebackgroundUse Win32 for event handling.
initnamesglInitNames
ismexNot supported.
isobjglIsList
isqueuedUse Win32 for event handling.
istagNot supported.
keepaspectUse Win32 for windowing.
lampoffNot supported.
lamponNot supported.
linesmoothglEnable(GL_LINE_SMOOTH)
linewidthglLineWidth
linewidthfglLineWidth
lmbindglEnable(GL_LIGHTING)
+glEnable(GL_LIGHT)
lmcolorglColorMaterial
lmdefglMaterial
+glLight
+glLightModel
loadmatrixglLoadMatrix
loadnameglLoadName
logicopglLogicOp
lookat gluLookAt
lrectread glReadPixels
lrectwrite(])glDrawPixels
lRGBrangeNot supported. (See glFog.)
lsbackupNot supported.
lsetdepthglDepthRange
lshaderangeNot supported. (See glFog.)
lsrepeatglLineStipple
makeobjglNewList
maketagNot supported.
mapcolorUse Win32 for color maps.
mapwgluProject
maxsizeUse Win32 for windowing.
minsizeUse Win32 for windowing.
mmodeglMatrixMode
moveNot supported.
mswapbuffersUse Win32 for windowing.
multimapUse Win32 for color maps.
multmatrixglMultMatrix
n3fglNormal3fv
newpupUse Win32 for Menus.
newtagNot supported.
nmodeglEnable(GL_NORMALIZE)
noborderUse Win32 for windowing.
noiseUse Win32 for event handling.
noportUse Win32 for windowing.
normalglNormal3fv
nurbscurvegluNurbsCurve
nurbssurfacegluNurbsSurface
objdeleteNot supported.
objinsertNot supported.
objreplaceNot supported.
onemapUse Win32 for color maps.
orthoglOrtho
ortho2gluOrtho2D
overlayUse Win32.
pagecolorNot supported.
passthroughglPassThrough
patchglEvalMesh2
patchbasisglMap2
patchcurvesglMap2
patchprecisionNot supported.
pclosNot supported. (See glEnd.)
pdrNot supported. (See glVertex.)
perspectivegluPerspective
pickgluPickMatrix
+glRenderMode(GL_SELECT)
picksize gluPickMatrix
pixmodeglPixelTransfer and 3
pmvNot supported. (See glBegin and glVertex.)
pntglBegin(GL_POINTS)
pntsizeglPointSize
pntsizefglPointSize
pntsmoothglEnable(GL_POINT_SMOOTH)
polarviewNot supported. (See glRotate and glTranslate.)
polfNot supported.
polyNot supported.
polymodeglPolygonMode
polysmoothglEnable(GL_POLYGON_SMOOTH)
popattributesglPopAttrib
popmatrixglPopMatrix
popnameglPopName
popviewportglPopAttrib
prefpositionUse Win32 for windowing.
prefsizeUse Win32 for windowing.
pupmodeUse Win32 for windowing.
pushattributesglPushAttrib
pushmatrixglPushMatrix
pushnameglPushName
pushviewportglPushAttrib(GL_VIEWPORT)
pwlcurvegluPWLCurve
qcontrolUse Win32 for event handling.
qdeviceUse Win32 for event handling.
qenterUse Win32 for event handling.
qgetfdUse Win32 for event handling.
qreadUse Win32 for event handling.
qresetUse Win32 for event handling.
qtestUse Win32 for event handling.
rcrvNot supported.
rcrvnNot supported.
rdrNot supported.
readdisplayNot supported.
readRGBNot supported.
readsourceglReadBuffer
rectglRect
+glPolygonMode
rectfglRect
rectcopy glCopyPixels
rectreadglReadPixels
rectwriteglDrawPixels
rectzoomglPixelZoom
resetlsNot supported.
reshapeviewportNot supported.
RGBcolorglColor
RGBcursorUse Win32 for cursors.
RGBmodeUse Win32 for windowing.
RGBrangeNot supported.
RGBwritemaskglColorMask
ringbellNot supported.
rmvNot supported.
rotglRotate
rotateglRotate
rpatchNot supported.
rpdrNot supported.
rpmvNot supported.
sboxglRect
scaleglScale
sclearglClear(GL_STENCIL_BUFFER_BIT)
scrboxNot supported.
screenspaceNot supported.
scrmask glScissor
scrnattachUse Win32 for windowing.
scrnselectUse Win32 for windowing.
scrsubdivideNot supported.
selectglRenderMode
setbellNot supported.
setcursor Use Win32 for cursors.
setdblightsNot supported.
setdepthglDepthRange
setlinestyleglLineStipple
setmapUse Win32 for color maps.
setmonitorNot supported.
setnurbspropertygluNurbsProperty
setpatternglPolygonStipple
setpupUse Win32 for menus.
setvaluatorUse Win32 for devices.
setvideoNot supported.
shademodelglShadeModel
shaderangeglFog
singlebufferUse Win32 for windowing.
smoothlineglEnable(GL_LINE_SMOOTH)
spclosNot supported.
splfNot supported. (See glBegin.)
stencilglStencilFunc
+glStencilOp
stensizeglStencilMask
stepunitUse Win32 for windowing.
strwidthUse Win32 for fonts and strings.
subpixelNot needed.
swapbuffersSwapBuffers
swapintervalUse Win32 for windowing.
swaptmeshNot supported.
+(See glBegin(GL_TRIANGLE_FAN).)
swinopenUse Win32 for windowing.
swritemaskglStencilMask
t2glTexCoord2
tevbind glTexEnv
tevdef glTexEnv
texbindglTexImage2D
+glTexParameter
+gluBuild2DMipmaps
texdef2dglTexImage2D
+glTexParameter
+gluBuild2DMipmaps
texgenglTexGen
textcolorNot supported.
textinitNot supported.
textportNot supported.
tieUse Win32 for event handling.
tpoffNot supported.
tponNot supported.
translateglTranslate
underlayChoosePixelFormat
unqdeviceUse Win32 for event handling.
vglVertex
videocmdNot supported.
viewportglViewport
winattachUse Win32 for windowing.
winclosewglDeleteContext
+CloseWindow
winconstraintsUse Win32 for windowing.
windepthUse Win32 for windowing.
window glFrustum
wingetwglGetCurrentContext
winmoveUse Win32 for windowing.
winopenUse Win32 for windowing.
winpopUse Win32 for windowing.
winposition Use Win32 for windowing.
winpushUse Win32 for windowing.
winsetUse Win32 for windowing.
wintitleUse Win32 for windowing.
wmpackglColorMask
writemaskglIndexMask
writepixelsglDrawPixels
writeRGBglDrawPixels
xfptNot supported.
zbufferglEnable(GL_DEPTH_TEST)
zclearglClear(GL_DEPTH_BUFFER_BIT)
zdrawNot supported.
zfunctionglDepthFunc
zsourceNot supported.
zwritemaskglDepthMask

+ +

+ + + + + + diff --git a/cpp.mf b/cpp.mf new file mode 100755 index 0000000..9dd44a8 --- /dev/null +++ b/cpp.mf @@ -0,0 +1,24 @@ +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +.c: + CC $*.c -o $* $(CFLAGS) $(LDFLAGS) + diff --git a/ht.mf b/ht.mf new file mode 100755 index 0000000..8ba70f7 --- /dev/null +++ b/ht.mf @@ -0,0 +1,49 @@ +OBJS = Main.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +VSSLIB = -L$(VSSDIR) -lsnd_o32 +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + +EXENAME = tetris + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +$(EXENAME): $(OBJS) + CC -o $(CFLAGS) $(LDFLAGS) $(OBJS) + +.C.o: + CC -c $(CFLAGS) $(LDFLAGS) diff --git a/htetris.mf b/htetris.mf new file mode 100755 index 0000000..5e19b95 --- /dev/null +++ b/htetris.mf @@ -0,0 +1,52 @@ +OBJS = Main.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +VSSLIB = -L$(VSSDIR) -lsnd_o32 +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + + + + + + + + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +.c: + CC $*.c -o $* $(CFLAGS) $(LDFLAGS) + diff --git a/htetris.test b/htetris.test new file mode 100755 index 0000000..a45351e --- /dev/null +++ b/htetris.test @@ -0,0 +1,54 @@ +OBJS = Main.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +VSSLIB = -L$(VSSDIR) -lsnd_o32 +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + +EXENAME = a.out + + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +$(EXENAME): $(OBJS) + CC $(CFLAGS) $(LDFLAGS) $(OBJS) + +.C.o: + CC $*.C -o $* $(CFLAGS) $(LDFLAGS) + + + + diff --git a/htetristest.makefile b/htetristest.makefile new file mode 100755 index 0000000..73fa1ca --- /dev/null +++ b/htetristest.makefile @@ -0,0 +1,50 @@ +OBJS = Main.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +VSSLIB = -L$(VSSDIR) -lsnd_o32 +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + +EXENAME = a.out + + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +$(EXENAME): $(OBJS) + CC $(CFLAGS) $(LDFLAGS) $(OBJS) + +.C.o: + CC -o $(CFLAGS) $(LDFLAGS) $? diff --git a/ml.c b/ml.c new file mode 100644 index 0000000..418493b --- /dev/null +++ b/ml.c @@ -0,0 +1,551 @@ +/* igl2ogl translation by */ +/* Matthew Rakher, Math 198, 2001 */ +/* lica.c copyright Chris Hartman 1992-1997*/ +/* this is the final version 27feb97 */ +#include +#include +#include +#include /* for the speedometer */ +#include +#include +#pragma warning (disable:581) +/* igl2ogl defines.i20 */ +#define LEFTMOUSE '[' +#define RIGHTMOUSE ']' +#define ENDKEY 'e' +#define ESCKEY 27 +#define AKEY 'A' +#define UKEY 'U' +#define JKEY 'J' +#define TKEY 'T' +#define PKEY 'P' +#define QKEY 'Q' +#define SKEY 'S' +#define RKEY 'R' +#define IKEY 'I' +#define NKEY 'N' +#define HKEY 'H' +#define LKEY 'L' +#define VKEY 'V' +#define SCROLLOCKKEY +#define MOUSE3 +#define MOUSEX +#define MOUSEY +#define CAPSLOCK +#define fsin sin +#define fcos cos +#define fsqrt sqrt +#define pushmatrix glPushMatrixf +#define loadmatrix glLoadMatrixf +#define multmatrix glMultMatrixf +#define popmatrix glPopMatrixf +#define bgntmesh() glBegin(GL_TRIANGLE_STRIP) +#define endtmesh glEnd +#define bgnpolygon() glBegin(GL_POLYGON) +#define endpolygon() glEnd +#define bgnline() glBegin(GL_LINE_STRIP); +#define endline glEnd +#define linewidth +#define depthcue +#define v3f glVertex3fv +#define v2f glVertex2fv +#define translate glTranslatef +#define viewport glViewport +#define window glFrustum +#define ortho glOrtho +#define ortho2(a,b,c,d) glOrtho(a,b,c,d,10.0,-10) /* ogl has no ortho2 ?? */ +#define swapbuffers glutSwapBuffers +#define rectzoom glPixelZoom + +#define IFCLICK(K,a){static flag=1;if(getbutton(K))flag=1-flag;if(flag){a} } +/* global variables */ +float gap, gap0=1.; /* kludge so that arguments() can set a default gap0 */ +float lux[3]={1.,2.,3.}; /*world light direction vector */ +float luxx[3]; /* object space direction vector*/ +float amb, pwr ; /* ambient fraction, pseudo-specular power */ +float mysiz,speed, torq, focal, far; /*console navigation variables */ +int win = 1; /* 2 full screen, use 0 for demand sized */ +unsigned int CLAW,PAW,XX,YY,SHIF; /* used in chaptrack gluttery */ +int xt,yt; /* once was xt,yt,xm,ym for viewportery */ +int mode,morph,msg,binoc; /* pretty global */ +int th0, th1, dth, ta0, ta1, dta; /* torus parameters */ +#define FLYMODE (0) +#define TURNMODE (1) +int ii, jj, kk; float tmp, temp; /* saves gray hairs later */ +float aff[16], starmat[16], mat[16]; +int binoc; /* flag */ +float nose; /* to eye distance in console */ +/* end define.i2o */ +/**********************************************************************/ +void autotymer(int reset){ /* cheap animations */ +#define TYME(cnt,max,act) {static cnt; if(first)cnt=max; else\ + if(cnt?cnt--:0){ act ; goto Break;}} + static first = 1; /* the first time autymer is called */ + if(reset)first=1; /* or if it is reset to start over */ +#if 0 + TYME( shrink , 150,th0++;th1--;ta0++;ta1--) + TYME( pause , 20, ) + TYME( grow , 150,th0--;th1++;ta0--;ta1++) +#endif + TYME( dwell , 30, ) + TYME(finish , 1 , first = 1 ) + first = 0; + Break: ; /* yes Virginia, C has gotos */ +} +/**********************************************************************/ +void deFault(void){ +#if 0 +th0=5; th1=355; ta0=5; ta1=355; gap = gap0; +msg=1; binoc=0; nose=.06; mode=TURNMODE; +speed=.1; torq=.02; focal = 2.; far =13.; mysiz=.01; morph=0; +FOR(ii,0,16) starmat[ii]=aff[ii] = (ii/4==ii%4); /* identities */ +FOR(ii,0,3)lux[ii]/=NRM(lux); amb = .3; pwr = 10. ; +aff[12]=0; aff[13]= 0; aff[14]= -4.2; /* place where we can see it */ +autotymer(1); /* reset autotymer to start at the beginning */ +#endif +} +/**********************************************************************/ +void cpack(long hexad){ + float red, green, blue; + red = (hexad & 255)/255.; + green = ((hexad >> 8) & 255)/255.; + blue = ((hexad >> 16)& 255)/255.; + glColor3f(red,green,blue); + } +/**********************************************************************/ + +/**********************************************************************/ +void rotate(int angle, int axis){return;} +void getmatrix(float* mat){glGetFloatv(GL_MODELVIEW_MATRIX, mat);} +/**********************************************************************/ +int getbutton(unsigned char key){ /* returns that keybit was set */ + if(CLAW & (1<(y)?(x):(y)) +#define TBLSIZ (sumrule?(2*radius+1)*(colors-1)+1:pow(colors,2*radius+1)) + +char *line1, *line2, *table, *swline, *rules, filerules[1000][256],userrule[256]; +unsigned long *offbase,masks[MAXR+1], + pixval[MAXCOLORS+1][MAXCOLORS]= {{0,0,0,0,0,0,0,0}, + {0xff880088,0,0,0,0,0,0,0}, /*The following are the seven different color schemes.*/ + {0xff880088,0xff0044aa,0,0,0,0,0,0}, + {0xff0088aa,0xff660066,0xffaa0000,0,0,0,0,0}, + {0xff0000aa,0xff0088aa,0xffaa8800,0xffff0000,0,0,0,0}, + {0xff0000aa,0xff0088aa,0xff00aa00,0xffff4400,0xff880088,0,0}, + {0xff000088,0xff008888,0xff00ff88,0xff00aa22,0xffff8822,0xffff0044,0,0}, + {0xff000088,0xff008888,0xff00ff88,0xff00aa22,0xffff8822,0xffff0044,0xff880066,0}, + {0xff000088,0xff008888,0xff00ff88,0xff00aa22,0xffaaff44,0xffff8822,0xffff0044,0xff880066}}; +long xsize=MAXX,ysize,licawin,statuswin; +int rulenum=-1,numrules=0,gen=-1,bpc,sumrule=1, + phade=0,slowed=1,cellsize=5,scrolling=0,radius=1,colors=4; +FILE *rulefile; + +void rectcopy(int x1, int y1, int x2, int y2, int newx, int newy){ + glCopyPixels( x1, y1, x2-x1, y2-y1, GL_COLOR); +} + + +void lrectwrite(int x1, int y1, int x2, int y2, unsigned long* offbase){ + int pair[2]; + pair[0]=x1; + pair[1]=y1; + glRasterPos2iv(pair) ; + glDrawPixels(x2-x1, y2-y1, GL_RGB, GL_UNSIGNED_INT, offbase); + +} +/*attempt to transfer lrectwrite to ogl*/ + +arguments(int argc,char **argv) +{ +extern char *optarg; +extern int optind; +int c; + while ((c = getopt(argc,argv,"d:c:su:r:z:"))!= -1) + switch (c) + { + case 'c': colors=atoi(optarg); + if((colors>MAXCOLORS)||(colors<2)) + {printf("You must have 2<=colors<=%d.\n",MAXCOLORS); exit(1);} break; + case 'd': slowed=atoi(optarg); + if((slowed<1)) {printf("You can't have a negative delay.\n"); exit(1);} break; + case 'z': cellsize=atoi(optarg); + if((cellsize>100)||(cellsize<1)) + {printf("You must have 1<=cellsize<=100.\n"); exit(1);} break; + case 'r': radius=atoi(optarg); + if((radius>3)||(radius<0)) {printf("Radius must be 0,1,2 or 3.\n"); exit(1);} break; + case 'u': sumrule=atoi(optarg); + if((sumrule<0)||(sumrule>1)) {printf("Sum"); exit(1);} break; + } + if (optind!=argc) { fprintf(stderr, + "Usage: %s [-u rulebysums?] [-d delay] [-r radius] [-c numcolors] [-z squaresize] [-s].\n",argv[0]); + exit(1); + } + printf("Running with %d colors, radius %d, rules are%sby sums.\n", + colors, radius,(sumrule?" ":" not ")); +} + +calcnewline(char *from, char *to) +{ +unsigned long ii, cframe = 0; + +for (ii = 0; ii < 2 * radius; ii++) cframe = (cframe << bpc) | from[ii]; +for (ii = 2 * radius; ii < xsize + 2 * radius + 1; ii++) { + cframe = masks[radius] & ((cframe << bpc) | from[ii % xsize]); + to[(ii - radius + phade) % xsize] = rules[cframe]; + offbase[(ii - radius) % xsize] = pixval[colors][rules[cframe]]; + } +} + +makerules() +{ +int ii,jj=0; +unsigned long sum,aa[2*MAXR+2],state; + +for(ii=0;ii<2*radius+1;ii++) aa[ii]=0; +while(aa[2*radius]= colors)){ + table[ii]=colors-1; + fprintf(stderr,"Error in rule, clipping the values.\n"); + } + } + makerules(); + randomize(); + updatestatus(); +} + +saverule() +{ +int ii; + +if(rulefile = fopen("licarules","a")) + { + fprintf(rulefile,"%d:%d:%d:",colors,radius,sumrule); + for(ii=0;ii=numrules) rulenum=-1; + else dofullrule(filerules[rulenum]);while(getbutton(UPARROWKEY));} +if(getbutton(DOWNARROWKEY)) {rulenum--; if(rulenum<0) rulenum=-1; + else dofullrule(filerules[rulenum]);while(getbutton(DOWNARROWKEY));} +if(getbutton(NKEY)) {newrule();while(getbutton(NKEY));} +if(getbutton(F1KEY)) {for(inx=0;inxMAXCOLORS)colors=MAXCOLORS;} + while(getbutton(CKEY)) ; + } +if(getbutton(RKEY)) { + if(SHIFT){radius--;updatestatus();if(radius<0)radius=0;} + else {radius++;updatestatus();if(radius>MAXR)radius=MAXR;} + while(getbutton(RKEY)) ; + } +if(getbutton(IKEY)) {printf("Rule? ");rulenum=-1;scanf("%s",userrule);dorule(userrule);} +if(getbutton(COMMAKEY)) {slowed++;while(getbutton(COMMAKEY));} +if(getbutton(PERIODKEY)) {slowed--;if(slowed<0)slowed=0;while(getbutton(PERIODKEY));} +if(getbutton(PAD4)) {phade--;while(getbutton(PAD4));} +if(getbutton(PAD5)) phade=0; +if(getbutton(PAD6)) {phade++;while(getbutton(PAD6));} +if(getbutton(F12KEY)) {inx=RND*xsize;offbase[inx] = pixval[colors][line1[inx] + = ((int)(line1[inx]+1+(RND*(colors-1)))%colors)]; while(getbutton(F12KEY));} +if(getbutton(VKEY)) {updatestatus();rulenum=rulenum++;} +while(getbutton(CAPSLOCKKEY)); /*pause*/ +if(getbutton(MOUSE3)) + { +glutSetWindow(statuswin); /* winset(statuswin); */ + getorigin(&xo,&yo); + choice = (getvaluator(MOUSEX)-xo-5)/25; + entry = TBLSIZ-((getvaluator(MOUSEY)-yo-5)/25)-1; + if((choice>=0)&&(choice=0)) + {table[entry]=choice; makerules(); updatestatus();} + } +#endif +} + +/**********************************************************************/ +void special_keybo(int key, int x, int y){ + + + + +/*non-ASCII keypresses go here, if you're lucky enough to know their names */ + fprintf(stderr," non-ASCII character was pressed.\n"); + fprintf(stderr," use special_keybo() to process it\n"); +} +/**********************************************************************/ + + +/**********************************************************************/ +void char2wall(float x,float y,float z, char buf[]){ + char *p; glRasterPos3f(x,y,z); + for(p = buf;*p;p++) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,*p); +} +/**********************************************************************/ +void square(int sz, int xx, int yy, long cc) { + float vv[2]; char phrase[10]; + bgnpolygon(); + cpack(pixval[colors][cc]); + vv[0]=xx; vv[1]=yy; + v2f(vv); vv[0]+=sz; + v2f(vv); vv[1]-=sz; + v2f(vv); vv[0]-=sz; + v2f(vv); + endpolygon(); + if (sz==20) {cpack(0xffffffff); + sprintf(phrase,"%d",cc); + char2wall(xx+8,yy-14,0,phrase); + } +} + +void updatestatus(void){ + char phrase[256],name[20]; + int ii,jj,kk; + long xt,yt; + + glutSetWindow(statuswin); /* winset(statuswin); */ + /* I don't know what the new name for that is reshapeviewport(); */ + /* getsize(&xt,&yt); glutPostRedisplay??*/ + if((xt!=MAX(210,colors*25+100)||yt!=75+25*TBLSIZ)) + { + /* + prefsize(MAX(210,colors*25+100),75+25*TBLSIZ); + winconstraints(); don't know gkf + */ + } + viewport(0,MAX(210,colors*25+100),25*TBLSIZ,25*TBLSIZ+75); + cpack(0); /* clear(); */ + ortho2(0.,1.,0.,1.); cpack(0xffffffff); + sprintf(phrase,"Radius=%d, %d colors.",radius,colors); + char2wall(.05,.8,0,phrase); + sprintf(phrase,"Rules are%sby sums.",sumrule?" ":" not "); + char2wall(.05,.5,0,phrase); + for(ii=0;ii=0) sprintf(phrase+ii," (%d/%d)",rulenum+1,numrules); + char2wall(.05,.2,0,phrase); + + viewport(0,MAX(210,colors*25+100),0,25*TBLSIZ); + ortho2(0,MAX(210,colors*25+100),0,25*TBLSIZ); + cpack(0); /* clear(); */ + for(ii=0;ii"); + if(win==2) glutFullScreen(); + glEnable(GL_DEPTH_TEST); + glutDisplayFunc(drawcons); +/* the following 5 aren't needed for a picture */ + glutKeyboardFunc(keyboard); + glutSpecialFunc(special_keybo); + glutMouseFunc(mousepushed); + glutMotionFunc(mousemoved); + glutPassiveMotionFunc(mousemoved); +/* beyond here you do need them */ + glutReshapeFunc(reshaped); + glutIdleFunc(idle); + glutMainLoop(); +} + diff --git a/ml3.gkf b/ml3.gkf new file mode 100644 index 0000000..2c50f47 --- /dev/null +++ b/ml3.gkf @@ -0,0 +1,474 @@ +/* lica.c copyright Chris Hartman 1992-1997*/ +/* this is the final version 27feb97 */ +#include +#include +#include +#include /* for the speedometer */ +#include +#include +#pragma 581 +/* igl2ogl defines.i20 */ +#define LEFTMOUSE '[' +#define RIGHTMOUSE ']' +#define ENDKEY 'e' +#define ESCKEY 27 +#define AKEY 'A' +#define UKEY 'U' +#define JKEY 'J' +#define TKEY 'T' +#define PKEY 'P' +#define QKEY 'Q' +#define SKEY 'S' +#define RKEY 'R' +#define IKEY 'I' +#define NKEY 'N' +#define HKEY 'H' +#define LKEY 'L' +#define fsin sin +#define fcos cos +#define fsqrt sqrt +#define pushmatrix glPushMatrixf +#define loadmatrix glLoadMatrixf +#define multmatrix glMultMatrixf +#define popmatrix glPopMatrixf +#define bgntmesh() glBegin(GL_TRIANGLE_STRIP) +#define endtmesh glEnd +#define bgnline() glBegin(GL_LINE_STRIP); +#define endline glEnd +#define linewidth +#define depthcue +#define v3f glVertex3fv +#define translate glTranslatef +#define viewport glViewport +#define window glFrustum +#define ortho glOrtho +#define swapbuffers glutSwapBuffers +#define rectzoom glPixelZoom +int win = 1; /* 2 full screen, use 0 for demand sized */ +unsigned int CLAW,PAW,XX,YY,SHIF; /* used in chaptrack gluttery */ +#define IFCLICK(K,a){static flag=1;if(getbutton(K))flag=1-flag;if(flag){a} } +/* end define.i2o */ +/**********************************************************************/ +void rotate(int angle, int axis){return;} +void getmatrix(float* mat){glGetFloatv(GL_MODELVIEW_MATRIX, mat);} +/**********************************************************************/ +int getbutton(unsigned char key){ /* returns that keybit was set */ + if(CLAW & (1<(y)?(x):(y)) +#define TBLSIZ (sumrule?(2*radius+1)*(colors-1)+1:pow(colors,2*radius+1)) + +char *line1, *line2, *table, *swline, *rules, filerules[1000][256],userrule[256]; +unsigned long *offbase,masks[MAXR+1], + pixval[MAXCOLORS+1][MAXCOLORS]= {{0,0,0,0,0,0,0,0}, + {0xff880088,0,0,0,0,0,0,0}, /*The following are the seven different color schemes.*/ + {0xff880088,0xff0044aa,0,0,0,0,0,0}, + {0xff0088aa,0xff660066,0xffaa0000,0,0,0,0,0}, + {0xff0000aa,0xff0088aa,0xffaa8800,0xffff0000,0,0,0,0}, + {0xff0000aa,0xff0088aa,0xff00aa00,0xffff4400,0xff880088,0,0}, + {0xff000088,0xff008888,0xff00ff88,0xff00aa22,0xffff8822,0xffff0044,0,0}, + {0xff000088,0xff008888,0xff00ff88,0xff00aa22,0xffff8822,0xffff0044,0xff880066,0}, + {0xff000088,0xff008888,0xff00ff88,0xff00aa22,0xffaaff44,0xffff8822,0xffff0044,0xff880066}}; +long xsize=MAXX,ysize,licawin,statuswin; +int rulenum=-1,numrules=0,gen=-1,bpc,sumrule=1, + phade=0,slowed=1,cellsize=5,scrolling=0,radius=1,colors=4; +FILE *rulefile; + +void rectcopy(int x1, int y1, int x2, int y2, int newx, int newy){ + glCopyPixels( x1, y1, x2-x1, y2-y1, GL_COLOR); +} + + +void lrectwrite(int x1, int y1, int x2, int y2, unsigned long* offbase){ + int pair[2]; + pair[0]=x1; + pair[1]=y1; + glRasterPos2iv(pair) ; + glDrawPixels(x2-x1, y2-y1, GL_RGB, GL_UNSIGNED_INT, offbase); + +} +/*attempt to transfer lrectwrite to ogl*/ + +arguments(int argc,char **argv) +{ +extern char *optarg; +extern int optind; +int c; + while ((c = getopt(argc,argv,"d:c:su:r:z:"))!= -1) + switch (c) + { + case 'c': colors=atoi(optarg); + if((colors>MAXCOLORS)||(colors<2)) + {printf("You must have 2<=colors<=%d.\n",MAXCOLORS); exit(1);} break; + case 'd': slowed=atoi(optarg); + if((slowed<1)) {printf("You can't have a negative delay.\n"); exit(1);} break; + case 'z': cellsize=atoi(optarg); + if((cellsize>100)||(cellsize<1)) + {printf("You must have 1<=cellsize<=100.\n"); exit(1);} break; + case 'r': radius=atoi(optarg); + if((radius>3)||(radius<0)) {printf("Radius must be 0,1,2 or 3.\n"); exit(1);} break; + case 'u': sumrule=atoi(optarg); + if((sumrule<0)||(sumrule>1)) {printf("Sum"); exit(1);} break; + } + if (optind!=argc) { fprintf(stderr, + "Usage: %s [-u rulebysums?] [-d delay] [-r radius] [-c numcolors] [-z squaresize] [-s].\n",argv[0]); + exit(1); + } + printf("Running with %d colors, radius %d, rules are%sby sums.\n", + colors, radius,(sumrule?" ":" not ")); +} + +calcnewline(char *from, char *to) +{ +unsigned long ii, cframe = 0; + +for (ii = 0; ii < 2 * radius; ii++) cframe = (cframe << bpc) | from[ii]; +for (ii = 2 * radius; ii < xsize + 2 * radius + 1; ii++) { + cframe = masks[radius] & ((cframe << bpc) | from[ii % xsize]); + to[(ii - radius + phade) % xsize] = rules[cframe]; + offbase[(ii - radius) % xsize] = pixval[colors][rules[cframe]]; + } +} + +makerules() +{ +int ii,jj=0; +unsigned long sum,aa[2*MAXR+2],state; + +for(ii=0;ii<2*radius+1;ii++) aa[ii]=0; +while(aa[2*radius]= colors)) + { + table[ii]=colors-1; + fprintf(stderr,"Error in rule, clipping the values.\n"); + } + } +makerules(); +randomize(); +updatestatus(); +} + +saverule() +{ +int ii; + +if(rulefile = fopen("licarules","a")) + { + fprintf(rulefile,"%d:%d:%d:",colors,radius,sumrule); + for(ii=0;ii=numrules) rulenum=-1; + else dofullrule(filerules[rulenum]);while(getbutton(UPARROWKEY));} +if(getbutton(DOWNARROWKEY)) {rulenum--; if(rulenum<0) rulenum=-1; + else dofullrule(filerules[rulenum]);while(getbutton(DOWNARROWKEY));} +if(getbutton(NKEY)) {newrule();while(getbutton(NKEY));} +if(getbutton(F1KEY)) {for(inx=0;inxMAXCOLORS)colors=MAXCOLORS;} + while(getbutton(CKEY)) ; + } +if(getbutton(RKEY)) { + if(SHIFT){radius--;updatestatus();if(radius<0)radius=0;} + else {radius++;updatestatus();if(radius>MAXR)radius=MAXR;} + while(getbutton(RKEY)) ; + } +if(getbutton(IKEY)) {printf("Rule? ");rulenum=-1;scanf("%s",userrule);dorule(userrule);} +if(getbutton(COMMAKEY)) {slowed++;while(getbutton(COMMAKEY));} +if(getbutton(PERIODKEY)) {slowed--;if(slowed<0)slowed=0;while(getbutton(PERIODKEY));} +if(getbutton(PAD4)) {phade--;while(getbutton(PAD4));} +if(getbutton(PAD5)) phade=0; +if(getbutton(PAD6)) {phade++;while(getbutton(PAD6));} +if(getbutton(F12KEY)) {inx=RND*xsize;offbase[inx] = pixval[colors][line1[inx] + = ((int)(line1[inx]+1+(RND*(colors-1)))%colors)]; while(getbutton(F12KEY));} +if(getbutton(VKEY)) {updatestatus();rulenum=rulenum++;} +while(getbutton(CAPSLOCKKEY)); /*pause*/ +if(getbutton(MOUSE3)) + { + winset(statuswin); + getorigin(&xo,&yo); + choice = (getvaluator(MOUSEX)-xo-5)/25; + entry = TBLSIZ-((getvaluator(MOUSEY)-yo-5)/25)-1; + if((choice>=0)&&(choice=0)) + {table[entry]=choice; makerules(); updatestatus();} + } +} + +square(int sz, int xx, int yy, long cc) +{ +float vv[2]; char phrase[10]; + bgnpolygon(); + cpack(pixval[colors][cc]); + vv[0]=xx; vv[1]=yy; + v2f(vv); vv[0]+=sz; + v2f(vv); vv[1]-=sz; + v2f(vv); vv[0]-=sz; + v2f(vv); + endpolygon(); + if (sz==20) {cpack(0xffffffff); cmov2(xx+8,yy-14); + sprintf(phrase,"%d",cc); charstr(phrase);} +} + +updatestatus() +{ +char phrase[256],name[20]; +int ii,jj,kk; +long xt,yt; + +winset(statuswin); reshapeviewport(); +getsize(&xt,&yt); +if((xt!=MAX(210,colors*25+100)||yt!=75+25*TBLSIZ)) + { + prefsize(MAX(210,colors*25+100),75+25*TBLSIZ); + winconstraints(); + } +viewport(0,MAX(210,colors*25+100),25*TBLSIZ,25*TBLSIZ+75); +cpack(0); clear(); +ortho2(0.,1.,0.,1.); cpack(0xffffffff); +sprintf(phrase,"Radius=%d, %d colors.",radius,colors); +cmov2(.05,.8); charstr(phrase); +sprintf(phrase,"Rules are%sby sums.",sumrule?" ":" not "); +cmov2(.05,.5); charstr(phrase); +for(ii=0;ii=0) sprintf(phrase+ii," (%d/%d)",rulenum+1,numrules); +cmov2(.05,.2); charstr(phrase); + +viewport(0,MAX(210,colors*25+100),0,25*TBLSIZ); +ortho2(0,MAX(210,colors*25+100),0,25*TBLSIZ); +cpack(0); clear(); +for(ii=0;iiMAXX) { + printf("Oops, window too large, increase MAXX.\n"); exit(0);} + drawit(); + calcnewline(line1, line2); + swline = line1; line1 = line2;line2 = swline; + + + + } /* mainloop function */ +} /* end main */ + +#endif + + +/**********************************************************************/ +void idle(void){ /*do this when nothing else is happening*/ + if(morph) autotymer(0); /* advance autotymer */ + glutPostRedisplay(); /*redraw the window*/ + IFCLICK('+',chaptrack(PAW,XX,YY,SHIF);) +} + +/**********************************************************************/ +void mousepushed(int but,int stat,int x,int y){ + if(stat==GLUT_DOWN) PAW |= (1<"); + if(win==2) glutFullScreen(); + glEnable(GL_DEPTH_TEST); + glutDisplayFunc(drawcons); +/* the following 5 aren't needed for a picture */ + glutKeyboardFunc(keyboard); + glutSpecialFunc(special_keybo); + glutMouseFunc(mousepushed); + glutMotionFunc(mousemoved); + glutPassiveMotionFunc(mousemoved); +/* beyond here you do need them */ + glutReshapeFunc(reshaped); + glutIdleFunc(idle); + glutMainLoop(); +} + diff --git a/pulled.txt b/pulled.txt new file mode 100644 index 0000000..ad36ea9 --- /dev/null +++ b/pulled.txt @@ -0,0 +1,354 @@ +//This code is related to opening a new window, should be easy direct port to GLUT + + keepaspect(1,1); + prefposition(300, 1285, 0, 985); + winopen("4-D Tetris"); // make sure you open the window BEFORE initializing + // any data structures. Otherwise, you'll dump core + winconstraints(); // should allow window to be resized + + +//keyboard ready commands not sure how they should port, don't think their needed... + qdevice(PAD1); + qdevice(PAD2); + qdevice(PAD3); + qdevice(PAD4); + qdevice(PAD6); + qdevice(PAD7); + qdevice(PAD8); + qdevice(PAD9); + qdevice(SPACEKEY); + qdevice(F1KEY); + qdevice(F2KEY); + qdevice(F3KEY); + qdevice(F4KEY); + qdevice(F5KEY); + qdevice(F6KEY); + qdevice(F7KEY); + qdevice(F8KEY); + qdevice(F9KEY); + qdevice(F10KEY); + qdevice(F11KEY); + qdevice(F12KEY); + + +//more igl setup command... gconfig is no needed + zbuffer(1); doublebuffer(); RGBmode(); + qdevice(MOUSEX); qdevice(MOUSEY;) + + + +//main processing loop, most should go into keyboard function + while (gameon && !getbutton(ESCKEY)) { + ortho(-5.01, 5.01, -5.01, 5.01, -5.01, 5.01); + + // if there is to be a rotation + if (gameon == 1) + if (getbutton(LEFTALTKEY) || getbutton(RIGHTALTKEY)) { + if (getbutton(PAD6)) { + if (getbutton(PAD8)) { + SOAK(PAD6); + SOAK(PAD8); + dude->Rotate(X, Y, 1); + } else if (getbutton(PAD2)) { + SOAK(PAD6); + SOAK(PAD2); + dude->Rotate(X, Y, -1); + } else if (getbutton(PAD9)) { + SOAK(PAD6); + SOAK(PAD9); + dude->Rotate(X, Z, 1); + } else if (getbutton(PAD1)) { + SOAK(PAD6); + SOAK(PAD1); + dude->Rotate(X, Z, -1); + } else if (getbutton(PAD7)) { + SOAK(PAD6); + SOAK(PAD7); + dude->Rotate(X, W, 1); + } else if (getbutton(PAD3)) { + SOAK(PAD6); + SOAK(PAD3); + dude->Rotate(X, W, -1); + } + } else if (getbutton(PAD4)) { + if (getbutton(PAD8)) { + SOAK(PAD4); + SOAK(PAD8); + dude->Rotate(X, Y, -1); + } else if (getbutton(PAD2)) { + SOAK(PAD4); + SOAK(PAD2); + dude->Rotate(X, Y, 1); + } else if (getbutton(PAD9)) { + SOAK(PAD4); + SOAK(PAD9); + dude->Rotate(X, Z, -1); + } else if (getbutton(PAD1)) { + SOAK(PAD4); + SOAK(PAD1); + dude->Rotate(X, Z, 1); + } else if (getbutton(PAD7)) { + SOAK(PAD4); + SOAK(PAD7); + dude->Rotate(X, W, -1); + } else if (getbutton(PAD3)) { + SOAK(PAD4); + SOAK(PAD3); + dude->Rotate(X, W, 1); + } + } else if (getbutton(PAD8)) { + if (getbutton(PAD9)) { + SOAK(PAD8); + SOAK(PAD9); + dude->Rotate(Y, Z, 1); + } else if (getbutton(PAD1)) { + SOAK(PAD8); + SOAK(PAD1); + dude->Rotate(Y, Z, -1); + } else if (getbutton(PAD7)) { + SOAK(PAD8); + SOAK(PAD7); + dude->Rotate(Y, W, 1); + } else if (getbutton(PAD3)) { + SOAK(PAD8); + SOAK(PAD3); + dude->Rotate(Y, W, -1); + } + } else if (getbutton(PAD2)) { + if (getbutton(PAD9)) { + SOAK(PAD2); + SOAK(PAD9); + dude->Rotate(Y, Z, -1); + } else if (getbutton(PAD1)) { + SOAK(PAD2); + SOAK(PAD1); + dude->Rotate(Y, Z, 1); + } else if (getbutton(PAD7)) { + SOAK(PAD2); + SOAK(PAD7); + dude->Rotate(Y, W, -1); + } else if (getbutton(PAD3)) { + SOAK(PAD2); + SOAK(PAD3); + dude->Rotate(Y, W, 1); + } + } else if (getbutton(PAD9)) { + if (getbutton(PAD7)) { + SOAK(PAD9); + SOAK(PAD7); + dude->Rotate(Z, W, 1); + } else if (getbutton(PAD3)) { + SOAK(PAD9); + SOAK(PAD3); + dude->Rotate(Z, W, -1); + } + } else if (getbutton(PAD1)) { + if (getbutton(PAD7)) { + SOAK(PAD1); + SOAK(PAD7); + dude->Rotate(Z, W, -1); + } else if (getbutton(PAD3)) { + SOAK(PAD1); + SOAK(PAD3); + dude->Rotate(Z, W, 1); + } + } + } // the ALT keys + + // otherwise look for a translation + else if (getbutton(PAD6)) { + SOAK(PAD6); + dude->Translate(X, 1); + } else if (getbutton(PAD4)) { + SOAK(PAD4); + dude->Translate(X, -1); + } else if (getbutton(PAD8)) { + SOAK(PAD8); + dude->Translate(Y, 1); + } else if (getbutton(PAD2)) { + SOAK(PAD2); + dude->Translate(Y, -1); + } else if (getbutton(PAD9)) { + SOAK(PAD9); + dude->Translate(Z, 1); + } else if (getbutton(PAD1)) { + SOAK(PAD1); + dude->Translate(Z, -1); + } else if (getbutton(PAD7)) { + SOAK(PAD7); + dude->Translate(W, 1); + } else if (getbutton(PAD3)) { + SOAK(PAD3); + dude->Translate(W, -1); + } + + + // drop the piece + else if (getbutton(SPACEKEY)) { + SOAK(SPACEKEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = NewPiece(numpieces, mypieces); + } + + // take a look at the different pieces + else if (getbutton(F1KEY)) { + SOAK(F1KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new CubePiece(); + } else if (getbutton(F2KEY)) { + SOAK(F2KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new LPiece(); + } else if (getbutton(F3KEY)) { + SOAK(F3KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new SPiece(); + } else if (getbutton(F4KEY)) { + SOAK(F4KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new StraightPiece(); + } else if (getbutton(F5KEY)) { + SOAK(F5KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TPiece(); + } else if (getbutton(F6KEY)) { + SOAK(F6KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new CornerPiece(); + } else if (getbutton(F7KEY)) { + SOAK(F7KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TwistyPiece(); + } else if (getbutton(F8KEY)) { + SOAK(F8KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new ZPiece(); + } else if (getbutton(F9KEY)) { + SOAK(F9KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new ThreeLinePiece(); + } else if (getbutton(F10KEY)) { + SOAK(F10KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TriPiece(); + } else if (getbutton(F11KEY)) { + SOAK(F11KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new TwoPiece(); + } else if (getbutton(F12KEY)) { + SOAK(F12KEY); + dude->Drop(); + gameon = dude->DonePiece(); + delete dude; + dude = new SimplePiece(); + } + + + +//auto fall stuff... maybe go into idle func? + + if (AUTOFALL && (gameon == 1)) { + gettimeofday(temptime); + if ((temptime->tv_sec > newtime->tv_sec) || + ((temptime->tv_sec == newtime->tv_sec) && + (temptime->tv_usec >= newtime->tv_usec))) { + newtime->tv_sec = temptime->tv_sec + waiting->tv_sec; + newtime->tv_usec = temptime->tv_usec + waiting->tv_usec; + if (!(dude->Translate(W, -1))) { + gameon = dude->DonePiece(); + delete dude; + //dude = new CubePiece(); + dude = NewPiece(numpieces, mypieces); + } + } + } + +//yet more keyboard func stuff + // pause/unpause the game + if (getbutton(MOUSE2)) { + SOAK(MOUSE2); + gameon = -gameon; + } + + if (getbutton(LEFTCTRLKEY) || getbutton(RIGHTCTRLKEY)) + if (getbutton(MOUSE1)) { + SOAK(MOUSE1); + if (ONE_TURN_AT_A_TIME) + for (int i = 0; i < 4; i++) + quad[i]->Deactivate(); + + quad[MyQuad(getvaluator(MOUSEX), getvaluator(MOUSEY))]->Activate(); + + } else if (getbutton(MOUSE3)) { + SOAK(MOUSE3); + for (int i = 0; i < 4; i++) + quad[i]->Deactivate(); + } + + +//reset stuff + cpack(0); clear(); zclear(); + reshapeviewport(); + +//main drawing code... go into display func? + // put the x, y, z axes in the upper right hand corner (quad 1) + pushmatrix(); + translate(2.5, 2.5, 0.0); + quad[1]->Rotate(); + dude->Drawit(7); + board->Drawit(7); + popmatrix(); + + // put the w, x, y axes in the upper left hand corner (quad 0) + pushmatrix(); + translate(-2.5, 2.5, 0.0); + quad[0]->Rotate(); + dude->Drawit(11); + board->Drawit(11); + popmatrix(); + + // put the z, w, x axes in the lower left corner (quad 2) + pushmatrix(); + translate(-2.5, -2.5, 0.0); + quad[2]->Rotate(); + dude->Drawit(13); + board->Drawit(13); + popmatrix(); + + // put the y, z, w axes in the lower right corner (quad 3) + pushmatrix(); + translate(2.5, -2.5, 0.0); + quad[3]->Rotate(); + dude->Drawit(14); + board->Drawit(14); + popmatrix(); + + swapbuffers(); + + + + diff --git a/skel.c b/skel.c new file mode 100644 index 0000000..34cbecd --- /dev/null +++ b/skel.c @@ -0,0 +1,309 @@ +/****************************************************************/ +/**** skel.c = OpenSkelGlut.c = Noosh97 with CAVE removed ****/ +/**** (C) 1994 Board of Trustees University of Illinois ****/ +/**** A Model Real-Time Interactive OpenGL Application ****/ +/**** George Francis, Glenn Chappell, Chris Hartman ****/ +/**** e-mail gfrancis@math.uiuc.edu ****/ +/******* revised 16jan2K by gkf**********************************/ +/****************************************************************/ +#include +#include +#include +#include /* for the speedometer */ +#include +#define MAX(x,y) (((x)<(y))?(y):(x)) +#define MIN(x,y) (((x)<(y))?(x):(y)) +#define ABS(u) ((u)<0 ? -(u): (u)) +#define FOR(a,b,c) for((a)=(b);(a)<(c);(a)++) +#define DOT(p,q) ((p)[0]*(q)[0]+(p)[1]*(q)[1]+(p)[2]*(q)[2]) +#define NRM(p) sqrt(DOT((p),(p))) +#define DG M_PI/180 +#define S(u) sin(u*DG) +#define C(u) cos(u*DG) +#define CLAMP(x,u,v) (xv ? v: x)) +// global variables +float gap, gap0=1.; /* kludge so that arguments() can set a default gap0 */ +float lux[3]={1.,2.,3.}; /*world light direction vector */ +float luxx[3]; /* object space direction vector*/ +float amb, pwr ; /* ambient fraction, pseudo-specular power */ +float mysiz,speed, torq, focal, far; /*console navigation variables */ +int win = 1; /* 2 full screen, use 0 for demand sized */ +unsigned int BUT, XX, YY,SHIF; /* used in chaptrack gluttery */ +int xt,yt; /* once was xt,yt,xm,ym for viewportery */ +int mode,morph,msg; /* pretty global */ +int th0, th1, dth, ta0, ta1, dta; /* torus parameters */ +#define FLYMODE (0) +#define TURNMODE (1) +int ii, jj, kk; float tmp, temp; /* saves gray hairs later */ +float aff[16], starmat[16], mat[16]; +int binoc; /* flag */ +float nose; /* to eye distance in console */ +/**********************************************************************/ +void autotymer(int reset){ /* cheap animations */ +#define TYME(cnt,max,act) {static cnt; if(first)cnt=max; else\ + if(cnt?cnt--:0){ act ; goto Break;}} + static first = 1; /* the first time autymer is called */ + if(reset)first=1; /* or if it is reset to start over */ + TYME( shrink , 150,th0++;th1--;ta0++;ta1--) + TYME( pause , 20, ) + TYME( grow , 150,th0--;th1++;ta0--;ta1++) + TYME( dwell , 30, ) + TYME(finish , 1 , first = 1 ) + first = 0; + Break: ; /* yes Virginia, C has gotos */ +} +/**********************************************************************/ +void deFault(void){ +th0=5; th1=355; ta0=5; ta1=355; gap = gap0; +msg=1; binoc=0; nose=.06; mode=TURNMODE; +speed=.1; torq=.02; focal = 2.; far =13.; mysiz=.01; morph=0; +FOR(ii,0,16) starmat[ii]=aff[ii] = (ii/4==ii%4); /* identities */ +FOR(ii,0,3)lux[ii]/=NRM(lux); amb = .3; pwr = 10. ; +aff[12]=0; aff[13]= 0; aff[14]= -4.2; /* place where we can see it */ +autotymer(1); /* reset autotymer to start at the beginning */ +} +/**********************************************************************/ +void drawvert(int th, int ta){ +float lmb,spec,nn[3], dog, cat; +nn[0] = C(th)*C(ta); /* unit sphere radius vector */ +nn[1] = S(th)*C(ta); +nn[2] = S(ta); +lmb = DOT(nn,luxx);lmb =(lmb<0 ? .2 : lmb); lmb = MAX(amb, lmb); +spec = CLAMP((1.1 - pwr+pwr*lmb), 0., 1.); +dog = (ta-ta0)/(float)(ta1-ta0); cat = (th-th0)/(float)(th1-th0); +glColor3f( + MAX(spec, lmb*dog), /* map R^2(dog,cat)->R^3(RGBspace */ + MAX(spec, lmb*(.25 + ABS(cat -.5))), /* dog cat model of Hartman */ + MAX(spec, lmb*(1 - cat))); /* illiLight by Ray Idaszak 1989 */ +glVertex3f( + C(th) + .5*nn[0], + S(th) + .5*nn[1], + .5*nn[2]); +} /* end drawvert */ +/**********************************************************************/ +void drawtor(void){ +int th, ta; +dth = (int)((th1-th0)/24); /* 24 meridian strips */ +dta = (int)((ta1-ta0)/24); /* 24 triangle pairs per strip */ +for(th=th0; th < th1; th += dth){ + glBegin(GL_TRIANGLE_STRIP); + for(ta=ta0; ta < ta1; ta += dta){ drawvert(th,ta); drawvert(th+gap*dth,ta); } + glEnd(); + } /* end for.theta loop */ +} /* end drawtor */ +/**********************************************************************/ +void drawcube(void){ /* transfer from skel.c as an exercise */ } + +/**********************************************************************/ +void drawall(void){ drawtor(); drawcube();} + +/**********************************************************************/ +void drawstars(void){ + static float star[1000][3]; static int virgin=1; + if(virgin){ /* first time set up the stars */ + FOR(ii,0,1000)FOR(jj,0,3)star[ii][jj]=random()/(float)0x40000000-1.; + virgin=0; /* never again */ + } + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); /* insurance of superstition */ + glMultMatrixf(starmat); + glColor3f(1.0,1.0,0.0); + glBegin(GL_POINTS); + FOR(ii,0,1000)glVertex3fv(star[ii]); + glEnd(); + glPopMatrix(); + glClear(GL_DEPTH_BUFFER_BIT); /* so the stars are behind everything */ +} +/**********************************************************************/ +void arguments(int argc,char **argv){ + extern char *optarg; + extern int optind; + int chi; + /* w: needs ONE number after -w, c means NO number follows*/ + while ((chi = getopt(argc,argv,"w:d:g:")) != -1) + switch(chi) { + case 'w': win=atoi(optarg); break; + case 'g': gap0=atof(optarg); break; + } + if (optind!=argc) fprintf(stderr,"%s: Incorrect usage\n",argv[0]); +} +/**********************************************************************/ +void keyboard(unsigned char key, int x, int y){ +#define IF(K) if(key==K) +#define PRESS(K,A,b) IF(K){b;}IF((K-32)){A;} +/*was backwards in previous versions */ +#define TOGGLE(K,flg) IF(K){(flg) = 1-(flg); } +#define CYCLE(K,f,m) PRESS((K), (f)=(((f)+(m)-1)%(m)),(f)=(++(f)%(m))) +#define SLIDI(K,f,m,M) PRESS(K,(--fM?M:f)) +#define SLIDF(K,f,m,M,d) PRESS(K,((f -= d)M?M:f)) +/* Only ASCII characters can be processes by this GLUT callback function */ + IF(27) { exit(0); } /* ESC exit */ + TOGGLE('v',binoc); /* cross-eyed STEREO */ + CYCLE(' ', mode,TURNMODE+1); /* fly/turn modes */ + TOGGLE('h',morph); /* autotymer on/off */ + TOGGLE('w',msg); /* writing on/off */ + PRESS('n', nose -= .001 , nose += .001 ); /* for binoculars */ + PRESS('s',speed /= 1.02, speed *= 1.02); /* flying speed */ + PRESS('q',torq /= 1.02, torq *= 1.02); /* turning speed */ + PRESS('o', focal *= 1.1 , focal /= 1.1) /* telephoto */ + PRESS('i', mysiz /= 1.1, mysiz *= 1.1) /* rescale the world */ + PRESS('p', far *= 1.01 , far /= 1.01) /* rear clipping plane */ + PRESS('z', deFault(), deFault()); /* zap changes */ + PRESS('g',gap /= .9, gap *= .9); /* gap parameter */ + PRESS('a',amb /= .9, amb *= .9); /* ambient fraction */ + PRESS('r',pwr /= .9, pwr *= .9); /* pseudo-spec power */ +} +/**********************************************************************/ +void special_keybo(int key, int x, int y){ +/*non-ASCII keypresses go here, if you're lucky enough to know their names */ + fprintf(stderr," non-ASCII character was pressed.\n"); + fprintf(stderr," use special_keybo() to process it\n"); +} +/**********************************************************************/ +float speedometer(void){ +double dbl; static double rate; static int ii=0; +static struct timezone notused; static struct timeval now, then; + if(++ii % 8 == 0){ /* 8 times around measure time */ + gettimeofday(&now, ¬used); /* elapsed time */ + dbl = (double)(now.tv_sec - then.tv_sec) + +(double)(now.tv_usec - then.tv_usec)/1000000; + then = now; rate = 8/dbl; + } + return((float)rate); +} +/**********************************************************************/ +void char2wall(float x,float y,float z, char buf[]){ + char *p; glRasterPos3f(x,y,z); + for(p = buf;*p;p++) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,*p); +} +/**********************************************************************/ +void messages(void){ + char buf[256]; /* console messages are done differently from cave */ +#define LABEL2(x,y,W,u) {sprintf(buf,(W),(u));char2wall(x,y,0.,buf);} + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); + gluOrtho2D(0,3000,0,3000); + glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); + /*bull's eye*/ + if(mode==TURNMODE) glColor3f(0x22/255.,0x88/255.,0xdd/255.); + else glColor3f(.8,.8,.8); + LABEL2(1500,1500,"%s","o"); + /* writings */ + if(mode==TURNMODE) glColor3f(1.,0.,1.); + else glColor3f(1.,1.,0.); + LABEL2(80,80,"%4.1f fps",speedometer()); + LABEL2(80,2840,\ + "(ESC)ape (V)Binoc (MAUS2)Fore (BAR)Flymode %s (H)omotopy (W)riting", + mode?"FLYING":"CONTROL"); + LABEL2(10,10,"illiOpenSkelGLUT \ + by Francis, Bourd, Hartman & Chappell, U Illinois, 1995..1997 %s",""); + LABEL2(80,2770,"(N)ose %0.3f",nose); + LABEL2(80,2700,"(S)peed %0.4f",speed); + LABEL2(80,2630," tor(Q) %0.4f",torq); + LABEL2(80,2560,"near clipper %g", mysiz*focal); + LABEL2(80,2490,"f(O)cal factor %g",focal); + LABEL2(80,2420,"my s(I)ze %.2g",mysiz); + LABEL2(80,2350,"far cli(P)er= %.2g",far); + LABEL2(80,2280,"(Z)ap %s",""); + LABEL2(80,2210,"(G)ap %.2g",gap); + LABEL2(80,2140,"(A)mb %.2g",amb); + LABEL2(80,2070,"pw(R) %.2g",pwr); + + glPopMatrix(); +glMatrixMode(GL_PROJECTION); glPopMatrix(); +} +/**********************************************************************/ +void chaptrack(int but,int xx,int yy,int shif){ + long dx,dy; + dx = xx -.5*xt; dx = abs(dx)>5?dx:0; + dy = yy -.5*yt; dy = abs(dy)>5?dy:0; + + glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); + + if(mode==TURNMODE) glTranslatef(aff[12],aff[13],aff[14]); + glRotatef(dx*torq,0.,1.,0.); glRotatef(dy*torq,1.,0.,0.); + if(but&(1<"); + if(win==2) glutFullScreen(); + glEnable(GL_DEPTH_TEST); + glutDisplayFunc(drawcons); + glutKeyboardFunc(keyboard); + glutSpecialFunc(special_keybo); + glutMouseFunc(mousepushed); + glutMotionFunc(mousemoved); + glutPassiveMotionFunc(mousemoved); + glutReshapeFunc(reshaped); + glutIdleFunc(idle); + glutMainLoop(); +} + + diff --git a/slevy.mf b/slevy.mf new file mode 100755 index 0000000..b0e2666 --- /dev/null +++ b/slevy.mf @@ -0,0 +1,52 @@ +OBJS = Main.o\ + Shared.o\ + FourD.o\ + Hyper.o\ + Asserts.o\ + Board.o\ + GenPiece.o\ + CubePiece.o\ + DList.o\ + LPiece.o\ + StraightPiece.o\ + TPiece.o\ + SPiece.o\ + CornerPiece.o\ + TwistyPiece.o\ + ZPiece.o\ + ThreeLinePiece.o\ + TriPiece.o\ + TwoPiece.o\ + SimplePiece.o\ + Rotor.o + +LOCAL = /afs/ncsa/projects/math/local +LIB = o32 +# LIB = o32 +# LOCAL = /usr/local/ +GLINC = -I$(LOCAL)/include +GLUTINC = -I$(LOCAL)/include/GL +CAVEINC = -I/usr/local/CAVE/include + +CAVELIB = -L/usr/local/CAVE/lib -lcave_ogl +GLUTLIB = -L$(LOCAL)/$(LIB) -lglut +GLLIB = -L$(LOCAL)/$(LIB) -lGL -lGLU +SYSLIBS = -L/usr/X11R6/lib -lX11 -lXi -lXext -lXmu -lm + + +# OPT = -DCAVE -O2 +# OPT = -DCAVE -n32 -mips3 +OPT = -DCAVE -o32 + +#CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} -woff 1116,1233,3341 +#CC doesn't understand -woff +CFLAGS = ${OPT} ${CAVEINC} ${GLUTINC} ${GLINC} +LDFLAGS = ${OPT} ${CAVELIB} ${GLUTLIB} ${GLLIB} ${SYSLIBS} + +tetris: $(OBJS) + CC -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) +.C.o: + CC $(CFLAGS) -c $< + + + diff --git a/so_locations b/so_locations new file mode 100644 index 0000000..d98e884 --- /dev/null +++ b/so_locations @@ -0,0 +1,3 @@ +a.out \ + :st = .text 0x5ffe0000, 0x00010000:\ + :st = .data 0x5fff0000, 0x00010000: diff --git a/unknown.txt b/unknown.txt new file mode 100644 index 0000000..6c46c58 --- /dev/null +++ b/unknown.txt @@ -0,0 +1,32 @@ +Unknowns: + +getvaluator(MOUSE) redo for mouse function Rotor.C lines 42 and 43 + +getsize Rotor.C line 46 Main.C 118 +getorigin Rotor.C line 47 Main.C 119 +keepaspect Main.C line 146 +prefposition Main.C line 147 + +winopen Main.C line 148 +winconstraints Main.C line 150 +qdevice Main.c lines 156 to 176 and line 276 no longer needed! +RGBmode Main.C line 275 +reshapeviewport Main.C line 549 - not supported by web page + + +tell mouse callback a temporary variable to use initally, then use + +equivocations: +getmatrix can be glGet(GL_MODELVIEW_MATRIX) or GL_PROJECTION_MATRIX) in Rotor.C line 69 useing GL_MODELVIEW_MATRIX + +doublebuffer - probably enables double buffering, changed to ChoosePixelFormat which might or might not have the desired effect in Main.C line 275 + +swapbuffers to SwapBuffers... needs to specify a device context and so... just converted in conversion... Main.C line 599 + + +NOTES: +gconfig not needed with Open GL, removed call from Main.C line 275 + +probably need to rework the whole keyboard while loop in Main.C + +pause/unpause already implemented??? Main.C line 528 \ No newline at end of file diff --git a/website.txt b/website.txt new file mode 100644 index 0000000..d81ff82 --- /dev/null +++ b/website.txt @@ -0,0 +1 @@ +http://msdn.microsoft.com/library/psdk/opengl/appenda1_3soj.htm