X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FObjects.cpp;h=6f98ead6d536f158581f024dd1d652e439708c07;hb=794f89c25569a9bf50f167689ca0faa3dcffc577;hp=df5f1bcabb58561c6622b3eab9db1e18dbabfd90;hpb=24004d6ab1e68faaf85ece11b566449997da5013;p=lugaru.git diff --git a/Source/Objects.cpp b/Source/Objects.cpp index df5f1bc..6f98ead 100644 --- a/Source/Objects.cpp +++ b/Source/Objects.cpp @@ -1,22 +1,21 @@ /* Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. -Lugaru 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; either version 2 -of the License, or (at your option) any later version. +Lugaru 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; either version 2 of the License, or +(at your option) any later version. -This program is distributed in the hope that it will be useful, +Lugaru 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. +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; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +along with Lugaru. If not, see . */ #include "Objects.h" @@ -39,7 +38,7 @@ extern bool skyboxtexture; //Functions -bool Objects::checkcollide(XYZ startpoint, XYZ endpoint, int which) +bool Objects::checkcollide(XYZ startpoint, XYZ endpoint, int which) { static XYZ colpoint, colviewer, coltarget; static int i; @@ -53,7 +52,8 @@ bool Objects::checkcollide(XYZ startpoint, XYZ endpoint, int which) if (type[i] != treeleavestype && type[i] != treetrunktype && type[i] != bushtype && type[i] != firetype && i != which) { colviewer = startpoint; coltarget = endpoint; - if (model[i].LineCheck(&colviewer, &coltarget, &colpoint, &position[i], &yaw[i]) != -1)return 1; + if (model[i].LineCheck(&colviewer, &coltarget, &colpoint, &position[i], &yaw[i]) != -1) + return 1; } } @@ -83,7 +83,7 @@ void Objects::SphereCheckPossible(XYZ *p1, float radius) void Objects::Draw() { static float distance; - static int i, j; + static int i; static XYZ moved, terrainlight; bool hidden; @@ -96,46 +96,51 @@ void Objects::Draw() hidden = !(distsqflat(&viewer, &position[i]) > playerdist + 3 || (type[i] != bushtype && type[i] != treeleavestype)); if (!hidden) { - if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness ); - else glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment) + glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness ); + else + glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance; - if (distance > 1)distance = 1; + if (distance > 1) + distance = 1; if (distance > 0) { - /*if(checkcollide(viewer,DoRotation(model[i].vertex[model[i].vertexNum],0,yaw[i],0)*scale[i]+position[i],i)){ - occluded[i]+=1; - } - else occluded[i]=0;*/ if (occluded[i] < 6) { - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix + glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (!model[i].color)glEnable(GL_LIGHTING); - else glDisable(GL_LIGHTING); + if (!model[i].color) + glEnable(GL_LIGHTING); + else + glDisable(GL_LIGHTING); glDepthMask(1); glTranslatef(position[i].x, position[i].y, position[i].z); if (type[i] == bushtype) { messedwith[i] -= multiplier; if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0)rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0)rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0)rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0)rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4)rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4)rotxvel[i] = 0; + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; rotx[i] += rotxvel[i] * multiplier * 4; } if (rotyvel[i] || roty[i]) { - if (roty[i] > 0)rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0)rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0)rotyvel[i] -= multiplier * 4; - if (roty[i] < 0)rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0)rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0)rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4)roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4)rotyvel[i] = 0; + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; roty[i] += rotyvel[i] * multiplier * 4; } @@ -145,35 +150,43 @@ void Objects::Draw() if (rotx[i]) { glRotatef(-rotx[i], 0, 0, 1); } - if (rotx[i] > 10)rotx[i] = 10; - if (rotx[i] < -10)rotx[i] = -10; - if (roty[i] > 10)roty[i] = 10; - if (roty[i] < -10)roty[i] = -10; + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; } if (type[i] == treetrunktype || type[i] == treeleavestype) { - if (type[i] == treetrunktype || environment == 2) { + if (type[i] == treetrunktype || environment == desertenvironment) { messedwith[i] -= multiplier; if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0)rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0)rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0)rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0)rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4)rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4)rotxvel[i] = 0; + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; rotx[i] += rotxvel[i] * multiplier * 4; } if (rotyvel[i] || roty[i]) { - if (roty[i] > 0)rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0)rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0)rotyvel[i] -= multiplier * 4; - if (roty[i] < 0)rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0)rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0)rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4)roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4)rotyvel[i] = 0; + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; roty[i] += rotyvel[i] * multiplier * 4; } @@ -183,33 +196,41 @@ void Objects::Draw() if (rotx[i]) { glRotatef(-rotx[i] / 6, 0, 0, 1); } - if (rotx[i] > 10)rotx[i] = 10; - if (rotx[i] < -10)rotx[i] = -10; - if (roty[i] > 10)roty[i] = 10; - if (roty[i] < -10)roty[i] = -10; + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; } else { messedwith[i] -= multiplier; if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0)rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0)rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0)rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0)rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4)rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4)rotxvel[i] = 0; + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; rotx[i] += rotxvel[i] * multiplier * 4; } if (rotyvel[i] || roty[i]) { - if (roty[i] > 0)rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0)rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0)rotyvel[i] -= multiplier * 4; - if (roty[i] < 0)rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0)rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0)rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4)roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4)rotyvel[i] = 0; + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; roty[i] += rotyvel[i] * multiplier * 4; } @@ -219,10 +240,14 @@ void Objects::Draw() if (rotx[i]) { glRotatef(-rotx[i] / 4, 0, 0, 1); } - if (rotx[i] > 10)rotx[i] = 10; - if (rotx[i] < -10)rotx[i] = -10; - if (roty[i] > 10)roty[i] = 10; - if (roty[i] < -10)roty[i] = -10; + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; } } @@ -254,7 +279,8 @@ void Objects::Draw() } } glRotatef(yaw[i], 0, 1, 0); - if (distance > 1)distance = 1; + if (distance > 1) + distance = 1; glColor4f((1 - shadowed[i]) / 2 + .5, (1 - shadowed[i]) / 2 + .5, (1 - shadowed[i]) / 2 + .5, distance); if (distance >= 1) { glDisable(GL_BLEND); @@ -283,7 +309,8 @@ void Objects::Draw() terrainlight = terrain.getLighting(position[i].x, position[i].z); if (!hidden) { glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance); - if (distance < 1)glAlphaFunc(GL_GREATER, 0.2); + if (distance < 1) + glAlphaFunc(GL_GREATER, 0.2); } if (hidden) { glDepthMask(0); @@ -299,7 +326,8 @@ void Objects::Draw() terrainlight = terrain.getLighting(position[i].x, position[i].z); if (!hidden) { glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance); - if (distance < 1)glAlphaFunc(GL_GREATER, 0.2); + if (distance < 1) + glAlphaFunc(GL_GREATER, 0.2); } if (hidden) { glDepthMask(0); @@ -331,141 +359,154 @@ void Objects::Draw() hidden = distsqflat(&viewer, &position[i]) <= playerdist + 3; if (hidden) { distance = 1; - if (distance > 0) { - if (1 == 1 || occluded[i] < 6) { - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glPushMatrix(); - glEnable(GL_LIGHTING); - glDepthMask(1); - glTranslatef(position[i].x, position[i].y, position[i].z); - if (type[i] == bushtype) { - messedwith[i] -= multiplier; - if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0)rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0)rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0)rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0)rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4)rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4)rotxvel[i] = 0; - - rotx[i] += rotxvel[i] * multiplier * 4; - } - if (rotyvel[i] || roty[i]) { - if (roty[i] > 0)rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0)rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0)rotyvel[i] -= multiplier * 4; - if (roty[i] < 0)rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0)rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0)rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4)roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4)rotyvel[i] = 0; - - roty[i] += rotyvel[i] * multiplier * 4; - } - if (roty[i]) { - glRotatef(roty[i], 1, 0, 0); - } - if (rotx[i]) { - glRotatef(-rotx[i], 0, 0, 1); - } - if (rotx[i] > 10)rotx[i] = 10; - if (rotx[i] < -10)rotx[i] = -10; - if (roty[i] > 10)roty[i] = 10; - if (roty[i] < -10)roty[i] = -10; - } - if (type[i] == treetrunktype || type[i] == treeleavestype) { - messedwith[i] -= multiplier; - if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0)rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0)rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0)rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0)rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0)rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4)rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4)rotxvel[i] = 0; - - rotx[i] += rotxvel[i] * multiplier * 4; - } - if (rotyvel[i] || roty[i]) { - if (roty[i] > 0)rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0)rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0)rotyvel[i] -= multiplier * 4; - if (roty[i] < 0)rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0)rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0)rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4)roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4)rotyvel[i] = 0; - - roty[i] += rotyvel[i] * multiplier * 4; - } - if (roty[i]) { - glRotatef(roty[i] / 2, 1, 0, 0); - } - if (rotx[i]) { - glRotatef(-rotx[i] / 2, 0, 0, 1); - } - if (rotx[i] > 10)rotx[i] = 10; - if (rotx[i] < -10)rotx[i] = -10; - if (roty[i] > 10)roty[i] = 10; - if (roty[i] < -10)roty[i] = -10; - } - if (environment == snowyenvironment) { - if (type[i] == treeleavestype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == treetrunktype) { - glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == bushtype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - } - if (environment == grassyenvironment) { - if (type[i] == treeleavestype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == treetrunktype) { - glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == bushtype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - } - glRotatef(yaw[i], 0, 1, 0); - glColor4f(1, 1, 1, distance); - if (type[i] == treeleavestype) { - glDisable(GL_CULL_FACE); - glDisable(GL_LIGHTING); - terrainlight = terrain.getLighting(position[i].x, position[i].z); - glDepthMask(0); - glEnable(GL_BLEND); - glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); - glAlphaFunc(GL_GREATER, 0); - glDisable(GL_ALPHA_TEST); - model[i].drawdifftex(treetextureptr); - } - if (type[i] == bushtype) { - glDisable(GL_CULL_FACE); - glDisable(GL_LIGHTING); - terrainlight = terrain.getLighting(position[i].x, position[i].z); - glDepthMask(0); - glEnable(GL_BLEND); - glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); - glAlphaFunc(GL_GREATER, 0); - glDisable(GL_ALPHA_TEST); - model[i].drawdifftex(bushtextureptr); - } - glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glEnable(GL_LIGHTING); + glDepthMask(1); + glTranslatef(position[i].x, position[i].y, position[i].z); + if (type[i] == bushtype) { + messedwith[i] -= multiplier; + if (rotxvel[i] || rotx[i]) { + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; + + rotx[i] += rotxvel[i] * multiplier * 4; + } + if (rotyvel[i] || roty[i]) { + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; + + roty[i] += rotyvel[i] * multiplier * 4; + } + if (roty[i]) { + glRotatef(roty[i], 1, 0, 0); + } + if (rotx[i]) { + glRotatef(-rotx[i], 0, 0, 1); + } + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; + } + if (type[i] == treetrunktype || type[i] == treeleavestype) { + messedwith[i] -= multiplier; + if (rotxvel[i] || rotx[i]) { + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; + + rotx[i] += rotxvel[i] * multiplier * 4; + } + if (rotyvel[i] || roty[i]) { + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; + + roty[i] += rotyvel[i] * multiplier * 4; + } + if (roty[i]) { + glRotatef(roty[i] / 2, 1, 0, 0); + } + if (rotx[i]) { + glRotatef(-rotx[i] / 2, 0, 0, 1); + } + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; + } + if (environment == snowyenvironment) { + if (type[i] == treeleavestype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == treetrunktype) { + glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == bushtype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + } + if (environment == grassyenvironment) { + if (type[i] == treeleavestype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == treetrunktype) { + glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == bushtype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); } } + glRotatef(yaw[i], 0, 1, 0); + glColor4f(1, 1, 1, distance); + if (type[i] == treeleavestype) { + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + terrainlight = terrain.getLighting(position[i].x, position[i].z); + glDepthMask(0); + glEnable(GL_BLEND); + glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); + glAlphaFunc(GL_GREATER, 0); + glDisable(GL_ALPHA_TEST); + model[i].drawdifftex(treetextureptr); + } + if (type[i] == bushtype) { + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + terrainlight = terrain.getLighting(position[i].x, position[i].z); + glDepthMask(0); + glEnable(GL_BLEND); + glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); + glAlphaFunc(GL_GREATER, 0); + glDisable(GL_ALPHA_TEST); + model[i].drawdifftex(bushtextureptr); + } + glPopMatrix(); } } } } - if (environment == desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); + if (environment == desertenvironment) + glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 ); glEnable(GL_ALPHA_TEST); SetUpLight(&light, 0); } @@ -485,16 +526,19 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale) { if ((atype != treeleavestype && atype != bushtype) || foliage == 1) { scale[numobjects] = ascale; - if (atype == treeleavestype)scale[numobjects] += fabs((float)(Random() % 100) / 900) * ascale; + if (atype == treeleavestype) + scale[numobjects] += fabs((float)(Random() % 100) / 900) * ascale; onfire[numobjects] = 0; flamedelay[numobjects] = 0; type[numobjects] = atype; - if (atype == firetype)onfire[numobjects] = 1; + if (atype == firetype) + onfire[numobjects] = 1; position[numobjects] = where; - if (atype == bushtype)position[numobjects].y = terrain.getHeight(position[numobjects].x, position[numobjects].z) - .3; + if (atype == bushtype) + position[numobjects].y = terrain.getHeight(position[numobjects].x, position[numobjects].z) - .3; yaw[numobjects] = ayaw; rotxvel[numobjects] = 0; @@ -502,30 +546,30 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale) rotx[numobjects] = 0; roty[numobjects] = 0; - if (atype == boxtype)model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0); - if (atype == cooltype)model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0); - if (atype == walltype)model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0); - if (atype == tunneltype)model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0); - if (atype == chimneytype)model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0); - if (atype == spiketype)model[numobjects].load((char *)":Data:Models:Spike.solid", 0); - if (atype == weirdtype)model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0); - if (atype == rocktype)model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0); - if (atype == treetrunktype)model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0); - if (atype == treeleavestype)model[numobjects].load((char *)":Data:Models:Leaves.solid", 0); - if (atype == bushtype)model[numobjects].load((char *)":Data:Models:Bush.solid", 0); - - if (atype == boxtype)friction[numobjects] = 1.5; - if (atype == cooltype)friction[numobjects] = 1.5; - if (atype == walltype)friction[numobjects] = 1.5; - if (atype == platformtype)friction[numobjects] = 1.5; - if (atype == tunneltype)friction[numobjects] = 1.5; - if (atype == chimneytype)friction[numobjects] = 1.5; - if (atype == rocktype)friction[numobjects] = .5; - if (atype == rocktype && ascale > .5)friction[numobjects] = 1.5; - if (atype == weirdtype)friction[numobjects] = 1.5; - if (atype == spiketype)friction[numobjects] = .4; - if (atype == treetrunktype)friction[numobjects] = .4; - if (atype == treeleavestype)friction[numobjects] = 0; + if (atype == boxtype) model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0); + if (atype == cooltype) model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0); + if (atype == walltype) model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0); + if (atype == tunneltype) model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0); + if (atype == chimneytype) model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0); + if (atype == spiketype) model[numobjects].load((char *)":Data:Models:Spike.solid", 0); + if (atype == weirdtype) model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0); + if (atype == rocktype) model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0); + if (atype == treetrunktype) model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0); + if (atype == treeleavestype) model[numobjects].load((char *)":Data:Models:Leaves.solid", 0); + if (atype == bushtype) model[numobjects].load((char *)":Data:Models:Bush.solid", 0); + + if (atype == boxtype) friction[numobjects] = 1.5; + if (atype == cooltype) friction[numobjects] = 1.5; + if (atype == walltype) friction[numobjects] = 1.5; + if (atype == platformtype) friction[numobjects] = 1.5; + if (atype == tunneltype) friction[numobjects] = 1.5; + if (atype == chimneytype) friction[numobjects] = 1.5; + if (atype == rocktype) friction[numobjects] = .5; + if (atype == rocktype && ascale>.5) friction[numobjects] = 1.5; + if (atype == weirdtype) friction[numobjects] = 1.5; + if (atype == spiketype) friction[numobjects] = .4; + if (atype == treetrunktype) friction[numobjects] = .4; + if (atype == treeleavestype) friction[numobjects] = 0; if (atype == platformtype) { model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0); @@ -551,11 +595,13 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale) model[numobjects].ScaleNormals(-1, -1, -1); if (atype == treetrunktype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) { - if (detail == 2)terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 2, .4, 0); + if (detail == 2) + terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 2, .4, 0); } if (atype == bushtype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) { - if (detail == 2)terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 1, .4, 0); + if (detail == 2) + terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 1, .4, 0); } if (atype != treeleavestype && atype != bushtype && atype != firetype) @@ -569,20 +615,19 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float a { if ((atype != treeleavestype && atype != bushtype) || foliage == 1) { scale[numobjects] = ascale; - if (atype == treeleavestype)scale[numobjects] += fabs((float)(Random() % 100) / 900) * ascale; + if (atype == treeleavestype) + scale[numobjects] += fabs((float)(Random() % 100) / 900) * ascale; onfire[numobjects] = 0; flamedelay[numobjects] = 0; type[numobjects] = atype; - if (atype == firetype)onfire[numobjects] = 1; + if (atype == firetype) + onfire[numobjects] = 1; position[numobjects] = where; - if (atype == bushtype)position[numobjects].y = terrain.getHeight(position[numobjects].x, position[numobjects].z) - .3; - /*if(atype==firetype){ - if(position[numobjects].y .5)friction[numobjects] = 1.5; - if (atype == weirdtype)friction[numobjects] = 1.5; - if (atype == spiketype)friction[numobjects] = .4; - if (atype == treetrunktype)friction[numobjects] = .4; - if (atype == treeleavestype)friction[numobjects] = 0; - - if (friction[numobjects] == 1.5 && fabs(apitch) > 5)friction[numobjects] = .5; + if (atype == boxtype) model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0); + if (atype == cooltype) model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0); + if (atype == walltype) model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0); + if (atype == tunneltype) model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0); + if (atype == chimneytype) model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0); + if (atype == spiketype) model[numobjects].load((char *)":Data:Models:Spike.solid", 0); + if (atype == weirdtype) model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0); + if (atype == rocktype) model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0); + if (atype == treetrunktype) model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0); + if (atype == treeleavestype) model[numobjects].load((char *)":Data:Models:Leaves.solid", 0); + if (atype == bushtype) model[numobjects].load((char *)":Data:Models:Bush.solid", 0); + + if (atype == boxtype) friction[numobjects] = 1.5; + if (atype == cooltype) friction[numobjects] = 1.5; + if (atype == walltype) friction[numobjects] = 1.5; + if (atype == platformtype) friction[numobjects] = 1.5; + if (atype == tunneltype) friction[numobjects] = 1.5; + if (atype == chimneytype) friction[numobjects] = 1.5; + if (atype == rocktype) friction[numobjects] = .5; + if (atype == rocktype && ascale>.5) friction[numobjects] = 1.5; + if (atype == weirdtype) friction[numobjects] = 1.5; + if (atype == spiketype) friction[numobjects] = .4; + if (atype == treetrunktype) friction[numobjects] = .4; + if (atype == treeleavestype) friction[numobjects] = 0; + + if (friction[numobjects] == 1.5 && fabs(apitch) > 5) + friction[numobjects] = .5; if (atype == platformtype) { model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0); @@ -643,11 +689,13 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float a model[numobjects].ScaleNormals(-1, -1, -1); if (atype == treetrunktype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) { - if (detail == 2)terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 2, .4, 0); + if (detail == 2) + terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 2, .4, 0); } if (atype == bushtype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) { - if (detail == 2)terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 1, .4, 0); + if (detail == 2) + terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 1, .4, 0); } if (atype != treeleavestype && atype != bushtype && atype != firetype) @@ -661,15 +709,15 @@ void Objects::DoStuff() { XYZ spawnpoint; for (int i = 0; i < numobjects; i++) { - /*if(type[i]==firetype){ - Sprite::MakeSprite(weaponshinesprite, position[i],position[i]*0, 1,1,1, 5, 1); - }*/ - - if (type[i] == firetype)onfire[i] = 1; + if (type[i] == firetype) + onfire[i] = 1; if (onfire[i]) { - if (type[i] == bushtype)flamedelay[i] -= multiplier * 3; - if (type[i] == firetype)flamedelay[i] -= multiplier * 3; - if (type[i] == treeleavestype)flamedelay[i] -= multiplier * 4; + if (type[i] == bushtype) + flamedelay[i] -= multiplier * 3; + if (type[i] == firetype) + flamedelay[i] -= multiplier * 3; + if (type[i] == treeleavestype) + flamedelay[i] -= multiplier * 4; while (flamedelay[i] < 0 && onfire[i]) { flamedelay[i] += .006; if (type[i] == bushtype || type[i] == firetype) { @@ -699,7 +747,8 @@ void Objects::DoShadows() int i, j, k, l; static XYZ testpoint, testpoint2, terrainpoint, lightloc, col; lightloc = light.location; - if (!skyboxtexture)lightloc = 0; + if (!skyboxtexture) + lightloc = 0; lightloc.y += 10; Normalise(&lightloc); int patchx, patchz;