//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * 球実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Geometry/Primitive/Sphere.h"
#include "Geometry/Distance/AxisAlignedBoxDistance.h"
#include "Geometry/Distance/CapsuleDistance.h"
#include "Geometry/Distance/ConeDistance.h"
#include "Geometry/Distance/LineDistance.h"
#include "Geometry/Distance/OrientedBoxDistance.h"
#include "Geometry/Distance/PlaneDistance.h"
#include "Geometry/Distance/RayDistance.h"
#include "Geometry/Distance/SegmentDistance.h"
#include "Geometry/Distance/SphereDistance.h"
#include "Geometry/Intersection/AxisAlignedBoxIntersection.h"
#include "Geometry/Intersection/CapsuleIntersection.h"
#include "Geometry/Intersection/ConeIntersection.h"
#include "Geometry/Intersection/LineIntersection.h"
#include "Geometry/Intersection/OrientedBoxIntersection.h"
#include "Geometry/Intersection/PlaneIntersection.h"
#include "Geometry/Intersection/RayIntersection.h"
#include "Geometry/Intersection/SegmentIntersection.h"
#include "Geometry/Intersection/SphereIntersection.h"

namespace Lamp{

//------------------------------------------------------------------------------
// 定数
//------------------------------------------------------------------------------
// ゼロ球
const Sphere Sphere::zero(0.f, 0.f, 0.f, 0.f);

// 単位球
const Sphere Sphere::unit(0.f, 0.f, 0.f, 1.f);

//------------------------------------------------------------------------------
// 距離
//------------------------------------------------------------------------------
// 点距離の二乗
float Sphere::getSquaredDistance(const Vector3& point) const{
	return SphereDistance::squaredDistance(*this, point);
}
//------------------------------------------------------------------------------
// 軸沿いボックス距離の二乗
float Sphere::getSquaredDistance(const AxisAlignedBox& axisAlignedBox) const{
	return AxisAlignedBoxDistance::squaredDistance(axisAlignedBox, *this);
}
//------------------------------------------------------------------------------
// カプセル距離の二乗
float Sphere::getSquaredDistance(const Capsule& capsule) const{
	return CapsuleDistance::squaredDistance(capsule, *this);
}
//------------------------------------------------------------------------------
// コーン距離の二乗
float Sphere::getSquaredDistance(const Cone& cone) const{
	return ConeDistance::squaredDistance(cone, *this);
}
//------------------------------------------------------------------------------
// ライン距離の二乗
float Sphere::getSquaredDistance(const Line& line) const{
	return LineDistance::squaredDistance(line, *this);
}
//------------------------------------------------------------------------------
// 指向性ボックス距離の二乗
float Sphere::getSquaredDistance(const OrientedBox& orientedBox) const{
	return OrientedBoxDistance::squaredDistance(orientedBox, *this);
}
//------------------------------------------------------------------------------
// 平面距離
float Sphere::getDistance(const Plane& plane) const{
	return PlaneDistance::distance(plane, *this);
}
//------------------------------------------------------------------------------
// レイ距離の二乗
float Sphere::getSquaredDistance(const Ray& ray) const{
	return RayDistance::squaredDistance(ray, *this);
}
//------------------------------------------------------------------------------
// セグメント距離の二乗
float Sphere::getSquaredDistance(const Segment& segment) const{
	return SegmentDistance::squaredDistance(segment, *this);
}
//------------------------------------------------------------------------------
// 球距離の二乗
float Sphere::getSquaredDistance(const Sphere& sphere) const{
	return SphereDistance::squaredDistance(*this, sphere);
}
//------------------------------------------------------------------------------
// 三角距離の二乗
float Sphere::getSquaredDistance(const Triangle& triangle) const{
	return SphereDistance::squaredDistance(*this, triangle);
}
//------------------------------------------------------------------------------
// 交差
//------------------------------------------------------------------------------
// 点交差
bool Sphere::intersect(const Vector3& point) const{
	return SphereIntersection::intersect(*this, point);
}
//------------------------------------------------------------------------------
// 軸沿いボックス交差
bool Sphere::intersect(const AxisAlignedBox& axisAlignedBox) const{
	return AxisAlignedBoxIntersection::intersect(axisAlignedBox, *this);
}
//------------------------------------------------------------------------------
// コーン交差
bool Sphere::intersect(const Cone& cone) const{
	return ConeIntersection::intersect(cone, *this);
}
//------------------------------------------------------------------------------
// カプセル交差
bool Sphere::intersect(const Capsule& capsule) const{
	return CapsuleIntersection::intersect(capsule, *this);
}
//------------------------------------------------------------------------------
// ライン交差
bool Sphere::intersect(const Line& line) const{
	return LineIntersection::intersect(line, *this);
}
//------------------------------------------------------------------------------
// 指向性ボックス交差
bool Sphere::intersect(const OrientedBox& orientedBox) const{
	return OrientedBoxIntersection::intersect(orientedBox, *this);
}
//------------------------------------------------------------------------------
// 平面交差
bool Sphere::intersect(const Plane& plane) const{
	return PlaneIntersection::intersect(plane, *this);
}
//------------------------------------------------------------------------------
// レイ交差
bool Sphere::intersect(const Ray& ray) const{
	return RayIntersection::intersect(ray, *this);
}
//------------------------------------------------------------------------------
// セグメント交差
bool Sphere::intersect(const Segment& segment) const{
	return SegmentIntersection::intersect(segment, *this);
}
//------------------------------------------------------------------------------
// 球交差
bool Sphere::intersect(const Sphere& sphere) const{
	return SphereIntersection::intersect(*this, sphere);
}
//------------------------------------------------------------------------------
// 球交差
bool Sphere::intersect(Intersection* intersection, const Sphere& sphere) const{
	return SphereIntersection::intersect(intersection, *this, sphere);
}
//------------------------------------------------------------------------------
// 三角交差
bool Sphere::intersect(const Triangle& triangle) const{
	return SphereIntersection::intersect(*this, triangle);
}
//------------------------------------------------------------------------------
// 三角交差
bool Sphere::intersect(
	Intersection* intersection, const Triangle& triangle) const{
	return SphereIntersection::intersect(intersection, *this, triangle);
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
