diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-05-14 01:22:15 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-05-14 01:22:15 -0300 |
commit | b324ff7ea584676fcc3292808d7e7ea609982f8e (patch) | |
tree | b80e9aa0b8f2926a398e25ef904f6229cb3e28dd /core/math/geometry.h | |
parent | 45a509282e912d85c46b40974a2deb926be5be42 (diff) | |
download | redot-engine-b324ff7ea584676fcc3292808d7e7ea609982f8e.tar.gz |
A bit of everything:
-IMA-ADPCM support for samples, this means that sound effects can be compressed and use 4 timess less RAM.
-New 3D import workflow based on Wavefront OBJ. Import single objects as mesh resources instead of full scenes. Many people prefers to work this way. Just like the rest of the imported resources, these are updated in realtime if modified externally.
-Mesh resources now support naming surfaces. This helps reimporting to identify which user-created materials must be kept.
-Several fixes and improvements to SurfaceTool.
-Anti Aliasing added to WorldEnvironment effects (using FXAA)
-2D Physics bodies (RigidBody, KinematicBody, etc), Raycasts, Tilemap, etc support collision layers. This makes easy to group which objects collide against which.
-2D Trigger shapes can now also trigger collision reporting in other 2D bodies (it used to be in Area2D before)
-Viewport render target textures can now be filtered.
-Few fixes in GDscript make it easier to work with static functions and class members.
-Several and many bugfixes.
Diffstat (limited to 'core/math/geometry.h')
-rw-r--r-- | core/math/geometry.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/core/math/geometry.h b/core/math/geometry.h index 826e4697b5..5b21c25bec 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -695,6 +695,86 @@ public: } + + static inline Vector<Vector3> clip_polygon(const Vector<Vector3>& polygon,const Plane& p_plane) { + + enum LocationCache { + LOC_INSIDE=1, + LOC_BOUNDARY=0, + LOC_OUTSIDE=-1 + }; + + if (polygon.size()==0) + return polygon; + + int *location_cache = (int*)alloca(sizeof(int)*polygon.size()); + int inside_count = 0; + int outside_count = 0; + + for (int a = 0; a < polygon.size(); a++) { + //float p_plane.d = (*this) * polygon[a]; + float dist = p_plane.distance_to(polygon[a]); + if (dist <-CMP_POINT_IN_PLANE_EPSILON) { + location_cache[a] = LOC_INSIDE; + inside_count++; + } else { + if (dist > CMP_POINT_IN_PLANE_EPSILON) { + location_cache[a] = LOC_OUTSIDE; + outside_count++; + } else { + location_cache[a] = LOC_BOUNDARY; + } + } + } + + if (outside_count == 0) { + + return polygon; // no changes + + } else if (inside_count == 0) { + + return Vector<Vector3>(); //empty + } + +// long count = 0; + long previous = polygon.size() - 1; + + Vector<Vector3> clipped; + + for (int index = 0; index < polygon.size(); index++) { + int loc = location_cache[index]; + if (loc == LOC_OUTSIDE) { + if (location_cache[previous] == LOC_INSIDE) { + const Vector3& v1 = polygon[previous]; + const Vector3& v2 = polygon[index]; + + Vector3 segment= v1 - v2; + double den=p_plane.normal.dot( segment ); + double dist=p_plane.distance_to( v1 ) / den; + dist=-dist; + clipped.push_back( v1 + segment * dist ); + } + } else { + const Vector3& v1 = polygon[index]; + if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) { + const Vector3& v2 = polygon[previous]; + Vector3 segment= v1 - v2; + double den=p_plane.normal.dot( segment ); + double dist=p_plane.distance_to( v1 ) / den; + dist=-dist; + clipped.push_back( v1 + segment * dist ); + } + + clipped.push_back(v1); + } + + previous = index; + } + + return clipped; + } + + static Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon) { Vector<int> triangles; |