Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #pragma once
00027
00028 #include "cinder/Vector.h"
00029 #include <iostream>
00030
00031 namespace cinder {
00032
00033 template<typename T>
00034 class Plane
00035 {
00036 public:
00037 Plane() {}
00038 Plane( const Vec3<T> &v1, const Vec3<T> &v2, const Vec3<T> &v3 );
00039 Plane( const Vec3<T> &point, const Vec3<T> &normal );
00040 Plane( T a, T b, T c, T d );
00041
00043 void set( const Vec3<T> &v1, const Vec3<T> &v2, const Vec3<T> &v3 );
00045 void set( const Vec3<T> &point, const Vec3<T> &normal );
00047 void set( T a, T b, T c, T d );
00048
00049 Vec3<T> getPoint() const { return mNormal * mDistance; };
00050 const Vec3<T>& getNormal() const { return mNormal; };
00051 float getDistance() const { return mDistance; }
00052 float distance( const Vec3f &p ) const { return (mNormal.dot(p) - mDistance); };
00053
00054 Vec3<T> reflectPoint( const Vec3<T> &p ) const { return mNormal * distance( p ) * -2 + p; }
00055 Vec3<T> reflectVector( const Vec3<T> &v ) const { return mNormal * mNormal.dot(v) * 2 - v; }
00056
00057 Vec3<T> mNormal;
00058 T mDistance;
00059 };
00060
00061 typedef Plane<float> Planef;
00062 typedef Plane<double> Planed;
00063
00064 template<typename T>
00065 std::ostream& operator<<( std::ostream &o, const Plane<T> &p )
00066 {
00067 return o << "(" << p.mNormal << ", " << p.mDistance << ")";
00068 }
00069
00070
00071 class PlaneExc : public std::exception {
00072 public:
00073 virtual const char* what() const throw() { return "Invalid parameters specified"; }
00074 };
00075
00076 }