bool MovingEntity::VerticalCollision(Vector3 pos) { bool colided = false; for (int i = 0;i < 36;i++) { BlockPosition *bp = &_blockPositions[i]; if (_world->IsBlockCollidable(bp->position.x,bp->position.y,bp->position.z)) { BoundingBox blockBox = BoundingBox(Vector3(bp->position.x,bp->position.y,bp->position.z),Vector3(bp->position.x+1,bp->position.y+1,bp->position.z+1)); if (blockBox.contains(pos)) { colided = true; float moveDirection = pos.y - blockBox.getCenter().y; if (moveDirection > 0.0f) { _position.y += (0.5f - moveDirection); }else if (moveDirection < 0.0f) { _position.y -= (0.51f + moveDirection); } } } } return colided; }
bool BoundingBox::contains(const BoundingBox& b) const { if (b.contains(max)) return true; if (b.contains(min)) return true; if (this->contains(b.max)) return true; if (this->contains(b.min)) return true; return false; }
bool Camera::collides(const Entity &e) { // return false; float cam_rad = collisionRadius(); if (e.useBoundingBox()) { // return true; BoundingBox bb = e.getBoundingBox(); bb.box.min += e.getPosition(); bb.box.max += e.getPosition(); Eigen::Vector3f our_pos = -translations; if (bb.contains(our_pos)) { return true; } Eigen::Vector3f displacement = (bb.box.center() - our_pos); float distance = displacement.norm(); Eigen::Vector3f direction = displacement.normalized(); if (bb.contains(direction * cam_rad + our_pos)) { return true; } return false; } else { Eigen::Vector3f their_pos = e.getCenterWorld(); Eigen::Vector3f our_pos = translations; their_pos(1) = 0; our_pos(1) = 0; Eigen::Vector3f delta = -their_pos - our_pos; return std::abs(delta.norm()) < cam_rad + e.getRadius(); } /* std::cout << "object pos" << std::endl; std::cout << their_pos << std::endl; std::cout << "cam pos" << std::endl; std::cout << our_pos << std::endl; std::cout << " dist = " << std::abs(delta.norm()) << std::endl; */ }
/** Helper method to determine if this Iterator is valid. */ bool is_valid() const { if (s_ == nullptr || bb_.empty()) return false; if (code_ >= s_->mc_.code(bb_.max())+1) return false; if (loc_ >= s_->c2t_[code_].size()) return false; return bb_.contains(s_->t2p_(s_->c2t_[code_][loc_])); }
void KDtree::splitTriangles(const BoundingBox & lb, const BoundingBox & rb, std::vector<unsigned> &left, std::vector<unsigned> &right) const { const Mesh & mesh = o.getMesh(); for(unsigned t : triangles) { bool isInLeft = false; bool isInRight = false; for(unsigned i = 0 ; i<3 ; i++) { unsigned v = mesh.getTriangles()[t].getVertex(i); const Vec3Df & p = mesh.getVertices()[v].getPos(); if(lb.contains(p)) isInLeft = true; else if(rb.contains(p)) isInRight = true; } if(isInLeft) left.push_back(t); if(isInRight) right.push_back(t); } }
/** Helper method to advance this Iterator until it reaches a valid * position or end(). */ void fix() { assert(s_ != nullptr && !bb_.empty()); if (code_ >= s_->mc_.code(bb_.max())+1) { // Make equal to end() and return. code_ = s_->mc_.code(bb_.max())+1; loc_ = 0; return; } if (loc_ >= s_->c2t_[code_].size() || !bb_.contains(s_->t2p_(s_->c2t_[code_][loc_]))) { operator++(); } }
// possible results = STORED/NOT_STORED, OCCLUDED, DOESNT_FIT CoverageMap::StorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, bool storeIt) { if (_isRoot || _myBoundingBox.contains(polygon->getBoundingBox())) { // check to make sure this polygon isn't occluded by something at this level for (int i = 0; i < _polygonCount; i++) { VoxelProjectedPolygon* polygonAtThisLevel = _polygons[i]; // Check to make sure that the polygon in question is "behind" the polygon in the list // otherwise, we don't need to test it's occlusion (although, it means we've potentially // added an item previously that may be occluded??? Is that possible? Maybe not, because two // voxels can't have the exact same outline. So one occludes the other, they can't both occlude // each other. if (polygonAtThisLevel->occludes(*polygon)) { // if the polygonAtThisLevel is actually behind the one we're inserting, then we don't // want to report our inserted one as occluded, but we do want to add our inserted one. if (polygonAtThisLevel->getDistance() >= polygon->getDistance()) { if (storeIt) { storeInArray(polygon); return STORED; } else { return NOT_STORED; } } // this polygon is occluded by a closer polygon, so don't store it, and let the caller know return OCCLUDED; } } // if we made it here, then it means the polygon being stored is not occluded // at this level of the quad tree, so we can continue to insert it into the map. // First we check to see if it fits in any of our sub maps for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { BoundingBox childMapBoundingBox = getChildBoundingBox(i); if (childMapBoundingBox.contains(polygon->getBoundingBox())) { // if no child map exists yet, then create it if (!_childMaps[i]) { _childMaps[i] = new CoverageMap(childMapBoundingBox, NOT_ROOT, _managePolygons); } return _childMaps[i]->checkMap(polygon, storeIt); } } // if we got this far, then the polygon is in our bounding box, but doesn't fit in // any of our child bounding boxes, so we should add it here. if (storeIt) { storeInArray(polygon); return STORED; } else { return NOT_STORED; } } return DOESNT_FIT; }
// possible results = STORED/NOT_STORED, OCCLUDED, DOESNT_FIT CoverageMapStorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, bool storeIt) { if (_isRoot) { _checkMapRootCalls++; } // short circuit: we don't handle polygons that aren't all in view, so, if the polygon in question is // not in view, then we just discard it with a DOESNT_FIT, this saves us time checking values later. if (!polygon->getAllInView()) { return DOESNT_FIT; } BoundingBox polygonBox(polygon->getBoundingBox()); if (_isRoot || _myBoundingBox.contains(polygonBox)) { CoverageMapStorageResult result = NOT_STORED; CoverageRegion* storeIn = &_remainder; bool fitsInAHalf = false; // Check each half of the box independently if (_topHalf.contains(polygonBox)) { result = _topHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_topHalf; fitsInAHalf = true; } else if (_bottomHalf.contains(polygonBox)) { result = _bottomHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_bottomHalf; fitsInAHalf = true; } else if (_leftHalf.contains(polygonBox)) { result = _leftHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_leftHalf; fitsInAHalf = true; } else if (_rightHalf.contains(polygonBox)) { result = _rightHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_rightHalf; fitsInAHalf = true; } // if we got this far, there are one of two possibilities, either a polygon doesn't fit // in one of the halves, or it did fit, but it wasn't occluded by anything only in that // half. In either of these cases, we want to check our remainder region to see if its // occluded by anything there if (!(result == STORED || result == OCCLUDED)) { result = _remainder.checkRegion(polygon, polygonBox, storeIt); } // It's possible that this first set of checks might have resulted in an out of order polygon // in which case we just return.. if (result == STORED || result == OCCLUDED) { return result; } // if we made it here, then it means the polygon being stored is not occluded // at this level of the quad tree, so we can continue to insert it into the map. // First we check to see if it fits in any of our sub maps for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { BoundingBox childMapBoundingBox = getChildBoundingBox(i); if (childMapBoundingBox.contains(polygon->getBoundingBox())) { // if no child map exists yet, then create it if (!_childMaps[i]) { _childMaps[i] = new CoverageMap(childMapBoundingBox, NOT_ROOT, _managePolygons); } return _childMaps[i]->checkMap(polygon, storeIt); } } // if we got this far, then the polygon is in our bounding box, but doesn't fit in // any of our child bounding boxes, so we should add it here. if (storeIt) { if (polygon->getBoundingBox().area() > CoverageMap::MINIMUM_POLYGON_AREA_TO_STORE) { //printLog("storing polygon of area: %f\n",polygon->getBoundingBox().area()); storeIn->storeInArray(polygon); return STORED; } else { return NOT_STORED; } } else { return NOT_STORED; } } return DOESNT_FIT; }
// possible results = STORED/NOT_STORED, OCCLUDED, DOESNT_FIT CoverageMapStorageResult CoverageMap::checkMap(OctreeProjectedPolygon* polygon, bool storeIt) { if (_isRoot) { _checkMapRootCalls++; } // short circuit: we don't handle polygons that aren't all in view, so, if the polygon in question is // not in view, then we just discard it with a DOESNT_FIT, this saves us time checking values later. if (!polygon->getAllInView()) { _notAllInView++; return DOESNT_FIT; } BoundingBox polygonBox(polygon->getBoundingBox()); if (_isRoot || _myBoundingBox.contains(polygonBox)) { CoverageMapStorageResult result = NOT_STORED; CoverageRegion* storeIn = &_remainder; // Check each half of the box independently const bool useRegions = true; // for now we will continue to use regions if (useRegions) { if (_topHalf.contains(polygonBox)) { result = _topHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_topHalf; } else if (_bottomHalf.contains(polygonBox)) { result = _bottomHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_bottomHalf; } else if (_leftHalf.contains(polygonBox)) { result = _leftHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_leftHalf; } else if (_rightHalf.contains(polygonBox)) { result = _rightHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_rightHalf; } } // if we got this far, there are one of two possibilities, either a polygon doesn't fit // in one of the halves, or it did fit, but it wasn't occluded by anything only in that // half. In either of these cases, we want to check our remainder region to see if its // occluded by anything there if (!(result == STORED || result == OCCLUDED)) { result = _remainder.checkRegion(polygon, polygonBox, storeIt); } // It's possible that this first set of checks might have resulted in an out of order polygon // in which case we just return.. if (result == STORED || result == OCCLUDED) { /* if (result == STORED) qDebug("CoverageMap2::checkMap()... STORED\n"); else qDebug("CoverageMap2::checkMap()... OCCLUDED\n"); */ return result; } // if we made it here, then it means the polygon being stored is not occluded // at this level of the quad tree, so we can continue to insert it into the map. // First we check to see if it fits in any of our sub maps const bool useChildMaps = true; // for now we will continue to use child maps if (useChildMaps) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { BoundingBox childMapBoundingBox = getChildBoundingBox(i); if (childMapBoundingBox.contains(polygon->getBoundingBox())) { // if no child map exists yet, then create it if (!_childMaps[i]) { _childMaps[i] = new CoverageMap(childMapBoundingBox, NOT_ROOT, _managePolygons); } result = _childMaps[i]->checkMap(polygon, storeIt); /* switch (result) { case STORED: qDebug("checkMap() = STORED\n"); break; case NOT_STORED: qDebug("checkMap() = NOT_STORED\n"); break; case OCCLUDED: qDebug("checkMap() = OCCLUDED\n"); break; default: qDebug("checkMap() = ????? \n"); break; } */ return result; } } } // if we got this far, then the polygon is in our bounding box, but doesn't fit in // any of our child bounding boxes, so we should add it here. if (storeIt) { if (polygon->getBoundingBox().area() > CoverageMap::MINIMUM_POLYGON_AREA_TO_STORE) { if (storeIn->getPolygonCount() < MAX_POLYGONS_PER_REGION) { storeIn->storeInArray(polygon); return STORED; } else { CoverageRegion::_regionFullSkips++; return NOT_STORED; } } else { CoverageRegion::_tooSmallSkips++; return NOT_STORED; } } else { return NOT_STORED; } } return DOESNT_FIT; }
//computes a set of solitary grid points that represent the interaction between //this ligand and the provided receptor in some way void OBAMolecule::computeInteractionGridPoints(OBAMolecule& receptor, MGrid& grid, double interactionDist, double maxClusterDist, unsigned minClusterPoints, double interactionPointRadius) { grid.clear(); //first construct a bounding box for the ligand while assembling a //vector of atomic coordinates BoundingBox ligandBox; vector<AtomPoint> points; points.reserve(mol.NumAtoms()); for (OBAtomIterator aitr = mol.BeginAtoms(); aitr != mol.EndAtoms(); ++aitr) { OBAtom* atom = *aitr; points.push_back(AtomPoint(atom->x(), atom->y(), atom->z())); ligandBox.update(atom->x(), atom->y(), atom->z()); } ligandBox.extend(interactionDist); //then identify all coordinates that are interacting double idistSq = interactionDist * interactionDist; OBMol& rmol = receptor.getMol(); for (OBAtomIterator aitr = rmol.BeginAtoms(); aitr != rmol.EndAtoms(); ++aitr) { OBAtom* a = *aitr; if (ligandBox.contains(a->x(), a->y(), a->z())) { for (unsigned i = 0, n = points.size(); i < n; i++) { if (points[i].distSq(a->x(), a->y(), a->z()) <= idistSq) { points[i].interactingCnt++; } } } } //prune out non-interacting poitns vector<AtomPoint> tmp; tmp.reserve(points.size()); for (unsigned i = 0, n = points.size(); i < n; i++) { if (points[i].interactingCnt > 0) tmp.push_back(points[i]); } points.swap(tmp); tmp.clear(); //cluster these coordinates vector<vector<unsigned> > clusters; clusterPoints(points, maxClusterDist, clusters); //make the cluster centers the interaction grid points for (unsigned i = 0, n = clusters.size(); i < n; i++) { double xtot = 0, ytot = 0, ztot = 0; unsigned npts = clusters[i].size(); if (npts >= minClusterPoints) { for (unsigned j = 0; j < npts; j++) { xtot += points[clusters[i][j]].x; ytot += points[clusters[i][j]].y; ztot += points[clusters[i][j]].z; } double xave = xtot / (double) npts; double yave = ytot / (double) npts; double zave = ztot / (double) npts; grid.setPoint(xave, yave, zave); if(interactionPointRadius > 0) { grid.markXYZSphere(xave,yave,zave,interactionPointRadius); } } } }