CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
TriangleClipper.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
16
17namespace CeresEngine {
18
99
101 template<typename T> class TriangleClipper2D : public TriangleClipper<T> {
102 public:
105 const std::function<void(TVector2<T>*, TVector2<T>*, UInt32)>& writeCallback);
106
107 private:
110 void convertToMesh(const std::function<void(TVector2<T>*, TVector2<T>*, UInt32)>& writeCallback);
111
112 static const int BUFFER_SIZE = 64 * 3; // Must be a multiple of three
115 };
116
118 template<typename T> class TriangleClipper3D : public TriangleClipper<T> {
119 public:
122 const std::function<void(TVector3<T>*, TVector2<T>*, UInt32)>& writeCallback);
123
124 private:
127 void convertToMesh(const std::function<void(TVector3<T>*, TVector2<T>*, UInt32)>& writeCallback);
128
129 static const int BUFFER_SIZE = 64 * 3; // Must be a multiple of three
132 };
133
134 extern template class TriangleClipper<float>;
135 extern template class TriangleClipper2D<float>;
136 extern template class TriangleClipper3D<float>;
137
138 extern template class TriangleClipper<double>;
139 extern template class TriangleClipper2D<double>;
140 extern template class TriangleClipper3D<double>;
141
142} // namespace CeresEngine
Clips two-dimensional triangles against a set of provided planes.
Definition TriangleClipper.hpp:101
void clip(UInt8 *vertices, UInt8 *uvs, UInt32 numTris, UInt32 vertexStride, const Vector< TPlane< T > > &clipPlanes, const std::function< void(TVector2< T > *, TVector2< T > *, UInt32)> &writeCallback)
void convertToMesh(const std::function< void(TVector2< T > *, TVector2< T > *, UInt32)> &writeCallback)
Converts clipped vertices back into triangles and outputs them via the provided callback.
TVector2< T > vertexBuffer[BUFFER_SIZE]
Definition TriangleClipper.hpp:113
static const int BUFFER_SIZE
Definition TriangleClipper.hpp:112
TVector2< T > uvBuffer[BUFFER_SIZE]
Definition TriangleClipper.hpp:114
Clips three-dimensional triangles against a set of provided planes.
Definition TriangleClipper.hpp:118
void clip(UInt8 *vertices, UInt8 *uvs, UInt32 numTris, UInt32 vertexStride, const Vector< TPlane< T > > &clipPlanes, const std::function< void(TVector3< T > *, TVector2< T > *, UInt32)> &writeCallback)
TVector3< T > vertexBuffer[BUFFER_SIZE]
Definition TriangleClipper.hpp:130
void convertToMesh(const std::function< void(TVector3< T > *, TVector2< T > *, UInt32)> &writeCallback)
Converts clipped vertices back into triangles and outputs them via the provided callback.
static const int BUFFER_SIZE
Definition TriangleClipper.hpp:129
TVector2< T > uvBuffer[BUFFER_SIZE]
Definition TriangleClipper.hpp:131
Implementation from: http://www.geometrictools.com/Documentation/ClipMesh.pdf.
Definition TriangleClipper.hpp:20
void getOrderedFaces(Vector< Vector< UInt32 > > &sortedFaces)
Returns a set of non-culled vertex indices for every visible face in the mesh.
Int32 clipByPlane(const TPlane< T > &plane)
Clips the current mesh with the provided plane.
TVector3< T > getNormal(Vector< UInt32 > &sortedVertices, UInt32 numVertices)
Calculates the normal for vertices related to the provided vertex indices.
void processFaces()
Clips the faces (polygons) of the current mesh.
void getOrderedVertices(const ClipFace &face, Vector< UInt32 > &vertices)
Returns a set of ordered and non-culled vertices for the provided face of the mesh.
bool getOpenPolyline(ClipFace &face, UInt32 &start, UInt32 &end)
Checks is the polygon shape of the provided face open or closed.
Int32 processVertices(const TPlane< T > &plane)
Clips vertices of the current mesh by the provided plane.
void processEdges()
Clips edges of the current mesh.
ClipMesh mesh
Definition TriangleClipper.hpp:97
void addEdgesAndFaces()
Register all edges and faces, using the mesh vertices as a basis.
Definition Application.hpp:19
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::int32_t Int32
Definition DataTypes.hpp:21
std::uint8_t UInt8
Definition DataTypes.hpp:17
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Single edge in the clipped mesh.
Definition TriangleClipper.hpp:34
ClipEdge()
Definition TriangleClipper.hpp:35
bool visible
Definition TriangleClipper.hpp:39
UInt32 verts[2]
Definition TriangleClipper.hpp:37
Vector< UInt32 > faces
Definition TriangleClipper.hpp:38
Single polygon in the clipped mesh.
Definition TriangleClipper.hpp:43
Vector< UInt32 > edges
Definition TriangleClipper.hpp:46
bool visible
Definition TriangleClipper.hpp:47
ClipFace()
Definition TriangleClipper.hpp:44
TVector3< T > normal
Definition TriangleClipper.hpp:48
Contains vertices, edges and faces of the clipped mesh.
Definition TriangleClipper.hpp:52
Vector< ClipVert > verts
Definition TriangleClipper.hpp:55
Vector< ClipFace > faces
Definition TriangleClipper.hpp:57
ClipMesh()
Definition TriangleClipper.hpp:53
Vector< ClipEdge > edges
Definition TriangleClipper.hpp:56
Single vertex in the clipped mesh.
Definition TriangleClipper.hpp:23
T distance
Definition TriangleClipper.hpp:28
UInt32 occurs
Definition TriangleClipper.hpp:29
TVector2< T > uv
Definition TriangleClipper.hpp:27
TVector3< T > point
Definition TriangleClipper.hpp:26
bool visible
Definition TriangleClipper.hpp:30
ClipVert()
Definition TriangleClipper.hpp:24