back to the text
/*----------------------------------------------------
*
* OBJECTS.c - object making functions
*
*--------------------------------------------------*/
#include "INCLUDES.h"
#include "vectorsforc07c.h"
#include "vectorsforc12c.h"
#include "cubicvolume.h"
Object GLmakePyr(void);
Object GLobjPyrIndex;
Object GLmakeTriangle(void);
Object GLobjTriangleIndex;
Object GLmakeSqr(void);
Object GLobjSqrIndex;
Object GLmakeCube(void);
Object GLobjCubeIndex;
Object GLmakeCyl(void);
Object GLobjCylIndex;
Object GLmakesculpture(void);
Object GLobjsculptureIndex;
Object GLmakesculpture2(void);
Object GLobjsculpture2Index;
Object GLmakecubicvolume(void);
Object GLobjcubicvolumeIndex;
Object GLmakeSph(void);
Object GLobjSphIndex;
FILE *fd;
wfObject **csoftarray;
wfObject ** init_object(int Argc, char **Argv);
char ** GetArgs(char *filename, int *numArgs);
/*--------------------------------------------------*/
float t0[2] = {0.0, 0.0};
float t1[2] = {1.0, 0.0};
float t2[2] = {1.0, 1.0};
float t3[2] = {0.0, 1.0};
static float v0[3] = { 1.0, 1.0, 0.0} ;/* sqr */
static float v1[3] = { -1.0, 1.0, 0.0} ;
static float v2[3] = { -1.0, -1.0, 0.0} ;
static float v3[3] = { 1.0, -1.0, 0.0} ;
static float v4[3] = { -1.0, 0.0, 1.0} ;/* pyr */
static float v5[3] = { 1.0, 0.0, 1.0} ;
static float v6[3] = { 1.0, 0.0, -1.0} ;
static float v7[3] = { -1.0, 0.0, -1.0} ;
static float v8[3] = { 0.0, 8.0, 0.0} ;
static float v9[3] = { -1.0, 0.0, -1.0} ;/* cube */
static float v10[3] = { 1.0, 0.0, -1.0} ;
static float v11[3] = { 1.0, 1.0, -1.0} ;
static float v12[3] = { -1.0, 1.0, -1.0} ;
static float v13[3] = { -1.0, 0.0, 1.0} ;
static float v14[3] = { 1.0, 0.0, 1.0} ;
static float v15[3] = { 1.0, 1.0, 1.0} ;
static float v16[3] = { -1.0, 1.0, 1.0} ;
static float v17[3] = { -1.0, 0.0, 0.0} ;/* tri */
static float v18[3] = { 1.0, 0.0, 0.0} ;
static float v19[3] = { 0.0, 8.0, 0.0} ;
float lat;/* sphere */
float lon;
float v[3];
float t[2];
int count = 0;
int index = 0;
/*----------------------------------------------------
*
* OBJ from wavefront.obj
*
*--------------------------------------------------*/
wfObject ** init_object(int Argc, char **Argv)
{
wfObject **obj;
int i;
obj = (wfObject**)malloc(Argc*sizeof(wfObject*));
for(i = 0; i < Argc; ++i)
{
if (!(obj[i] = wfReadObject(Argv[i]))) exit(1);
printf("%s\n",Argv[i]);
}
return obj;
}
char ** GetArgs(char *filename, int *numArgs )
{
char **Args;
int num, i;
int dum=0;
fd = fopen( filename ,"r" );
fscanf( fd ,"%d", numArgs);
Args = (char **)malloc(sizeof(char *) * (*numArgs));
for(num = 0; num < (*numArgs); ++num)
{
Args[num] = (char *)malloc(sizeof(char ) * 100);
}
num = 0;
while ( dum=fscanf( fd ,"%s", Args[num]) != EOF)
{
++num;
printf("dum=%d\n", dum);
}
fclose(fd);
for(i = 0; i < num; ++i)
{
printf("%s\n", Args[i]);
}
return Args;
}
/*----------------------------------------------------
*
* SQUARE - with texture coordinates
*
*--------------------------------------------------*/
Object GLmakeSqr(void)
{
makeobj(GLobjSqrIndex = genobj() );
bgnpolygon();
t2f(t0);
v3f(v0);
t2f(t1);
v3f(v1);
t2f(t2);
v3f(v2);
t2f(t3);
v3f(v3);
endpolygon();
closeobj();
return( GLobjSqrIndex );
}
/*----------------------------------------------------
*
* CUBE - without texture coordinates
*
*--------------------------------------------------*/
Object GLmakeCube(void)
{
makeobj(GLobjCubeIndex = genobj() );
bgnpolygon();/* sides */
t2f(t0);
v3f(v10);
t2f(t1);
v3f(v9);
t2f(t2);
v3f(v12);
t2f(t3);
v3f(v11);
endpolygon();
bgnpolygon();
t2f(t0);
v3f(v9);
t2f(t1);
v3f(v13);
t2f(t2);
v3f(v16);
t2f(t3);
v3f(v12);
endpolygon();
bgnpolygon();
t2f(t0);
v3f(v13);
t2f(t1);
v3f(v14);
t2f(t2);
v3f(v15);
t2f(t3);
v3f(v16);
endpolygon();
bgnpolygon();
t2f(t0);
v3f(v14);
t2f(t1);
v3f(v10);
t2f(t2);
v3f(v11);
t2f(t3);
v3f(v15);
endpolygon();
bgnpolygon(); /* top */
t2f(t0);
v3f(v12);
t2f(t1);
v3f(v16);
t2f(t2);
v3f(v15);
t2f(t3);
v3f(v11);
endpolygon();
bgnpolygon();/* bottom */
t2f(t0);
v3f(v9);
t2f(t1);
v3f(v13);
t2f(t2);
v3f(v14);
t2f(t3);
v3f(v10);
endpolygon();
closeobj();
return( GLobjCubeIndex );
}
Object GLmakeTriangle(void)
{
makeobj(GLobjTriangleIndex = genobj() );
bgnpolygon();
t2f(t0);
v3f(v17);
t2f(t1);
v3f(v18);
t2f(t2);
v3f(v19);
t2f(t3);
v3f(v17);
endpolygon();
closeobj();
return( GLobjTriangleIndex );
}
/*----------------------------------------------------
*
* PYRAMID - (4 sides) with texture coordinates
*
*--------------------------------------------------*/
Object GLmakePyr(void)
{
makeobj(GLobjPyrIndex = genobj() );
bgnpolygon(); /* base */
t2f(t0);
v3f(v4);
t2f(t1);
v3f(v5);
t2f(t2);
v3f(v6);
t2f(t3);
v3f(v7);
endpolygon();
bgnpolygon(); /* sides */
t2f(t0);
v3f(v4);
t2f(t1);
v3f(v5);
t2f(t2);
v3f(v8);
t2f(t3);
v3f(v4);
endpolygon();
bgnpolygon();
t2f(t0);
v3f(v5);
t2f(t1);
v3f(v6);
t2f(t2);
v3f(v8);
t2f(t3);
v3f(v5);
endpolygon();
bgnpolygon();
t2f(t0);
v3f(v6);
t2f(t1);
v3f(v7);
t2f(t2);
v3f(v8);
t2f(t3);
v3f(v6);
endpolygon();
bgnpolygon();
t2f(t0);
v3f(v7);
t2f(t1);
v3f(v4);
t2f(t2);
v3f(v8);
t2f(t3);
v3f(v7);
endpolygon();
closeobj();
return( GLobjPyrIndex );
}
/*----------------------------------------------------
*
* CYLINDER - with texture coordinates for SOUP
*
*--------------------------------------------------*/
Object GLmakeCyl(void)
{
makeobj(GLobjCylIndex = genobj() );
double dz = -150;
double theta, dtheta = 2*M_PI/40;
double x, y, z;
float v[3], t[2];
int i, j;
for (i = 0, z = 45; i < 1; i++, z += dz)
{
bgntmesh();
for (j = 0, theta = 0; j <= 40; j++, theta += dtheta)
{
if (j == 40) theta = 0;
x = cos(theta);
y = sin(theta);
t[1] = j/20.0; t[0] = 1;
t2f(t);
v[0] = x*25; v[1] = (y*25)+3; v[2] = z;
v3f(v);
v[2] = z + dz;
t[0] = 0;
t2f(t);
v3f(v);
}
endtmesh();
}
closeobj();
return( GLobjCylIndex );
}
/*----------------------------------------------------
*
* Sculpture Objects - in GALLERY
*
*--------------------------------------------------*/
Object GLmakesculpture(void)
{
makeobj(GLobjsculptureIndex = genobj() );
C7C();
closeobj();
return( GLobjsculptureIndex );
}
Object GLmakesculpture2(void)
{
makeobj(GLobjsculpture2Index = genobj() );
C12C();
closeobj();
return( GLobjsculpture2Index );
}
/*----------------------------------------------------
*
* CUBICVOLUME
*
*--------------------------------------------------*/
Object GLmakecubicvolume(void)
{
makeobj(GLobjcubicvolumeIndex = genobj() );
cubicvolume();
closeobj();
return( GLobjcubicvolumeIndex );
}
/*----------------------------------------------------
*
* SPHERE - with texture coordinates
*
*--------------------------------------------------*/
Object GLmakeSph(void)
{
makeobj(GLobjSphIndex = genobj() );
float lat,lon,v[3],t[2];
int count = 0, index = 0;
for (lat=-M_PI/2; lat<=M_PI/2 - STEP; lat+=STEP)
{
bgntmesh();
++count;
for (lon=0; lon<=2*M_PI + STEP; lon+=STEP)
{
++index;
t[0] = lat/M_PI; t[1] = lon/(2*M_PI);
v[0] = sin(lon)*cos(lat);
v[1] = cos(lon)*cos(lat);
v[2] = sin(lat);
t2f(t);
n3f(v);
v3f(v);
t[0]= (lat + STEP)/M_PI;
v[0] = sin(lon)*cos(lat+STEP);
v[1] = cos(lon)*cos(lat+STEP);
v[2] = sin(lat+STEP);
t2f(t);
n3f(v);
v3f(v);
}
index = 0;
endtmesh();
}
closeobj();
return( GLobjSphIndex );
}
/*--------------------------------------------------*/