1 /* 2 * inc3d.h 3 * by Jon Kinsey, 2003 4 * 5 * General definitions for 3d board 6 * 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of version 3 or later of the GNU General Public License as 10 * published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 * $Id: inc3d.h,v 1.58 2018/04/28 21:40:58 plm Exp $ 22 */ 23 #ifndef INC3D_H 24 #define INC3D_H 25 26 #include <math.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 #if HAVE_UNISTD_H 31 #include <unistd.h> 32 #endif 33 34 #include <gtk/gtk.h> 35 36 #if defined(WIN32) 37 /* MS gl.h needs windows.h to be included first */ 38 #include <winsock2.h> 39 #include <windows.h> 40 #endif 41 42 #if defined(USE_APPLE_OPENGL) 43 #include <gl.h> 44 #include <glu.h> 45 #else 46 #include <GL/gl.h> 47 #include <GL/glu.h> 48 #endif 49 50 #if defined(HAVE_GL_GLX_H) 51 #include <GL/glx.h> /* x-windows file */ 52 #endif 53 54 #include <gtk/gtkgl.h> 55 #include "fun3d.h" 56 #include "matrix.h" 57 #include "gtkwindows.h" 58 59 #include "model.h" 60 #include "drawboard.h" /* for fClockwise decl */ 61 62 /* Clipping planes */ 63 #define zNear .1 64 #define zFar 70.0 65 66 extern int numRestrictFrames; 67 extern int renderingBase; 68 69 extern gboolean gtk_gl_init_success; 70 71 typedef enum _BoardState { 72 BOARD_CLOSED, BOARD_CLOSING, BOARD_OPENING, BOARD_OPEN 73 } BoardState; 74 75 /* Font info */ 76 77 #define FONT_PITCH 24 78 #define FONT_SIZE (base_unit / 20.0f) 79 #define FONT_HEIGHT_RATIO 1.f 80 81 #define CUBE_FONT_PITCH 34 82 #define CUBE_FONT_SIZE (base_unit / 24.0f) 83 #define CUBE_FONT_HEIGHT_RATIO 1.25f 84 85 #define FONT_VERA "fonts/Vera.ttf" 86 #define FONT_VERA_SERIF_BOLD "fonts/VeraSeBd.ttf" 87 88 /* Animation paths */ 89 #define MAX_PATHS 3 90 typedef enum _PathType { 91 PATH_LINE, PATH_CURVE_9TO12, PATH_CURVE_12TO3, PATH_PARABOLA, PATH_PARABOLA_12TO3 92 } PathType; 93 94 struct _Path { 95 float pts[MAX_PATHS + 1][3]; 96 PathType pathType[MAX_PATHS]; 97 int state; 98 float mileStone; 99 int numSegments; 100 }; 101 102 enum OcculderType { OCC_BOARD, OCC_CUBE, OCC_DICE1, OCC_DICE2, OCC_FLAG, OCC_HINGE1, OCC_HINGE2, OCC_PIECE }; 103 #define FIRST_PIECE (int)OCC_PIECE 104 #define LAST_PIECE ((int)OCC_PIECE + 29) 105 #define NUM_OCC (LAST_PIECE + 1) 106 107 struct _Texture { 108 unsigned int texID; 109 int width; 110 int height; 111 }; 112 113 #define FILENAME_SIZE 15 114 #define NAME_SIZE 20 115 116 struct _TextureInfo { 117 char file[FILENAME_SIZE + 1]; 118 char name[NAME_SIZE + 1]; 119 TextureType type; 120 }; 121 122 struct _BoardData3d { 123 GtkWidget *drawing_area3d; /* main 3d widget */ 124 125 /* Bit of a hack - assign each possible position a set rotation */ 126 int pieceRotation[28][15]; 127 int movingPieceRotation; 128 129 /* Misc 3d objects */ 130 Material gapColour; 131 Material logoMat; 132 Material flagMat, flagNumberMat; 133 134 /* Store how "big" the screen maps to in 3d */ 135 float backGroundPos[2], backGroundSize[2]; 136 137 BoardState State; /* Open/closed board */ 138 float perOpen; /* Percentage open when opening/closing board */ 139 140 int moving; /* Is a piece moving (animating) */ 141 Path piecePath; /* Animation path for moving pieces */ 142 float rotateMovingPiece; /* Piece going home? */ 143 int shakingDice; /* Are dice being animated */ 144 Path dicePaths[2]; /* Dice shaking paths */ 145 146 /* Some positions of dice, moving/dragging pieces */ 147 float movingPos[3]; 148 float dragPos[3]; 149 float dicePos[2][3]; 150 float diceMovingPos[2][3]; 151 DiceRotation diceRotation[2]; 152 153 float flagWaved; /* How much has flag waved */ 154 155 OGLFont *numberFont, *cubeFont; /* OpenGL fonts */ 156 157 /* Saved viewing values (used for picking) */ 158 double vertFrustrum, horFrustrum; 159 float modelMatrix[16]; 160 161 /* Display list ids and quadratics */ 162 GLuint diceList, DCList, pieceList, piecePickList; 163 GLUquadricObj *qobjTex, *qobj; 164 165 /* Shadow casters */ 166 Occluder Occluders[NUM_OCC]; 167 float shadow_light_position[4]; 168 int shadowsInitialised; 169 int fBasePreRendered; 170 int fBuffers; 171 int shadowsOutofDate; 172 173 float ***boardPoints; /* Used for rounded corners */ 174 #ifdef WIN32 175 HANDLE wglBuffer; 176 #endif 177 178 /* Textures */ 179 #define MAX_TEXTURES 10 180 Texture textureList[MAX_TEXTURES]; 181 char *textureName[MAX_TEXTURES]; 182 int numTextures; 183 unsigned int dotTexture; /* Holds texture used to draw dots on dice */ 184 }; 185 186 struct _Flag3d { 187 /* Define nurbs surface - for flag */ 188 GLUnurbsObj *flagNurb; 189 #define S_NUMPOINTS 4 190 #define S_NUMKNOTS (S_NUMPOINTS * 2) 191 #define T_NUMPOINTS 2 192 #define T_NUMKNOTS (T_NUMPOINTS * 2) 193 /* Control points for the flag. The Z values are modified to make it wave */ 194 float ctlpoints[S_NUMPOINTS][T_NUMPOINTS][3]; 195 }; 196 197 extern struct _Flag3d flag; 198 199 /* Define relative sizes of objects from arbitrary unit .05 */ 200 #define base_unit .05f 201 202 /* Piece/point size */ 203 #define PIECE_HOLE (base_unit * 3.0f) 204 #define PIECE_DEPTH base_unit 205 206 /* Scale textures by this amount */ 207 #define TEXTURE_SCALE (10.0f / base_unit) 208 209 #define copyPoint(to, from) memcpy(to, from, sizeof(float[3])) 210 211 #define TEXTURE_PATH "textures/" 212 #define NO_TEXTURE_STRING _("No texture") 213 214 #define HINGE_SEGMENTS 6.f 215 216 #define CUBE_TWODIGIT_FACTOR .9f 217 218 /* Draw board parts (boxes) specially */ 219 enum { /*boxType */ BOX_ALL = 0, BOX_NOSIDES = 1, BOX_NOENDS = 2, BOX_SPLITTOP = 4, BOX_SPLITWIDTH = 8 }; 220 221 struct _ClipBox { 222 float x; 223 float y; 224 float xx; 225 float yy; 226 }; 227 /* functions used in test harness (static in gnubg) */ 228 #ifndef TEST_HARNESS 229 #define NTH_STATIC static 230 #else 231 #define NTH_STATIC extern 232 extern void TestHarnessDraw(const BoardData * bd); 233 #endif 234 235 /* Some 3d functions */ 236 extern float getDiceSize(const renderdata * prd); 237 extern void SetupFlag(void); 238 extern void setupDicePaths(const BoardData * bd, Path dicePaths[2], float diceMovingPos[2][3], 239 DiceRotation diceRotation[2]); 240 extern void waveFlag(float wag); 241 extern GdkGLConfig *getGlConfig(void); 242 243 /* Helper functions in misc3d */ 244 void cylinder(float radius, float height, unsigned int accuracy, const Texture * texture); 245 void circle(float radius, float height, unsigned int accuracy); 246 void circleRev(float radius, float height, unsigned int accuracy); 247 void circleTex(float radius, float height, unsigned int accuracy, const Texture * texture); 248 void circleRevTex(float radius, float height, unsigned int accuracy, const Texture * texture); 249 void circleOutlineOutward(float radius, float height, unsigned int accuracy); 250 void circleOutline(float radius, float height, unsigned int accuracy); 251 void circleSloped(float radius, float startHeight, float endHeight, unsigned int accuracy); 252 void drawBox(int type, float x, float y, float z, float w, float h, float d, const Texture * texture); 253 void drawCube(float size); 254 void drawRect(float x, float y, float z, float w, float h, const Texture * texture); 255 void drawSplitRect(float x, float y, float z, float w, float h, const Texture * texture); 256 void drawChequeredRect(float x, float y, float z, float w, float h, int across, int down, const Texture * texture); 257 void QuarterCylinder(float radius, float len, unsigned int accuracy, const Texture * texture); 258 void QuarterCylinderSplayed(float radius, float len, unsigned int accuracy, const Texture * texture); 259 void QuarterCylinderSplayedRev(float radius, float len, unsigned int accuracy, const Texture * texture); 260 void drawCornerEigth(float **const *boardPoints, float radius, unsigned int accuracy); 261 void calculateEigthPoints(float ****boardPoints, float radius, unsigned int accuracy); 262 void drawBoardTop(const BoardData * bd, const BoardData3d * bd3d, const renderdata * prd); 263 #ifdef WIN32 264 void drawBasePreRender(const BoardData * bd, const BoardData3d * bd3d, const renderdata * prd); 265 #endif 266 267 /* Other functions */ 268 void initPath(Path * p, const float start[3]); 269 void addPathSegment(Path * p, PathType type, const float point[3]); 270 void initDT(diceTest * dt, int x, int y, int z); 271 272 #endif 273