1#ifndef GIM_CLIP_POLYGON_H_INCLUDED
2#define GIM_CLIP_POLYGON_H_INCLUDED
40 template <
typename CLASS_POINT,
typename CLASS_PLANE>
47template <
typename CLASS_POINT>
49 const CLASS_POINT& point0,
50 const CLASS_POINT& point1,
58 if (_classif != _prevclassif)
60 GREAL blendfactor = -dist0 / (dist1 - dist0);
61 VEC_BLEND(clipped[clipped_count], point0, point1, blendfactor);
66 VEC_COPY(clipped[clipped_count], point1);
75template <
typename CLASS_POINT,
typename CLASS_PLANE,
typename DISTANCE_PLANE_FUNC>
77 const CLASS_PLANE& plane,
78 const CLASS_POINT* polygon_points,
79 GUINT polygon_point_count,
80 CLASS_POINT* clipped, DISTANCE_PLANE_FUNC distance_func)
82 GUINT clipped_count = 0;
85 GREAL firstdist = distance_func(plane, polygon_points[0]);
89 VEC_COPY(clipped[clipped_count], polygon_points[0]);
93 GREAL olddist = firstdist;
94 for (
GUINT _i = 1; _i < polygon_point_count; _i++)
96 GREAL dist = distance_func(plane, polygon_points[_i]);
99 polygon_points[_i - 1], polygon_points[_i],
111 polygon_points[polygon_point_count - 1], polygon_points[0],
117 return clipped_count;
124template <
typename CLASS_POINT,
typename CLASS_PLANE,
typename DISTANCE_PLANE_FUNC>
126 const CLASS_PLANE& plane,
127 const CLASS_POINT& point0,
128 const CLASS_POINT& point1,
129 const CLASS_POINT& point2,
130 CLASS_POINT* clipped, DISTANCE_PLANE_FUNC distance_func)
132 GUINT clipped_count = 0;
135 GREAL firstdist = distance_func(plane, point0);
139 VEC_COPY(clipped[clipped_count], point0);
144 GREAL olddist = firstdist;
145 GREAL dist = distance_func(plane, point1);
157 dist = distance_func(plane, point2);
175 return clipped_count;
178template <
typename CLASS_POINT,
typename CLASS_PLANE>
180 const CLASS_PLANE& plane,
181 const CLASS_POINT* polygon_points,
182 GUINT polygon_point_count,
183 CLASS_POINT* clipped)
185 return PLANE_CLIP_POLYGON_GENERIC<CLASS_POINT, CLASS_PLANE>(plane, polygon_points, polygon_point_count, clipped,
DISTANCE_PLANE_3D_FUNC());
188template <
typename CLASS_POINT,
typename CLASS_PLANE>
190 const CLASS_PLANE& plane,
191 const CLASS_POINT& point0,
192 const CLASS_POINT& point1,
193 const CLASS_POINT& point2,
194 CLASS_POINT* clipped)
196 return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT, CLASS_PLANE>(plane, point0, point1, point2, clipped,
DISTANCE_PLANE_3D_FUNC());
#define SIMD_FORCE_INLINE
This function calcs the distance from a 3D plane.
GREAL operator()(const CLASS_PLANE &plane, const CLASS_POINT &point)
#define DISTANCE_PLANE_POINT(plane, point)
GUINT PLANE_CLIP_POLYGON3D(const CLASS_PLANE &plane, const CLASS_POINT *polygon_points, GUINT polygon_point_count, CLASS_POINT *clipped)
GUINT PLANE_CLIP_POLYGON_GENERIC(const CLASS_PLANE &plane, const CLASS_POINT *polygon_points, GUINT polygon_point_count, CLASS_POINT *clipped, DISTANCE_PLANE_FUNC distance_func)
Clips a polygon by a plane.
GUINT PLANE_CLIP_TRIANGLE3D(const CLASS_PLANE &plane, const CLASS_POINT &point0, const CLASS_POINT &point1, const CLASS_POINT &point2, CLASS_POINT *clipped)
GUINT PLANE_CLIP_TRIANGLE_GENERIC(const CLASS_PLANE &plane, const CLASS_POINT &point0, const CLASS_POINT &point1, const CLASS_POINT &point2, CLASS_POINT *clipped, DISTANCE_PLANE_FUNC distance_func)
Clips a polygon by a plane.
void PLANE_CLIP_POLYGON_COLLECT(const CLASS_POINT &point0, const CLASS_POINT &point1, GREAL dist0, GREAL dist1, CLASS_POINT *clipped, GUINT &clipped_count)
#define VEC_COPY(b, a)
Copy 3D vector.
#define VEC_BLEND(vr, a, b, s)