Exemplo n.º 1
0
//=============================================================================
// AABB同士の当たり判定
//=============================================================================
bool CCollisionManager::JudgeAABBCross(
	const VECTOR3& p1, const AABB& b1,
	const VECTOR3& p2, const AABB& b2)
{
	VECTOR3 min_pos1;
	VECTOR3 min_pos2;
	min_pos1._x = p1._x + b1.Min._x;
	min_pos1._y = p1._y + b1.Min._y;
	min_pos1._z = p1._z + b1.Min._z;
	min_pos2._x = p2._x + b2.Min._x;
	min_pos2._y = p2._y + b2.Min._y;
	min_pos2._z = p2._z + b2.Min._z;

	bool bHitX = 
		min_pos1._x <= min_pos2._x + b2.width() &&
		min_pos1._x >= min_pos2._x - b1.width();
	bool bHitY =
		min_pos1._y <= min_pos2._y + b2.height() &&
		min_pos1._y >= min_pos2._y - b1.height();
	bool bHitZ =
		min_pos1._z <= min_pos2._z + b2.depth() &&
		min_pos1._z >= min_pos2._z - b1.depth();

	if(!bHitX || !bHitY || !bHitZ)
	{
		return false;
	}

	return true;
}
Exemplo n.º 2
0
  void centerOnObject(const AABB &objectBounds) {
    auto size = std::max(
        {objectBounds.width(), objectBounds.height(), objectBounds.depth()});
    auto cx = (objectBounds.xmax + objectBounds.xmin) / 2.f;
    auto cy = (objectBounds.ymax + objectBounds.ymin) / 2.f;
    auto cz = (objectBounds.zmax + objectBounds.zmin) / 2.f;
    const float fov = 45.0f;
    float camDist = (0.5f * size) / std::tan(0.5f * glm::radians(fov));
    lookAt(cx, cy, cz);
    lookDistance(camDist);
    setNearFarPlanes(0.1f * camDist, 10.0f * camDist);
    setFieldOfView(fov);
	arcballRotation = quat{};
    AG_DEBUG("near {} far {}", 0.5f * camDist, 2.0f * camDist);
  }