Example #1
0
	bool Collider::CollideCircleCircle(CircleCollider* a, CircleCollider* b, CollisionData *collisionData)
	{
		//TODO: store data in collisionData!

		Vector2 diff = b->GetCenter() - a->GetCenter();
		return (diff.IsInRange(a->radius + b->radius));
	}
Example #2
0
	bool CircleCollider::IntersectsPoint(const Vector2& point, CollisionData *collisionData)
	{
		Vector2 ePos = GetEntityPosition();

		Vector2 diff = point - (ePos + offset);
		return (diff.IsInRange(radius));
	}
Example #3
0
	bool Collider::CollideCircleCircle(CircleCollider* a, CircleCollider* b)
	{
		Vector2 aOff = a->GetEntityPosition();
		Vector2 bOff = b->GetEntityPosition();

		Vector2 diff = (b->offset + bOff) - (a->offset + aOff);
		return (diff.IsInRange(a->radius + b->radius));
	}
Example #4
0
	bool Collider::CollideCircleCircle(CircleCollider* a, CircleCollider* b, CollisionData *collisionData)
	{
		Vector2 diff = a->GetCenter() - b->GetCenter();
		if (diff.IsInRange(a->GetRadius() + b->GetRadius()))
		{
			if (collisionData)
			{
				collisionData->normal = diff.GetNormalized();
				collisionData->penetration = (a->GetRadius() + b->GetRadius()) - diff.GetMagnitude();
				collisionData->hitPoint = diff * 0.5f + b->GetCenter();
			}
			return true;
		}
		return false;
	}
Example #5
0
	Entity* Scene::GetNearestEntityByControlPoint(const Vector2 &position, const std::string &tag, Entity *ignoreEntity)
	{
		float smallestSqrMag = -1.0f;

		Entity *nearestEntity = NULL;

		std::list<Entity*> *entities = &this->entities;

		if (tag != "")
		{
			entities = GetAllTag(tag);
		}

		if (entities != NULL)
		{
			for (std::list<Entity*>::iterator i = entities->begin(); i != entities->end(); ++i)
			{
				if ((*i) != ignoreEntity)
				{
					Vector2 diff = (*i)->GetWorldPosition() - position;
					if (diff.IsInRange(ENTITY_CONTROLPOINT_SIZE))
					{
						float sqrMag = diff.GetSquaredMagnitude();
						if (smallestSqrMag == -1 || sqrMag < smallestSqrMag)
						{
							smallestSqrMag = sqrMag;
							nearestEntity = (*i);
						}
					}
				}

				//Entity *nearestChild = (*i)->GetNearestEntityByControlPoint(position, tag, ignoreEntity, smallestSqrMag);
				//if (nearestChild)
				//{
				//	nearestEntity = nearestChild;
				//}
			}
		}


		return nearestEntity;
	}
Example #6
0
bool Collider::CollideCircleCircle(CircleCollider* a, CircleCollider* b)
{
    Vector2 diff = b->GetCenter() - a->GetCenter();
    return (diff.IsInRange(a->radius + b->radius));
}