Menu

[r1]: / trunk / browser3d.h  Maximize  Restore  History

Download this file

171 lines (142 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* browser3d.h (Visit http://browser3d.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (file COPYRIGHT); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef __WIN32
#include <GL/openglut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <expat.h>
#include <string.h>
#include <math.h>
#ifndef _BROWSER3D_H_INCLUDED
#define _BROWSER3D_H_INCLUDED
#ifdef __WIN32
#define usleep(time) Sleep(time/1000)
#else
#define __glutSolidCylinder
#endif
/* const char* version="0.2a"; */
#define BROWSER3D_VERSION "0.2a"
#define BROWSER3D_NAME "Browser3D"
#define BROWSER3D_USERAGENT "Browser3D 0.2a"
#define MAX_LINE_LENGTH 1024
//#include "browser3d_network.h"
enum object3d_type {CUBE, SPHERE, CONE, TORUS, DODECAHEDRON, OCTAHEDRON, TETRAHEDRON, ICOSAHEDRON, TEAPOT, RHOMBICDODECAHEDRON, SIERPINSKISPONGE, CYLINDER, PLANE, A3D, LABEL3D};
typedef enum object3d_type object_type;
struct object3d
{
object_type type;
GLfloat x,y,z;
GLfloat scalex,scaley,scalez;
GLfloat rotatex,rotatey,rotatez;
GLfloat red,green,blue;
char* data;
unsigned char collision;
} static object[255];
struct s_vector
{
float x,y,z;
};
typedef struct s_vector vector;
static int num_objects=0;
//// TEXTURES
// Storage for one texture
static GLuint texture[1];
// Image type - contains height, width, and data
struct Image
{
unsigned long sizeX;
unsigned long sizeY;
char *data;
};
typedef struct Image Image;
//// END TEXTURES
/* planes for texture coordinate generation */
static GLfloat xequalzero[] = {1.0, 0.0, 0.0, 0.0};
static GLfloat slanted[] = {1.0, 1.0, 1.0, 0.0};
static GLfloat *currentCoeff;
static GLenum currentPlane;
static GLint currentGenMode;
static GLuint texName;
//values for lighting
static GLfloat AmbientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
static GLfloat DiffuseLight[] = { 0.8f, 0.8f, 0.8f, 1.0f };
static GLfloat SpecularLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
static GLfloat SpecRef[] = { 0.7f, 0.7f, 0.7f, 1.0f };
static GLfloat LightPos[] = {-50.0f,50.0f,100.0f,1.0f};
static GLubyte Shine = 128;
//camera position
#define XCAM_INI 0.0
#define YCAM_INI 0.0
#define ZCAM_INI 0.0
#define SXCAM_INI 0.0
#define SYCAM_INI 0.0
#define SZCAM_INI 1.0
#define UPXCAM_INI 0.0
#define UPYCAM_INI 1.0
#define UPZCAM_INI 0.0
static GLfloat xCam = XCAM_INI,yCam=YCAM_INI,zCam = ZCAM_INI,sxCam=SXCAM_INI,syCam=SYCAM_INI,szCam=SZCAM_INI,upxCam=UPXCAM_INI,upyCam=UPYCAM_INI,upzCam=UPZCAM_INI;
//mouse position
static int xMouse = 0, yMouse = 0;
void rotateCamera(GLfloat xRotate,GLfloat yRotate,GLfloat zrotate);
int ImageLoad(char *, Image *);
void LoadGLTextures(void);
void initialize3DObject(GLfloat x,GLfloat y,GLfloat z, GLfloat width, GLfloat height, GLfloat depth,GLfloat xRotate,GLfloat yRotate,GLfloat zRotate,GLfloat red,GLfloat green,GLfloat blue);
void draw_object(int num);
void initialize3DObject(GLfloat x,GLfloat y,GLfloat z, GLfloat width, GLfloat height, GLfloat depth,GLfloat xRotate,GLfloat yRotate,GLfloat zRotate,GLfloat red,GLfloat green,GLfloat blue);
void draw_object(int num);
void cube(GLfloat x,GLfloat y,GLfloat z, GLfloat width, GLfloat height, GLfloat depth,GLfloat xRotate,GLfloat yRotate,GLfloat zRotate,GLfloat red,GLfloat green,GLfloat blue);
void sphere(GLfloat x,GLfloat y,GLfloat z, GLfloat width, GLfloat height, GLfloat depth,GLfloat xRotate,GLfloat yRotate,GLfloat zRotate,GLfloat red,GLfloat green,GLfloat blue);
void draw_object_type(struct object3d* o3d);
void initialize_3D_object(struct object3d* o3d);
void init(void);
void display(void);
void reshape (int w, int h);
void keyboard (unsigned char key, int x, int y);
void idle();
void menu1(int id);
void menu2(int id);
void draw_object(int num);
void parse_attributes(const char **attr);
void create_primitive(object_type type,const char **atts);
static void startElement(void *userdata, const char *name, const char **atts);
static void endElement(void *userData, const char *name);
int main(int argc, char** argv);
void initialize_world();
void load_url(char* url);
int collision(vector* v);
void move_forward();
void move_backward();
void change_move_mode();
int winIdMain, winIdSub;
#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
void subDisplay(void);
void subReshape(int w, int h);
void drawString (char *s);
void drawStringBig (char *s);
static char label[100] = "";
static char label2[100] = "";
char *new_url;
char n_url[255];
char current_url[255];
#define MOVE_3D 0
#define MOVE_2D 1
static unsigned int move_mode = MOVE_3D;
#endif