Beispiel #1
0
bool HollowBall::intersects(const Line3D& line, ClosedIntervalSet& segs) const
{
  Sphere3D s;
  s.center=center;
  s.radius=outerRadius+wsEpsilon;
  ClosedInterval i;
  OpenInterval j;
  if(!s.intersects(line,&i.a,&i.b)) return false;
  //cout<<"Outer sphere intersects at "<<i.a<<","<<i.b<<endl;

  segs.resize(1);
  segs[0] = i;
  if(innerRadius >= 0) {
    s.radius=innerRadius-wsEpsilon;
    if(s.intersects(line,&j.a,&j.b)) {
      //cout<<"Inner sphere intersects at "<<j.a<<","<<j.b<<endl;
      ClosedInterval p,q;
      int num=IntervalSubtract(i,j,p,q);
      Assert(num==2);
      segs.resize(num);
      segs[0] = p;
      segs[1] = q;
    }
  }
  return true;
}
Beispiel #2
0
bool Ellipsoid3D::intersects(const Segment3D& seg, Real* t1, Real* t2) const
{
	Segment3D slocal;
	toLocalNormalized(seg,slocal);
	Sphere3D s;
	s.center.setZero();
	s.radius = One;
	return s.intersects(slocal,t1,t2);
}
Beispiel #3
0
bool Ellipsoid3D::intersects(const Line3D& l, Real* t1, Real* t2) const
{
	Line3D llocal;
	toLocalNormalized(l,llocal);
	Sphere3D s;
	s.center.setZero();
	s.radius = One;
	return s.intersects(llocal,t1,t2);
}
Beispiel #4
0
bool Box3D::intersects(const Sphere3D& s) const
{
  Sphere3D sloc;
  toLocal(s.center,sloc.center);
  sloc.radius = s.radius;
  AABB3D bbloc;
  bbloc.bmin.setZero();
  bbloc.bmax=dims;
  return sloc.intersects(bbloc);
}
Beispiel #5
0
//------------------------------------------------------------------------------------------------------
//function that checks if line segment collides with another sphere object
//------------------------------------------------------------------------------------------------------
bool Line3D::IsColliding(const Sphere3D& secondSphere) const
{

	glm::vec3 distanceFromLine;

	//calculate the distance the sphere and point on line segment are apart from each other
	//this makes use of inner function that calculates the point on line segment closest to sphere 
	distanceFromLine = secondSphere.GetPosition() - PointOnLine(secondSphere.GetPosition().x, 
						                                        secondSphere.GetPosition().y, 
		                                                        secondSphere.GetPosition().z);

	//return flag based on if line segment intersects with sphere
	return (glm::length(distanceFromLine) <= secondSphere.GetRadius());

}
Beispiel #6
0
void OctreePointSet::BallQuery(const Vector3& c,Real r,vector<Vector3>& points,vector<int>& ids) const
{
  points.resize(0);
  ids.resize(0);
  vector<int> ballnodes;
  BallLookup(c,r,ballnodes);
  Sphere3D s;
  s.center = c;
  s.radius = r;
  for(size_t i=0;i<ballnodes.size();i++) {
    const vector<Vector3>& pts = pointLists[ballnodes[i]];
    const vector<int>& bids = idLists[ballnodes[i]];
    for(size_t k=0;k<pts.size();k++)
      if(s.contains(pts[k])) {
	points.push_back(pts[k]);
	ids.push_back(bids[k]);
      }
  }
}
Beispiel #7
0
void WorkspaceBound::GetBounds(AABB3D& bb) const
{
  Sphere3D s;
  GetBounds(s);
  s.getAABB(bb);
}
bool TransformWidget::Hover(int x,int y,Camera::Viewport& viewport,double& distance)
{
  Real globalScale = 1.0;
  if(scaleToScreen) {
    float sx,sy,sz;
    viewport.project(T.t,sx,sy,sz);
    globalScale = sz/viewport.scale;
  }
  distance = Inf;
  int oldHoverItem = hoverItem;
  hoverItem = -1;
  Ray3D r;
  viewport.getClickSource(x,y,r.source);
  viewport.getClickVector(x,y,r.direction);
  //check origin
  if(enableTranslation && enableOriginTranslation) {
    Sphere3D s;
    s.center = T.t;
    s.radius = originRadius*globalScale;
    Real tmin,tmax;
    if(s.intersects(r,&tmin,&tmax)) {
      distance = tmin;
      hoverItem = 0;
    }
  }
  //check translation axes
  for(int i=0;i<3;i++) {
    if(!enableTranslation) break;
    if(!enableTranslationAxes[i]) continue;
    Line3D axisLine;
    axisLine.source = T.t;
    axisLine.direction = Vector3(T.R.col(i));
    Real t,u;
    axisLine.closestPoint(r,t,u);
    t = Clamp(t,0.0,axisLength*globalScale);
    u = Clamp(u,0.0,Inf);
    Vector3 paxis,pray;
    axisLine.eval(t,paxis);
    r.eval(u,pray);
    if(paxis.distanceSquared(pray) <= Sqr(axisRadius*globalScale)) {
      if(u < distance) {
	distance = u;
	hoverItem = 1+i;
      }
    }
  }
  if(enableRotation) {
    //check rotation rings
    Circle3D c;
    c.center = T.t;
    for(int i=0;i<3;i++) {
      if(!enableRotationAxes[i]) continue;
      c.axis = Vector3(T.R.col(i));
      c.radius = ringOuterRadius*globalScale;
      Real t;
      if(c.intersects(r,&t) && t >= 0) {
	c.radius = ringInnerRadius*globalScale;
	if(!c.intersects(r,NULL)) {
	  if(t < distance) {
	    distance = t;
	    hoverItem = i+4;
	  }
	}
      }
    }
  }
  if(enableRotation && enableOuterRingRotation) {
    //check outer ring
    Circle3D c;
    c.center = T.t;
    viewport.getViewVector(c.axis);
    c.radius = (ringOuterRadius+arrowHeight)*globalScale;
    Real t;
    if(c.intersects(r,&t) && t >= 0) {
      c.radius = (ringInnerRadius+arrowHeight)*globalScale;
      if(!c.intersects(r,NULL)) {
	if(t < distance) {
	  distance = t;
	  hoverItem = 7;
	}
      }
    }
    clickAxis = c.axis;
  }
  if(hoverItem != oldHoverItem) Refresh();
  r.eval(distance,hoverPos);
  return hoverItem != -1;
}