nvidia-texture-tools/src/nvmath/Plane.cpp

28 lines
763 B
C++
Raw Normal View History

2008-04-17 06:58:43 +00:00
// This code is in the public domain -- castanyo@yahoo.es
#include "Plane.h"
#include "Plane.inl"
2011-10-11 18:52:24 +00:00
#include "Matrix.inl"
2008-04-17 06:58:43 +00:00
namespace nv
{
2012-07-20 16:19:03 +00:00
Plane transformPlane(const Matrix & m, const Plane & p)
2010-05-27 23:19:24 +00:00
{
Vector3 newVec = transformVector(m, p.vector());
2008-04-17 06:58:43 +00:00
2010-05-27 23:19:24 +00:00
Vector3 ptInPlane = p.offset() * p.vector();
ptInPlane = transformPoint(m, ptInPlane);
2008-04-17 06:58:43 +00:00
2010-05-27 23:19:24 +00:00
return Plane(newVec, ptInPlane);
}
2012-07-20 16:19:03 +00:00
Vector3 planeIntersection(const Plane & a, const Plane & b, const Plane & c)
2010-05-27 23:19:24 +00:00
{
return dot(a.vector(), cross(b.vector(), c.vector())) * (
a.offset() * cross(b.vector(), c.vector()) +
c.offset() * cross(a.vector(), b.vector()) +
b.offset() * cross(c.vector(), a.vector()));
}
} // nv namespace