void Needle::checkBoxAttach() { vector<Box*> boxes; world->getObjects<Box>(boxes); for (int box_ind = 0; box_ind < boxes.size(); box_ind++) { if (!boxes[box_ind]->isNeedleAttached()) { if (!boxes[box_ind]->isThreadAttached() && boxCollision(boxes[box_ind]->getPosition(), boxes[box_ind]->getHalfLength())) { boxes[box_ind]->attach(this); cout << "needle gets attached to box" << endl; } } else { if (!boxCollision(boxes[box_ind]->getPosition(), boxes[box_ind]->getHalfLength())) { boxes[box_ind]->dettachNeedle(); cout << "needle gets dettached from box" << endl; } } } }
vector<tile*> zone::getTiles(float box_x1, float box_y1, float box_x2, float box_y2) { vector<tile*> pTile; vector<tile*> temp_tile; int i; if ( !boxCollision( x, y, x + width, y + height, box_x1, box_y1, box_x2, box_y2 ) && !boxCollision( box_x1, box_y1, box_x2, box_y2, x, y, x + width, y + height ) ) return pTile; for (i = 0; i < quads.size(); i++){ temp_tile = quads[i]->getTiles(box_x1, box_y1, box_x2, box_y2); if (temp_tile.size() > 0) pTile.insert( pTile.end(),temp_tile.begin(), temp_tile.end()); } return pTile; }
void Needle::setTransformFromEndEffectorBoxConstrained(const Vector3d& new_ee_pos, const Matrix3d& new_ee_rot, Box* box) { Vector3d old_ee_pos; Matrix3d old_ee_rot; getEndEffectorTransform(old_ee_pos, old_ee_rot); Vector3d old_proj = (old_ee_pos - position); old_proj.normalize(); Vector3d proj = (new_ee_pos-position).dot(rotation.col(0))*rotation.col(0) + (new_ee_pos-position).dot(rotation.col(2))*rotation.col(2); proj.normalize(); glColor3f(0.8,0.8,0); drawArrow(position, 20*proj); glColor3f(0.8,0,0); drawArrow(position, 20*old_proj); Vector3d normal = proj.cross(old_proj); normal.normalize(); double angle = angle_between(proj, old_proj)*180.0/M_PI; if (angle > 90.0) { angle = 0.0; //TODO return; } else { double sign = ((normal - rotation.col(1)).squaredNorm() < 1e-5) ? -1 : 1; angle = sign*min(angle_between(proj, old_proj)*180.0/M_PI, 5.0); } if (!isnan(angle) && abs(angle)>1e-5 && angle>0.0) { //TODO for now, only allows forward movement of needle through box rotateAboutAxis(angle); if(isThreadAttached()) { thread->updateConstrainedTransform(constraint_ind, getEndPosition(), getEndRotation()); } } if (isThreadAttached()) { Vector3d direction; if (!box->isThreadAttached() && (sphereBoxDistance(getEndPosition(), getThicknessRadius(), box->getPosition(), box->getHalfLength(), direction) < 0)) { cout << "thread gets into the box" << endl; //box->attach(getThread()); box->attachThreadIn(getThread(), getEndPosition(), getEndRotation()); } if (box->isThreadAttached() && !boxCollision(box->getPosition(), box->getHalfLength())) { cout << "thread gets out of the box" << endl; box->attachThreadOut(getThread(), getEndPosition(), getEndRotation()); } } }