// Copyright (C) 2013 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include #define F(a) static_cast(a) template NzPlane::NzPlane(T normalX, T normalY, T normalZ, T D) { Set(normalX, normalY, normalZ, D); } template NzPlane::NzPlane(const T plane[4]) { Set(plane); } template NzPlane::NzPlane(const NzVector3& Normal, T D) { Set(Normal, D); } template NzPlane::NzPlane(const NzVector3& Normal, const NzVector3& point) { Set(Normal, point); } template NzPlane::NzPlane(const NzVector3& point1, const NzVector3& point2, const NzVector3& point3) { Set(point1, point2, point3); } template template NzPlane::NzPlane(const NzPlane& plane) { Set(plane); } template T NzPlane::Distance(const NzVector3& point) const { return normal.DotProduct(point) + distance; } template T NzPlane::Distance(T x, T y, T z) const { return Distance(NzVector3(x, y, z)); } template NzPlane& NzPlane::Set(T normalX, T normalY, T normalZ, T D) { distance = D; normal.Set(normalX, normalY, normalZ); return *this; } template NzPlane& NzPlane::Set(const T plane[4]) { normal.Set(plane[0], plane[1], plane[2]); distance = plane[3]; return *this; } template NzPlane& NzPlane::Set(const NzPlane& plane) { std::memcpy(this, &plane, sizeof(NzPlane)); return *this; } template NzPlane& NzPlane::Set(const NzVector3& Normal, T D) { distance = D; normal = Normal; return *this; } template NzPlane& NzPlane::Set(const NzVector3& Normal, const NzVector3& point) { normal = Normal; distance = -normal.DotProduct(point); return *this; } template NzPlane& NzPlane::Set(const NzVector3& point1, const NzVector3& point2, const NzVector3& point3) { NzVector3 edge1 = point2 - point1; NzVector3 edge2 = point3 - point1; normal = edge1.CrossProduct(edge2); normal.Normalize(); distance = -normal.DotProduct(point3); return *this; } template template NzPlane& NzPlane::Set(const NzPlane& plane) { normal.Set(plane.normal); distance = F(plane.distance); return *this; } template NzString NzPlane::ToString() const { NzStringStream ss; return ss << "Plane(Normal: " << normal.ToString() << "; Distance: " << distance << ')'; } template NzPlane NzPlane::Lerp(const NzPlane& from, const NzPlane& to, T interpolation) { #ifdef NAZARA_DEBUG if (interpolation < F(0.0) || interpolation > F(1.0)) { NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); return NzPlane(); } #endif NzPlane plane; plane.distance = NzLerp(from.distance, to.distance, interpolation); plane.normal = NzVector3::Lerp(from.normal, to.normal, interpolation); plane.normal.Normalize(); return plane; } template std::ostream& operator<<(std::ostream& out, const NzPlane& plane) { return out << plane.ToString(); } #undef F #include