00001 /* 00002 Copyright (C) 1997,1998,1999 00003 Kenji Hiranabe, Eiwa System Management, Inc. 00004 00005 This program is free software. 00006 Implemented by Kenji Hiranabe(hiranabe@esm.co.jp), 00007 conforming to the Java(TM) 3D API specification by Sun Microsystems. 00008 00009 Permission to use, copy, modify, distribute and sell this software 00010 and its documentation for any purpose is hereby granted without fee, 00011 provided that the above copyright notice appear in all copies and 00012 that both that copyright notice and this permission notice appear 00013 in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc. 00014 makes no representations about the suitability of this software for any 00015 purpose. It is provided "AS IS" with NO WARRANTY. 00016 00017 Copyright (C) 2004 00018 Rune Myrland, Skalden Studio AS 00019 SagaEngine adaptions. Kenji Hiranabe's license apply. 00020 */ 00021 #ifndef base_vecmath_Point2_hpp 00022 #define base_vecmath_Point2_hpp 00023 00024 #include "util_vecmath.hpp" 00025 #include "Vector2.hpp" 00026 #include "Point3.hpp" 00027 00028 namespace se_core { 00034 class _SeCoreExport Point2 : public Vector2 { 00035 public: 00041 Point2(coor_t x, coor_t y): Vector2(x, y) { } 00042 00047 Point2(const coor_t p[]): Vector2(p) { } 00048 00053 Point2(const Tuple2& t1): Vector2(t1) { } 00054 00058 Point2(): Vector2() { } 00059 00060 00064 inline void projectIsometric(Point3& p1) { 00065 x_ = p1.x_; 00066 y_ = CoorT::half(p1.z_) + CoorT::half(p1.y_); 00067 } 00068 00069 00073 inline void projectTopDown(Point3& p1) { 00074 x_ = p1.x_; 00075 y_ = p1.z_; 00076 } 00077 00078 00083 coor_double_t distanceSquared(const Point2& p1) const { 00084 coor_double_t dx = x_ - p1.x_; 00085 coor_double_t dy = y_ - p1.y_; 00086 return static_cast<coor_double_t>(dx)*dx + static_cast<coor_double_t>(dy)*dy; 00087 } 00088 00093 coor_t distance(const Point2& p1) const; 00094 00100 coor_t distanceL1(const Point2& p1) const; 00101 00107 coor_t distanceLinf(const Point2& p1) const; 00108 00109 scale_t lineIntersect(const Point2& a0, const Point2& a1, const Point2& b0, const Point2& b1); 00110 scale_t lineIntersect(const Point3& a0, const Point3& a1, const Point3& b0, const Point3& b1); 00111 00112 bool willAIntersectB(const Point2& a0, const Point2& a1, const Point2& b0, const Point2& b1); 00113 bool willAIntersectB(const Point3& a0, const Point3& a1, const Point3& b0, const Point3& b1, float tolerance = 0); 00114 00115 void nearestPoint(const Point2& pt1, const Point2& pt2, const Point2& testPoint); 00116 00121 float left(const Point2& P0, const Point2& P1 ) const { 00122 return (P1.x_ - P0.x_) * (y_ - P0.y_) - (x_ - P0.x_) * (P1.y_ - P0.y_); 00123 } 00124 00125 bool isLeft(const Point2& P0, const Point2& P1 ) const { 00126 return (0 > left(P0, P1)); 00127 } 00128 00129 // copy constructor and operator = is made by complier 00130 Point2& operator=(const Tuple2& t) { 00131 Tuple2::operator=(t); 00132 return *this; 00133 } 00134 }; 00135 00136 } // Namespace 00137 00138 00139 inline 00140 se_core::Point2 operator*(scale_t s, const se_core::Point2& t1) { 00141 return operator*(s, (const se_core::Tuple2&)t1); 00142 } 00143 00144 00145 #endif /* POINT2_H */
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:13 2007 by Doxygen version 1.3.9.1.