Пример #1
0
	bool	iTest		(const AABB2D &ac, const Ray2D &bc)
	{
		assert(bc.direction[0] + bc.direction[1] != 0);

		Ray2D ray = bc;

		for (int i = 0; i < 2; ++i)
			ray.direction[i] = (ray.direction[i] == 0) ? FLT_EPSILON : ray.direction[i];

		Plane2D planes[4];

		planes[0] = { Vector2{ ac.min.x  , ac.pos().y },Vector2{ -1, 0 } };
		planes[1] = { Vector2{ ac.pos().x, ac.min.y   },Vector2{  0,-1 } };
		planes[2] = { Vector2{ ac.max.x  , ac.pos().y },Vector2{  1, 0 } };
		planes[3] = { Vector2{ ac.pos().x, ac.max.y   },Vector2{  0, 1 } };

		float dists[4];

		float tmin = FLT_MAX;
		float tmax = -FLT_MAX;

		for (int i = 0; i < 4; ++i)
		{
			float deno = -(dot(planes[i].normal, ray.direction));

			dists[i] = dot(planes[i].normal, (ray.position - planes[i].position)) / deno;
		}

		tmin = fmaxf(fminf(dists[0], dists[2]), fminf(dists[1], dists[3]));
		tmax = fminf(fmaxf(dists[0], dists[2]), fmaxf(dists[1], dists[3]));

		return tmin <= tmax && 0 <= tmin <= bc.length;
	}
Пример #2
0
void Line2D::getAABB(AABB2D& bb, Real tmin, Real tmax) const
{
	Point2D a,b;
	eval(tmin,a);
	eval(tmax,b);
	bb.setPoint(a);
	bb.expand(b);
}
Пример #3
0
void Player2D::render() {
	glPushMatrix();

	glColor3f(0x00, 0x11, 0xaa);

	glTranslatef(this->getPosition().x + gCameraX, this->getPosition().y + gCameraY, 0.0f);
	AABB2D temp = this->getBoundingBox(false);
	temp.render();

	glPopMatrix();
}
Пример #4
0
//------------------------------------------------------------------------------------------------------
//predicate function that checks if mouse cursor collides with passed box bound
//------------------------------------------------------------------------------------------------------
bool InputManager::IsMouseColliding(const AABB2D& bound)
{

	//create a temporary bounding box to represent mouse cursor
	AABB2D tempBound;

	//set mouse cursor bounds of 1x1 based on mouse position
	//flip Y axis as mouse coordinates run from top to bottom
	tempBound.SetPosition(m_mousePosition.x,
					      TheScreen::Instance()->GetScreenSize().y - m_mousePosition.y);
	tempBound.SetDimension(1, 1);
	tempBound.Update();

	//return flag based on if mouse collides with bound
	return tempBound.IsColliding(bound);

}
Пример #5
0
Mouse Mouse::scaleMouse(const AABB2D& cam) const noexcept
{
	Mouse temp = *this;
	float camWidth = cam.width();
	temp.position = cam.min + (temp.position * camWidth);
	temp.motion = temp.motion * camWidth;
	return temp;
}
Пример #6
0
Real Segment2D::distance(const AABB2D& bb, Real& tmin) const
{
  Real tmax;
  if(intersects(bb,tmin,tmax)) return 0;
  //non-intersecting -- either bb vertex - seg is closest feature pair or
  //bb edge - endpoint is closest feature pair

  //first check segment endpoints
  Real dmin;
  dmin = bb.distance(a);
  tmin = 0.0;
  Real d=bb.distance(b);
  if(d < dmin) {
    dmin = d;
    tmin = 1.0;
  }
  //now check vertices
  Vector2 p;
  Real t = closestPoint(bb.bmax,p);
  d = p.distanceSquared(bb.bmax);
  if(d < Sqr(dmin)) {
    dmin = Sqrt(d);
    tmin = t;
  }
  t = closestPoint(bb.bmin,p);
  d = p.distanceSquared(bb.bmin);
  if(d < Sqr(dmin)) {
    dmin = Sqrt(d);
    tmin = t;
  }
  t = closestPoint(Vector2(bb.bmin.x,bb.bmax.y),p);
  d = p.distanceSquared(Vector2(bb.bmin.x,bb.bmax.y));
  if(d < Sqr(dmin)) {
    dmin = Sqrt(d);
    tmin = t;
  }
  t = closestPoint(Vector2(bb.bmax.x,bb.bmin.y),p);
  d = p.distanceSquared(Vector2(bb.bmax.x,bb.bmin.y));
  if(d < Sqr(dmin)) {
    dmin = Sqrt(d);
    tmin = t;
  }
  return dmin;
}
Пример #7
0
	CollisionData iTest_data(const AABB2D &ac, const Plane2D &bc)
	{
		if (iTest(ac, bc))
		{
			CollisionData r;
			r.collisionNormal = bc.normal;
			r.penDepth = dot(bc.normal, (ac.pos() - bc.position));
			if (r.penDepth < 0) r.penDepth = 0;
			return r;
		}
		else return CollisionData{ 0,0 };
	}
Пример #8
0
void Segment2D::getAABB(AABB2D& bb) const
{
  bb.setPoint(a);
  bb.expand(b);
}
Пример #9
0
void FontRenderer::begin(const AABB2D& camera) noexcept
{
	this->begin(camera.position(), camera.dimensions());
}
Пример #10
0
	bool	iTest		(const AABB2D &ac, const Plane2D &bc)
	{
		return dot(bc.normal, (ac.pos() - bc.position)) <= 
				  (ac.dim().x / 2) * dot(bc.normal, Vector2{ 1,0 }) 
				+ (ac.dim().y / 2) * dot(bc.normal, Vector2{ 0,1 });
	}