Point3.cpp

Go to the documentation of this file.
00001 #include "Point3.hpp"
00002 #include "Point4.hpp"
00003 #include "Euler3.hpp"
00004 #include "../math/CoorT.hpp"
00005 #include "../math/Trig.hpp"
00006 
00007 namespace se_core {
00008 
00009     coor_t Point3
00010     ::distance(const Point3& p1) const {
00011         return CoorT::sqrt(distanceSquared(p1));
00012     }
00013 
00014 
00015     coor_t Point3
00016     ::distanceL1(const Point3& p1) const {
00017         return CoorT::abs(x_-p1.x_) + CoorT::abs(y_-p1.y_) + CoorT::abs(z_-p1.z_);
00018     }
00019 
00020 
00021     coor_t Point3
00022     ::distanceLinf(const Point3& p1) const {
00023         return CoorT::max(CoorT::abs(x_-p1.x_), CoorT::abs(y_-p1.y_), CoorT::abs(z_-p1.z_));
00024     }
00025 
00026     void Point3
00027     ::project(const Point4& p1) {
00028         // zero div may occur.
00029         x_ = CoorT::div(p1.x_, p1.w_);
00030         y_ = CoorT::div(p1.y_, p1.w_);
00031         z_ = CoorT::div(p1.z_, p1.w_);
00032     }
00033 
00034 
00035     coor_t Point3
00036     ::xzDistanceLinf(const Point3& c) const {
00037         coor_t xDist = CoorT::abs(c.x_ - x_);
00038         coor_t yDist = CoorT::abs(c.z_ - z_);
00039 
00040         return (xDist > yDist) ? xDist : yDist;
00041     }
00042 
00043 
00044     coor_t Point3
00045     ::yDistance(const Point3& c) const {
00046         coor_t dist = CoorT::abs(c.y_ - y_);
00047         return dist;
00048     }
00049 
00050 
00051     bray_t Point3
00052     ::yawTowards(const Point3& c) const {
00053         coor_t xp = c.x_ - x_;
00054         coor_t yp = c.z_ - z_;
00055         return Trig::atan2(-yp, xp);
00056     }
00057 
00058 
00059     void Point3
00060     ::eulerTowards(const Point3& c, Euler3& dest) const {
00061         coor_t xp = c.x_ - x_;
00062         coor_t zp = c.z_ - z_;
00063         dest.yaw_ = Trig::atan2(-zp, xp);
00064 
00065         coor_t xzp = CoorT::sqrt(xp * xp + zp * zp);
00066         coor_t yp = c.y_ - y_;
00067         dest.pitch_ = Trig::atan2(xzp, -yp);
00068     }
00069 
00070 
00071     void Point3
00072     ::nearestPoint(const Point3& pt1, const Point3& pt2, const Point3& testPoint) {
00073         Vector3 A, u;
00074         A.sub(testPoint, pt1);
00075         u.sub(pt2, pt1);
00076 
00077         // Normalize u
00078         coor_t len = u.length();
00079         u.scale(1 / len);
00080 
00081         // Nearest point
00082         scale_t s = A.dot(u);
00083         // Clamp point between pt1 and pt2
00084         if(s < 0)
00085             s = 0;
00086         else if(s > len)
00087             s = len;
00088 
00089         // Calc point
00090         scale(s, u);
00091         add(pt1);
00092 
00093         //Assert(testPoint.distanceSquared(*this) <= testPoint.distanceSquared(pt1));
00094         //Assert(testPoint.distanceSquared(*this) <= testPoint.distanceSquared(pt2));
00095     }
00096 
00097 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:13 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo