}
}
-
-void SetUpMainLight(Light* whichsource, int whichlight, float ambientr, float ambientg, float ambientb)
-{
- static float qattenuation[] = {0.0f};
-
- //Initialize lights
-
- if (whichlight == 0) {
- GLfloat LightAmbient[] = { ambientr, ambientg, ambientb, 1.0f};
- GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
- GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
-
- glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
- glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
- glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
- glEnable(GL_LIGHT0);
- }
-}
}
};
-void SetUpMainLight(Light* whichsource, int whichlight, float ambientr, float ambientg, float ambientb);
void SetUpLight(Light* whichsource, int whichlight);
#endif
return firstintersecting;
}
-int Model::LineCheckSlide(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate)
-{
- static int j;
- static float distance;
- static float olddistance;
- static int intersecting;
- static int firstintersecting;
- static XYZ point;
-
- *p1 = *p1 - *move;
- *p2 = *p2 - *move;
- if (!sphere_line_intersection(p1, p2, &boundingspherecenter, &boundingsphereradius))
- return -1;
- firstintersecting = -1;
- if (*rotate)
- *p1 = DoRotation(*p1, 0, -*rotate, 0);
- if (*rotate)
- *p2 = DoRotation(*p2, 0, -*rotate, 0);
-
- for (j = 0; j < TriangleNum; j++) {
- intersecting = LineFacetd(p1, p2, &vertex[Triangles[j].vertex[0]], &vertex[Triangles[j].vertex[1]], &vertex[Triangles[j].vertex[2]], &facenormals[j], &point);
- distance = (point.x - p1->x) * (point.x - p1->x) + (point.y - p1->y) * (point.y - p1->y) + (point.z - p1->z) * (point.z - p1->z);
- if ((distance < olddistance || firstintersecting == -1) && intersecting) {
- olddistance = distance;
- firstintersecting = j;
- }
- }
-
- distance = abs((facenormals[firstintersecting].x * p2->x) + (facenormals[firstintersecting].y * p2->y) + (facenormals[firstintersecting].z * p2->z) - ((facenormals[firstintersecting].x * vertex[Triangles[firstintersecting].vertex[0]].x) + (facenormals[firstintersecting].y * vertex[Triangles[firstintersecting].vertex[0]].y) + (facenormals[firstintersecting].z * vertex[Triangles[firstintersecting].vertex[0]].z)));
- *p2 -= facenormals[firstintersecting] * distance;
-
- if (*rotate)
- *p2 = DoRotation(*p2, 0, *rotate, 0);
- *p2 = *p2 + *move;
- return firstintersecting;
-}
-
int Model::LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate)
{
static int j;
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- //drawdiffteximmediate(texture);
}
void Model::drawdifftex(Texture texture)
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- //drawdiffteximmediate(texture);
-}
-
-void Model::drawdiffteximmediate(GLuint texture)
-{
- glBindTexture(GL_TEXTURE_2D, (unsigned long)texture);
-
- glBegin(GL_TRIANGLES);
- for (int i = 0; i < TriangleNum; i++) {
- /*if(Triangles[i].vertex[0]<vertexNum&&Triangles[i].vertex[1]<vertexNum&&Triangles[i].vertex[2]<vertexNum&&Triangles[i].vertex[0]>=0&&Triangles[i].vertex[1]>=0&&Triangles[i].vertex[2]>=0){
- if(isnormal(vertex[Triangles[i].vertex[0]].x)&&isnormal(vertex[Triangles[i].vertex[0]].y)&&isnormal(vertex[Triangles[i].vertex[0]].z)
- &&isnormal(vertex[Triangles[i].vertex[1]].x)&&isnormal(vertex[Triangles[i].vertex[1]].y)&&isnormal(vertex[Triangles[i].vertex[1]].z)
- &&isnormal(vertex[Triangles[i].vertex[2]].x)&&isnormal(vertex[Triangles[i].vertex[2]].y)&&isnormal(vertex[Triangles[i].vertex[2]].z)){
- */glTexCoord2f(Triangles[i].gx[0], Triangles[i].gy[0]);
- if (color)
- glColor3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
- if (!color && !flat)
- glNormal3f(normals[Triangles[i].vertex[0]].x, normals[Triangles[i].vertex[0]].y, normals[Triangles[i].vertex[0]].z);
- if (!color && flat)
- glNormal3f(facenormals[i].x, facenormals[i].y, facenormals[i].y);
- glVertex3f(vertex[Triangles[i].vertex[0]].x, vertex[Triangles[i].vertex[0]].y, vertex[Triangles[i].vertex[0]].z);
-
- glTexCoord2f(Triangles[i].gx[1], Triangles[i].gy[1]);
- if (color)
- glColor3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
- if (!color && !flat)
- glNormal3f(normals[Triangles[i].vertex[1]].x, normals[Triangles[i].vertex[1]].y, normals[Triangles[i].vertex[1]].z);
- if (!color && flat)
- glNormal3f(facenormals[i].x, facenormals[i].y, facenormals[i].y);
- glVertex3f(vertex[Triangles[i].vertex[1]].x, vertex[Triangles[i].vertex[1]].y, vertex[Triangles[i].vertex[1]].z);
-
- glTexCoord2f(Triangles[i].gx[2], Triangles[i].gy[2]);
- if (color)
- glColor3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
- if (!color && !flat)
- glNormal3f(normals[Triangles[i].vertex[2]].x, normals[Triangles[i].vertex[2]].y, normals[Triangles[i].vertex[2]].z);
- if (!color && flat)
- glNormal3f(facenormals[i].x, facenormals[i].y, facenormals[i].y);
- glVertex3f(vertex[Triangles[i].vertex[2]].x, vertex[Triangles[i].vertex[2]].y, vertex[Triangles[i].vertex[2]].z);
- //}
- //}
- }
- glEnd();
}
void Model::drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloodtexture2, Texture breaktexture)
int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate);
int SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate);
int LineCheck(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
- int LineCheckSlide(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
int LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
int LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
void UpdateVertexArray();
void drawdifftex(GLuint texture);
void drawdifftex(Texture texture);
void drawimmediate();
- void drawdiffteximmediate(GLuint texture);
void Rotate(float xang, float yang, float zang);
~Model();
void deallocate();
return load_image(fname, tex);
}
-void ScreenShot(const char * fname)
-{
-
-}
-
-
-
static bool load_image(const char *file_name, TGAImageRec &tex)
{
const char *ptr = strrchr((char *)file_name, '.');
//return height1*(1-(pointz-tiley))*scale+height2*(pointz-tiley)*scale;
}
-float Terrain::getHeightExtrude(float pointx, float pointz, float point2x, float point2z)
-{
- static int tilex, tiley;
- static XYZ startpoint, endpoint, intersect, triangle[3], average;
-
- pointx /= scale;
- pointz /= scale;
- point2x /= scale;
- point2z /= scale;
-
- if (pointx >= size - 1 || pointz >= size - 1 || pointx <= 0 || pointz <= 0)
- return 0;
- if (point2x >= size - 1 || point2z >= size - 1 || point2x <= 0 || point2z <= 0)
- return 0;
-
- startpoint.x = point2x;
- startpoint.y = -1000;
- startpoint.z = point2z;
-
- endpoint = startpoint;
- endpoint.y = 1000;
-
- tilex = pointx;
- tiley = pointz;
-
- triangle[0].x = tilex;
- triangle[0].z = tiley;
- triangle[0].y = heightmap[tilex][tiley];
-
- triangle[1].x = tilex + 1;
- triangle[1].z = tiley;
- triangle[1].y = heightmap[tilex + 1][tiley];
-
- triangle[2].x = tilex;
- triangle[2].z = tiley + 1;
- triangle[2].y = heightmap[tilex][tiley + 1];
-
- XYZ mid;
-
- mid = (triangle[0] + triangle[1] + triangle[2]) / 2;
-
- triangle[0] = mid + (triangle[0] - mid) * 10;
- triangle[1] = mid + (triangle[0] - mid) * 10;
- triangle[2] = mid + (triangle[0] - mid) * 10;
-
- /*
- if(!LineFacetd(&startpoint,&endpoint,&triangle[0],&triangle[1],&triangle[2],&intersect)){
- triangle[0].x=tilex+1;
- triangle[0].z=tiley;
- triangle[0].y=heightmap[tilex+1][tiley];
-
- triangle[1].x=tilex+1;
- triangle[1].z=tiley+1;
- triangle[1].y=heightmap[tilex+1][tiley+1];
-
- triangle[2].x=tilex;
- triangle[2].z=tiley+1;
- triangle[2].y=heightmap[tilex][tiley+1];
- LineFacetd(&startpoint,&endpoint,&triangle[0],&triangle[1],&triangle[2],&intersect);
- }*/
- return intersect.y * scale + getOpacity(pointx * scale, pointz * scale) / 8;
-
- //height1=heightmap[tilex][tiley]*(1-(pointx-tilex))+heightmap[tilex+1][tiley]*(pointx-tilex);
- //height2=heightmap[tilex][tiley+1]*(1-(pointx-tilex))+heightmap[tilex+1][tiley+1]*(pointx-tilex);
-
- //return height1*(1-(pointz-tiley))*scale+height2*(pointz-tiley)*scale;
-}
-
-
float Terrain::getOpacity(float pointx, float pointz)
{
static float height1, height2;
}
}
-void Terrain::DoLighting()
-{
- static int i, j, k, todivide;
- static float brightness, total;
- static XYZ blank, terrainpoint, lightloc;
- lightloc = light.location;
- Normalise(&lightloc);
- //Calculate shadows
- for (i = 0; i < size; i++) {
- for (j = 0; j < size; j++) {
- terrainpoint.x = (float)i * scale;
- terrainpoint.z = (float)j * scale;
- terrainpoint.y = heightmap[i][j] * scale + .1;
- /*brightness=0;
- if(lineTerrain(lightlocation*10+terrainpoint,terrainpoint,&blank)==-1)
- */
- brightness = dotproduct(&lightloc, &normals[i][j]);
-
- if (brightness > 1)
- brightness = 1;
- if (brightness < 0)
- brightness = 0;
-
- colors[i][j][0] = light.color[0] * brightness + light.ambient[0];
- colors[i][j][1] = light.color[1] * brightness + light.ambient[1];
- colors[i][j][2] = light.color[2] * brightness + light.ambient[2];
-
- if (colors[i][j][0] > 1) colors[i][j][0] = 1;
- if (colors[i][j][1] > 1) colors[i][j][1] = 1;
- if (colors[i][j][2] > 1) colors[i][j][2] = 1;
- if (colors[i][j][0] < 0) colors[i][j][0] = 0;
- if (colors[i][j][1] < 0) colors[i][j][1] = 0;
- if (colors[i][j][2] < 0) colors[i][j][2] = 0;
- }
- }
-
- //Smooth shadows
- for (i = 0; i < size; i++) {
- for (j = 0; j < size; j++) {
- for (k = 0; k < 3; k++) {
- total = 0;
- todivide = 0;
- if (i != 0) {
- total += colors[j][i - 1][k];
- todivide++;
- }
- if (i != size - 1) {
- total += colors[j][i + 1][k];
- todivide++;
- }
- if (j != 0) {
- total += colors[j - 1][i][k];
- todivide++;
- }
- if (j != size - 1) {
- total += colors[j + 1][i][k];
- todivide++;
- }
- if (i != 0 && j != 0) {
- total += colors[j - 1][i - 1][k];
- todivide++;
- }
- if (i != size - 1 && j != 0) {
- total += colors[j - 1][i + 1][k];
- todivide++;
- }
- if (j != size - 1 && i != size - 1) {
- total += colors[j + 1][i + 1][k];
- todivide++;
- }
- if (j != size - 1 && i != 0) {
- total += colors[j + 1][i - 1][k];
- todivide++;
- }
- total += colors[j][i][k];
- todivide++;
-
- colors[j][i][k] = total / todivide;
- }
- }
- }
-}
-
void Terrain::DoShadows()
{
static int i, j, k, l, todivide;
void MakeDecalLock(int type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation);
int lineTerrain(XYZ p1, XYZ p2, XYZ *p);
float getHeight(float pointx, float pointz);
- float getHeightExtrude(float pointx, float pointz, float point2x, float point2z);
float getOpacity(float pointx, float pointz);
XYZ getLighting(float pointx, float pointz);
XYZ getNormal(float pointx, float pointz);
void drawpatch(int whichx, int whichy, float opacity);
void drawpatchother(int whichx, int whichy, float opacity);
void drawpatchotherother(int whichx, int whichy, float opacity);
- void DoLighting();
void DoShadows();
Terrain();
return true;
}
-AL_API void OPENAL_Stream_Close(OPENAL_STREAM *stream)
-{
- OPENAL_Sample_Free((OPENAL_SAMPLE *) stream);
-}
-
static OPENAL_SAMPLE *OPENAL_Stream_GetSample(OPENAL_STREAM *stream)
{
if (!initialized)
AL_API signed char OPENAL_SetPaused(int channel, signed char paused);
AL_API void OPENAL_SetSFXMasterVolume(int volume);
AL_API signed char OPENAL_StopSound(int channel);
- AL_API void OPENAL_Stream_Close(OPENAL_STREAM *stream);
AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM *stream, unsigned int mode);
AL_API void OPENAL_Update();
AL_API signed char OPENAL_SetOutput(int outputtype);