]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects.cpp
Add copyright notice and AUTHORS file for open source contributors
[lugaru.git] / Source / Objects.cpp
index 6f3d3c08f44a5f981fdbb72d5a1f900538f1bd9b..1a974be750cfb5be564aa5b80f619375a6c4c268 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
 */
 
 #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;
@@ -84,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;
 
@@ -106,12 +105,8 @@ void Objects::Draw()
                         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);
@@ -364,152 +359,148 @@ 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();
                 }
             }
         }
@@ -637,10 +628,6 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float a
         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<terrain.getHeight(position[numobjects].x,position[numobjects].z)-.3)
-        position[numobjects].y=terrain.getHeight(position[numobjects].x,position[numobjects].z)-.3;
-        }*/
         yaw[numobjects] = ayaw;
         pitch[numobjects] = apitch;
 
@@ -722,10 +709,6 @@ 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 (onfire[i]) {