X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FObjects%2FObject.cpp;fp=Source%2FObjects%2FObject.cpp;h=1189f365243c75a0fdb33193a35f599313c5213b;hb=bdf3ebaf05ce8dc8d59e321a07c66598db181eb7;hp=3e1e100eaffb5b7d30942ec6dfa18d58a1f2eb8f;hpb=9d126720312b8fa13279c144b2f74bc3d2c66fd9;p=lugaru.git diff --git a/Source/Objects/Object.cpp b/Source/Objects/Object.cpp index 3e1e100..1189f36 100644 --- a/Source/Objects/Object.cpp +++ b/Source/Objects/Object.cpp @@ -814,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 (int i = 0; i < objects.size(); i++) { + if (checkcollide(startpoint, endpoint, i, minx, miny, minz, maxx, maxy, maxz) != -1) { + return 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();