Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletCollision/Gimpact/gim_clip_polygon.h
| Show All 27 Lines | |||||
| This library is distributed in the hope that it will be useful, | This library is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files | ||||
| GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details. | GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details. | ||||
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ||||
| */ | */ | ||||
| //! This function calcs the distance from a 3D plane | //! This function calcs the distance from a 3D plane | ||||
| class DISTANCE_PLANE_3D_FUNC | class DISTANCE_PLANE_3D_FUNC | ||||
| { | { | ||||
| public: | public: | ||||
| template<typename CLASS_POINT,typename CLASS_PLANE> | template <typename CLASS_POINT, typename CLASS_PLANE> | ||||
| inline GREAL operator()(const CLASS_PLANE & plane, const CLASS_POINT & point) | inline GREAL operator()(const CLASS_PLANE& plane, const CLASS_POINT& point) | ||||
| { | { | ||||
| return DISTANCE_PLANE_POINT(plane, point); | return DISTANCE_PLANE_POINT(plane, point); | ||||
| } | } | ||||
| }; | }; | ||||
| template<typename CLASS_POINT> | template <typename CLASS_POINT> | ||||
| SIMD_FORCE_INLINE void PLANE_CLIP_POLYGON_COLLECT( | SIMD_FORCE_INLINE void PLANE_CLIP_POLYGON_COLLECT( | ||||
| const CLASS_POINT & point0, | const CLASS_POINT& point0, | ||||
| const CLASS_POINT & point1, | const CLASS_POINT& point1, | ||||
| GREAL dist0, | GREAL dist0, | ||||
| GREAL dist1, | GREAL dist1, | ||||
| CLASS_POINT * clipped, | CLASS_POINT* clipped, | ||||
| GUINT & clipped_count) | GUINT& clipped_count) | ||||
| { | { | ||||
| GUINT _prevclassif = (dist0>G_EPSILON); | GUINT _prevclassif = (dist0 > G_EPSILON); | ||||
| GUINT _classif = (dist1>G_EPSILON); | GUINT _classif = (dist1 > G_EPSILON); | ||||
| if(_classif!=_prevclassif) | if (_classif != _prevclassif) | ||||
| { | { | ||||
| GREAL blendfactor = -dist0/(dist1-dist0); | GREAL blendfactor = -dist0 / (dist1 - dist0); | ||||
| VEC_BLEND(clipped[clipped_count],point0,point1,blendfactor); | VEC_BLEND(clipped[clipped_count], point0, point1, blendfactor); | ||||
| clipped_count++; | clipped_count++; | ||||
| } | } | ||||
| if(!_classif) | if (!_classif) | ||||
| { | { | ||||
| VEC_COPY(clipped[clipped_count],point1); | VEC_COPY(clipped[clipped_count], point1); | ||||
| clipped_count++; | clipped_count++; | ||||
| } | } | ||||
| } | } | ||||
| //! Clips a polygon by a plane | //! Clips a polygon by a plane | ||||
| /*! | /*! | ||||
| *\return The count of the clipped counts | *\return The count of the clipped counts | ||||
| */ | */ | ||||
| template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC> | template <typename CLASS_POINT, typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC> | ||||
| SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON_GENERIC( | SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON_GENERIC( | ||||
| const CLASS_PLANE & plane, | const CLASS_PLANE& plane, | ||||
| const CLASS_POINT * polygon_points, | const CLASS_POINT* polygon_points, | ||||
| GUINT polygon_point_count, | GUINT polygon_point_count, | ||||
| CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func) | CLASS_POINT* clipped, DISTANCE_PLANE_FUNC distance_func) | ||||
| { | { | ||||
| GUINT clipped_count = 0; | GUINT clipped_count = 0; | ||||
| //clip first point | //clip first point | ||||
| GREAL firstdist = distance_func(plane,polygon_points[0]);; | GREAL firstdist = distance_func(plane, polygon_points[0]); | ||||
| ; | |||||
| if(!(firstdist>G_EPSILON)) | if (!(firstdist > G_EPSILON)) | ||||
| { | { | ||||
| VEC_COPY(clipped[clipped_count],polygon_points[0]); | VEC_COPY(clipped[clipped_count], polygon_points[0]); | ||||
| clipped_count++; | clipped_count++; | ||||
| } | } | ||||
| GREAL olddist = firstdist; | GREAL olddist = firstdist; | ||||
| for(GUINT _i=1;_i<polygon_point_count;_i++) | for (GUINT _i = 1; _i < polygon_point_count; _i++) | ||||
| { | { | ||||
| GREAL dist = distance_func(plane,polygon_points[_i]); | GREAL dist = distance_func(plane, polygon_points[_i]); | ||||
| PLANE_CLIP_POLYGON_COLLECT( | PLANE_CLIP_POLYGON_COLLECT( | ||||
| polygon_points[_i-1],polygon_points[_i], | polygon_points[_i - 1], polygon_points[_i], | ||||
| olddist, | olddist, | ||||
| dist, | dist, | ||||
| clipped, | clipped, | ||||
| clipped_count); | clipped_count); | ||||
| olddist = dist; | olddist = dist; | ||||
| } | } | ||||
| //RETURN TO FIRST point | //RETURN TO FIRST point | ||||
| PLANE_CLIP_POLYGON_COLLECT( | PLANE_CLIP_POLYGON_COLLECT( | ||||
| polygon_points[polygon_point_count-1],polygon_points[0], | polygon_points[polygon_point_count - 1], polygon_points[0], | ||||
| olddist, | olddist, | ||||
| firstdist, | firstdist, | ||||
| clipped, | clipped, | ||||
| clipped_count); | clipped_count); | ||||
| return clipped_count; | return clipped_count; | ||||
| } | } | ||||
| //! Clips a polygon by a plane | //! Clips a polygon by a plane | ||||
| /*! | /*! | ||||
| *\return The count of the clipped counts | *\return The count of the clipped counts | ||||
| */ | */ | ||||
| template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC> | template <typename CLASS_POINT, typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC> | ||||
| SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE_GENERIC( | SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE_GENERIC( | ||||
| const CLASS_PLANE & plane, | const CLASS_PLANE& plane, | ||||
| const CLASS_POINT & point0, | const CLASS_POINT& point0, | ||||
| const CLASS_POINT & point1, | const CLASS_POINT& point1, | ||||
| const CLASS_POINT & point2, | const CLASS_POINT& point2, | ||||
| CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func) | CLASS_POINT* clipped, DISTANCE_PLANE_FUNC distance_func) | ||||
| { | { | ||||
| GUINT clipped_count = 0; | GUINT clipped_count = 0; | ||||
| //clip first point | //clip first point | ||||
| GREAL firstdist = distance_func(plane,point0);; | GREAL firstdist = distance_func(plane, point0); | ||||
| ; | |||||
| if(!(firstdist>G_EPSILON)) | if (!(firstdist > G_EPSILON)) | ||||
| { | { | ||||
| VEC_COPY(clipped[clipped_count],point0); | VEC_COPY(clipped[clipped_count], point0); | ||||
| clipped_count++; | clipped_count++; | ||||
| } | } | ||||
| // point 1 | // point 1 | ||||
| GREAL olddist = firstdist; | GREAL olddist = firstdist; | ||||
| GREAL dist = distance_func(plane,point1); | GREAL dist = distance_func(plane, point1); | ||||
| PLANE_CLIP_POLYGON_COLLECT( | PLANE_CLIP_POLYGON_COLLECT( | ||||
| point0,point1, | point0, point1, | ||||
| olddist, | olddist, | ||||
| dist, | dist, | ||||
| clipped, | clipped, | ||||
| clipped_count); | clipped_count); | ||||
| olddist = dist; | olddist = dist; | ||||
| // point 2 | // point 2 | ||||
| dist = distance_func(plane,point2); | dist = distance_func(plane, point2); | ||||
| PLANE_CLIP_POLYGON_COLLECT( | PLANE_CLIP_POLYGON_COLLECT( | ||||
| point1,point2, | point1, point2, | ||||
| olddist, | olddist, | ||||
| dist, | dist, | ||||
| clipped, | clipped, | ||||
| clipped_count); | clipped_count); | ||||
| olddist = dist; | olddist = dist; | ||||
| //RETURN TO FIRST point | //RETURN TO FIRST point | ||||
| PLANE_CLIP_POLYGON_COLLECT( | PLANE_CLIP_POLYGON_COLLECT( | ||||
| point2,point0, | point2, point0, | ||||
| olddist, | olddist, | ||||
| firstdist, | firstdist, | ||||
| clipped, | clipped, | ||||
| clipped_count); | clipped_count); | ||||
| return clipped_count; | return clipped_count; | ||||
| } | } | ||||
| template<typename CLASS_POINT,typename CLASS_PLANE> | template <typename CLASS_POINT, typename CLASS_PLANE> | ||||
| SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON3D( | SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON3D( | ||||
| const CLASS_PLANE & plane, | const CLASS_PLANE& plane, | ||||
| const CLASS_POINT * polygon_points, | const CLASS_POINT* polygon_points, | ||||
| GUINT polygon_point_count, | GUINT polygon_point_count, | ||||
| CLASS_POINT * clipped) | CLASS_POINT* clipped) | ||||
| { | { | ||||
| return PLANE_CLIP_POLYGON_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,polygon_points,polygon_point_count,clipped,DISTANCE_PLANE_3D_FUNC()); | return PLANE_CLIP_POLYGON_GENERIC<CLASS_POINT, CLASS_PLANE>(plane, polygon_points, polygon_point_count, clipped, DISTANCE_PLANE_3D_FUNC()); | ||||
| } | } | ||||
| template<typename CLASS_POINT,typename CLASS_PLANE> | template <typename CLASS_POINT, typename CLASS_PLANE> | ||||
| SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE3D( | SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE3D( | ||||
| const CLASS_PLANE & plane, | const CLASS_PLANE& plane, | ||||
| const CLASS_POINT & point0, | const CLASS_POINT& point0, | ||||
| const CLASS_POINT & point1, | const CLASS_POINT& point1, | ||||
| const CLASS_POINT & point2, | const CLASS_POINT& point2, | ||||
| CLASS_POINT * clipped) | CLASS_POINT* clipped) | ||||
| { | { | ||||
| return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,point0,point1,point2,clipped,DISTANCE_PLANE_3D_FUNC()); | return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT, CLASS_PLANE>(plane, point0, point1, point2, clipped, DISTANCE_PLANE_3D_FUNC()); | ||||
| } | } | ||||
| #endif // GIM_TRI_COLLISION_H_INCLUDED | #endif // GIM_TRI_COLLISION_H_INCLUDED | ||||