]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects/Object.cpp
Fixing some warnings
[lugaru.git] / Source / Objects / Object.cpp
index 12c96e5fda4fe8e8e09f89bf0c5acd3774e29251..c91e5d8c2b3faf84a973c965856403fcc3168c91 100644 (file)
@@ -49,7 +49,7 @@ Texture Object::rocktextureptr;
 
 Object::Object() :
     position(),
-    type(0),
+    type(boxtype),
     yaw(0),
     pitch(0),
     rotx(0),
@@ -70,7 +70,7 @@ Object::Object() :
 {
 }
 
-Object::Object(int _type, XYZ _position, float _yaw, float _pitch, float _scale) : Object()
+Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float _scale) : Object()
 {
     scale = _scale;
     type = _type;
@@ -689,7 +689,7 @@ void Object::ComputeRadius()
 {
     float maxdistance = 0;
     float tempdist;
-    for (int i = 0; i < objects.size(); i++) {
+    for (unsigned int i = 0; i < objects.size(); i++) {
         tempdist = distsq(&center, &objects[i]->position);
         if (tempdist > maxdistance) {
             maxdistance = tempdist;
@@ -714,7 +714,7 @@ void Object::LoadObjectsFromFile(FILE* tfile, bool skip)
             if (type == treeleavestype) {
                 scale = lastscale;
             }
-            objects.emplace_back(new Object(type, position, yaw, pitch, scale));
+            objects.emplace_back(new Object(object_type(type), position, yaw, pitch, scale));
             lastscale = scale;
         }
     }
@@ -744,28 +744,6 @@ void Object::AddObjectsToTerrain()
     }
 }
 
-bool Object::Checkcollide(XYZ startpoint, XYZ endpoint, int which)
-{
-    static XYZ colpoint, colviewer, coltarget;
-    static int i;
-
-    startpoint.y += .1;
-    endpoint.y += .1;
-    startpoint.y -= .1;
-    endpoint.y -= .1;
-
-    for (i = 0; i < objects.size(); i++) {
-        if (objects[i]->type != treeleavestype && objects[i]->type != treetrunktype && objects[i]->type != bushtype && objects[i]->type != firetype && i != which) {
-            colviewer = startpoint;
-            coltarget = endpoint;
-            if (objects[i]->model.LineCheck(&colviewer, &coltarget, &colpoint, &objects[i]->position, &objects[i]->yaw) != -1)
-                return 1;
-        }
-    }
-
-    return 0;
-}
-
 void Object::SphereCheckPossible(XYZ *p1, float radius)
 {
     int whichpatchx = p1->x / (terrain.size / subdivision * terrain.scale);
@@ -810,8 +788,7 @@ void Object::MakeObject(int atype, XYZ where, float ayaw, float apitch, float as
 {
     if ((atype != treeleavestype && atype != bushtype) || foliage == 1) {
         unsigned nextid = objects.size();
-        cout << "Adding object " << nextid << endl;
-        objects.emplace_back(new Object(atype, where, ayaw, apitch, ascale));
+        objects.emplace_back(new Object(object_type(atype), where, ayaw, apitch, ascale));
         objects.back()->addToTerrain(nextid);
     }
 }
@@ -837,6 +814,70 @@ void Object::DoShadows()
     }
 }
 
+int Object::checkcollide(XYZ startpoint, XYZ endpoint)
+{
+    float minx, minz, maxx, maxz, miny, maxy;
+
+    minx = min(startpoint.x, endpoint.x) - 1;
+    miny = min(startpoint.y, endpoint.y) - 1;
+    minz = min(startpoint.z, endpoint.z) - 1;
+    maxx = max(startpoint.x, endpoint.x) + 1;
+    maxy = max(startpoint.y, endpoint.y) + 1;
+    maxz = max(startpoint.z, endpoint.z) + 1;
+
+    for (unsigned int i = 0; i < objects.size(); i++) {
+        if (checkcollide(startpoint, endpoint, i, minx, miny, minz, maxx, maxy, maxz) != -1) {
+            return (int) i;
+        }
+    }
+
+    return -1;
+}
+
+int Object::checkcollide(XYZ startpoint, XYZ endpoint, int what)
+{
+    float minx, minz, maxx, maxz, miny, maxy;
+
+    minx = min(startpoint.x, endpoint.x) - 1;
+    miny = min(startpoint.y, endpoint.y) - 1;
+    minz = min(startpoint.z, endpoint.z) - 1;
+    maxx = max(startpoint.x, endpoint.x) + 1;
+    maxy = max(startpoint.y, endpoint.y) + 1;
+    maxz = max(startpoint.z, endpoint.z) + 1;
+
+    return checkcollide(startpoint, endpoint, what, minx, miny, minz, maxx, maxy, maxz);
+}
+
+int Object::checkcollide(XYZ startpoint, XYZ endpoint, int what, float minx, float miny, float minz, float maxx, float maxy, float maxz)
+{
+    XYZ colpoint, colviewer, coltarget;
+
+    if (what == 1000) {
+        if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) {
+            return what;
+        }
+    } else {
+        if (     objects[what]->position.x > minx - objects[what]->model.boundingsphereradius &&
+                 objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius &&
+                 objects[what]->position.y > miny - objects[what]->model.boundingsphereradius &&
+                 objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius &&
+                 objects[what]->position.z > minz - objects[what]->model.boundingsphereradius &&
+                 objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) {
+            if (     objects[what]->type != treeleavestype &&
+                     objects[what]->type != bushtype &&
+                     objects[what]->type != firetype) {
+                colviewer = startpoint;
+                coltarget = endpoint;
+                if (objects[what]->model.LineCheck(&colviewer, &coltarget, &colpoint, &objects[what]->position, &objects[what]->yaw) != -1) {
+                    return what;
+                }
+            }
+        }
+    }
+
+    return -1;
+}
+
 //~ Object::~Objects()
 //~ {
     //~ boxtextureptr.destroy();