1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsPrerequisites.h" |
6 | #include "Image/BsColor.h" |
7 | #include "Math/BsAABox.h" |
8 | #include "Math/BsRect3.h" |
9 | |
10 | namespace bs |
11 | { |
12 | /** @addtogroup Utility-Engine |
13 | * @{ |
14 | */ |
15 | |
16 | /** Helper class for easily creating common 3D shapes. */ |
17 | class BS_EXPORT ShapeMeshes3D |
18 | { |
19 | public: |
20 | /** |
21 | * Fills the mesh data with vertices representing an outline of axis aligned box. |
22 | * |
23 | * @param[in] box Axis aligned box to create the mesh data for |
24 | * @param[in, out] meshData Mesh data that will be populated. |
25 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
26 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
27 | * |
28 | * @note |
29 | * Provided MeshData must have some specific elements at least: |
30 | * Vector3 VES_POSITION |
31 | * 32bit index buffer |
32 | * Enough space for 8 vertices and 24 indices |
33 | * @note |
34 | * Primitives are output in the form of a line list. |
35 | */ |
36 | static void wireAABox(const AABox& box, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
37 | |
38 | /** |
39 | * Fills the mesh data with vertices representing a solid axis aligned box. |
40 | * |
41 | * @param[in] box Axis aligned box to create the mesh data for |
42 | * @param[in, out] meshData Mesh data that will be populated. |
43 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
44 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
45 | * |
46 | * @note |
47 | * Provided MeshData must have some specific elements at least: |
48 | * Vector3 VES_POSITION |
49 | * Vector3 VES_NORMAL |
50 | * 32bit index buffer |
51 | * Enough space for 24 vertices and 36 indices |
52 | * Optionally it may also have: |
53 | * Vector2 VES_TEXCOORD |
54 | * Vector4 VES_TANGENT |
55 | * @note |
56 | * Primitives are output in the form of a triangle list. |
57 | */ |
58 | static void solidAABox(const AABox& box, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
59 | |
60 | /** |
61 | * Fills the mesh data with vertices representing an outline of a sphere. |
62 | * |
63 | * @param[in] sphere Sphere to get the mesh data for |
64 | * @param[in, out] meshData Mesh data that will be populated. |
65 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
66 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
67 | * @param[in] quality Represents the level of tessellation the sphere will have. Higher level means |
68 | * higher quality but also more vertices and primitives. |
69 | * |
70 | * @note |
71 | * Provided MeshData must have some specific elements at least: |
72 | * Vector3 VES_POSITION |
73 | * 32bit index buffer |
74 | * Enough space for 3 * ((quality + 1) * 5) vertices |
75 | * Enough space for 6 * ((quality + 1) * 5 - 1) indices |
76 | * @note |
77 | * Primitives are output in the form of a line list. |
78 | */ |
79 | static void wireSphere(const Sphere& sphere, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, |
80 | UINT32 quality = 10); |
81 | |
82 | /** |
83 | * Fills the mesh data with vertices representing an outline of a hemisphere. |
84 | * |
85 | * @param[in] sphere Sphere to get the mesh data for |
86 | * @param[in, out] meshData Mesh data that will be populated. |
87 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
88 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
89 | * @param[in] quality Represents the level of tessellation the sphere will have. Higher level means |
90 | * higher quality but also more vertices and primitives. |
91 | * |
92 | * @note |
93 | * Provided MeshData must have some specific elements at least: |
94 | * Vector3 VES_POSITION |
95 | * 32bit index buffer |
96 | * Enough space for 3 * ((quality + 1) * 5) vertices |
97 | * Enough space for 6 * ((quality + 1) * 5 - 1) indices |
98 | * @note |
99 | * Primitives are output in the form of a line list. |
100 | */ |
101 | static void wireHemisphere(const Sphere& sphere, const SPtr<MeshData>& meshData, UINT32 vertexOffset, |
102 | UINT32 indexOffset, UINT32 quality = 10); |
103 | |
104 | /** |
105 | * Fills the mesh data with vertices representing a sphere. |
106 | * |
107 | * @param[in] sphere Sphere to get the mesh data for |
108 | * @param[in, out] meshData Mesh data that will be populated. |
109 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
110 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
111 | * @param[in] quality Represents the level of tessellation the sphere will have. Higher level means |
112 | * higher quality but also more vertices and primitives. |
113 | * |
114 | * @note |
115 | * Provided MeshData must have some specific elements at least: |
116 | * Vector3 VES_POSITION |
117 | * Vector3 VES_NORMAL |
118 | * 32bit index buffer |
119 | * Enough space for 20 * (4 * (3 ^ quality)) vertices |
120 | * Enough space for 20 * (4 * (3 ^ quality)) indices |
121 | * Optionally it may also have: |
122 | * Vector2 VES_TEXCOORD |
123 | * Vector4 VES_TANGENT |
124 | * @note |
125 | * Primitives are output in the form of a triangle list. |
126 | */ |
127 | static void solidSphere(const Sphere& sphere, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, |
128 | UINT32 quality = 1); |
129 | |
130 | /** |
131 | * Fills the mesh data with vertices representing an outline of an arc. |
132 | * |
133 | * @param[in] center Center of the arc to generate geometry for. |
134 | * @param[in] radius Radius of the arc to generate geometry for. |
135 | * @param[in] normal Normal around which the arc is generated. Arc geometry will be perpendicular |
136 | * to the normal. |
137 | * @param[in] startAngle Angle at which the arc starts. |
138 | * @param[in] amountAngle Angle that the arc spans. |
139 | * @param[in, out] meshData Mesh data that will be populated. |
140 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
141 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
142 | * @param[in] quality Represents the level of tessellation the arc will have. Higher level means |
143 | * higher quality but also more vertices and primitives. |
144 | * |
145 | * @note |
146 | * Provided MeshData must have some specific elements at least: |
147 | * Vector3 VES_POSITION |
148 | * 32bit index buffer |
149 | * Enough space for ((quality + 1) * 5) vertices |
150 | * Enough space for (((quality + 1) * 5 - 1) * 2) indices |
151 | * @note |
152 | * Primitives are output in the form of a line list. |
153 | */ |
154 | static void wireArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle, |
155 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
156 | |
157 | /** |
158 | * Fills the mesh data with vertices representing a solid double-sided arc. |
159 | * |
160 | * @param[in] center Center of the arc to generate geometry for. |
161 | * @param[in] radius Radius of the arc to generate geometry for. |
162 | * @param[in] normal Normal around which the arc is generated. Arc geometry will be perpendicular to |
163 | * the normal. |
164 | * @param[in] startAngle Angle at which the arc starts. |
165 | * @param[in] amountAngle Angle that the arc spans. |
166 | * @param[in, out] meshData Mesh data that will be populated. |
167 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
168 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
169 | * @param[in] quality Represents the level of tessellation the arc will have. Higher level means higher |
170 | * quality but also more vertices and primitives. |
171 | * |
172 | * @note |
173 | * Provided MeshData must have some specific elements at least: |
174 | * Vector3 VES_POSITION |
175 | * Vector3 VES_NORMAL |
176 | * 32bit index buffer |
177 | * Enough space for ((quality + 1) * 5 + 1) * 2 vertices |
178 | * Enough space for (((quality + 1) * 5 - 1) * 6) indices |
179 | * Optionally it may also have: |
180 | * Vector2 VES_TEXCOORD |
181 | * Vector4 VES_TANGENT |
182 | * @note |
183 | * Primitives are output in the form of a triangle list. |
184 | */ |
185 | static void solidArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle, |
186 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
187 | |
188 | /** |
189 | * Fills the mesh data with vertices representing an outline of a disc. |
190 | * |
191 | * @param[in] center Center of the disc to generate geometry for. |
192 | * @param[in] radius Radius of the disc to generate geometry for. |
193 | * @param[in] normal Normal around which the disc is generated. Disc geometry will be perpendicular |
194 | * to the normal. |
195 | * @param[in, out] meshData Mesh data that will be populated. |
196 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
197 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
198 | * @param[in] quality Represents the level of tessellation the disc will have. Higher level means |
199 | * higher quality but also more vertices and primitives. |
200 | * |
201 | * @note |
202 | * Provided MeshData must have some specific elements at least: |
203 | * Vector3 VES_POSITION |
204 | * 32bit index buffer |
205 | * Enough space for ((quality + 1) * 5) vertices |
206 | * Enough space for (((quality + 1) * 5 - 1) * 2) indices |
207 | * @note |
208 | * Primitives are output in the form of a line list. |
209 | */ |
210 | static void wireDisc(const Vector3& center, float radius, const Vector3& normal, const SPtr<MeshData>& meshData, |
211 | UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
212 | |
213 | /** |
214 | * Fills the mesh data with vertices representing a solid double-sided disc. |
215 | * |
216 | * @param[in] center Center of the disc to generate geometry for. |
217 | * @param[in] radius Radius of the disc to generate geometry for. |
218 | * @param[in] normal Normal around which the disc is generated. Disc geometry will be perpendicular |
219 | * to the normal. |
220 | * @param[in, out] meshData Mesh data that will be populated. |
221 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
222 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
223 | * @param[in] quality Represents the level of tessellation the disc will have. Higher level means higher |
224 | * quality but also more vertices and primitives. |
225 | * |
226 | * @note |
227 | * Provided MeshData must have some specific elements at least: |
228 | * Vector3 VES_POSITION |
229 | * Vector3 VES_NORMAL |
230 | * 32bit index buffer |
231 | * Enough space for ((quality + 1) * 5 + 1) * 2 vertices |
232 | * Enough space for (((quality + 1) * 5 - 1) * 6) indices |
233 | * @note |
234 | * Primitives are output in the form of a triangle list. |
235 | */ |
236 | static void solidDisc(const Vector3& center, float radius, const Vector3& normal, const SPtr<MeshData>& meshData, |
237 | UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
238 | |
239 | /** |
240 | * Fills the mesh data with vertices representing an outline of an camera frustum. Frustum will be facing -z and be |
241 | * positioned at world origin. |
242 | * |
243 | * @param[in] position Starting point for the frustum. |
244 | * @param[in] aspect Aspect ratio (width / height). |
245 | * @param[in] FOV Horizontal field of view angle. |
246 | * @param[in] near Distance to near clipping plane. |
247 | * @param[in] far Distance to far clipping plane. |
248 | * @param[in, out] meshData Mesh data that will be populated. |
249 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
250 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
251 | * |
252 | * @note |
253 | * Provided MeshData must have some specific elements at least: |
254 | * Vector3 VES_POSITION |
255 | * 32bit index buffer |
256 | * Enough space for 8 vertices and 24 indices |
257 | * @note |
258 | * Primitives are output in the form of a line list. |
259 | */ |
260 | static void wireFrustum(const Vector3& position, float aspect, Degree FOV, float near, float far, |
261 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
262 | |
263 | /** |
264 | * Fills the mesh data with vertices representing a wireframe cone. |
265 | * |
266 | * @param[in] base World position of the cone base. |
267 | * @param[in] normal Direction of the pointed part of the cone. |
268 | * @param[in] height Cone height (distance from base to the top). |
269 | * @param[in] radius Cone radius (distance from base center to outer edge). |
270 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cones. |
271 | * @param[in, out] meshData Mesh data that will be populated. |
272 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
273 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
274 | * @param[in] quality Represents the level of tessellation the cone will have. Higher level means |
275 | * higher quality but also more vertices and primitives. |
276 | * |
277 | * @note |
278 | * Provided MeshData must have some specific elements at least: |
279 | * Vector3 VES_POSITION |
280 | * 32bit index buffer |
281 | * Enough space for ((quality + 1) * 4 + 5) vertices |
282 | * Enough space for (((quality + 1) * 4 + 4) * 2) indices |
283 | * @note |
284 | * Primitives are output in the form of a line list. |
285 | */ |
286 | static void wireCone(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
287 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
288 | |
289 | /** |
290 | * Fills the mesh data with vertices representing a solid cone. |
291 | * |
292 | * @param[in] base World position of the cone base. |
293 | * @param[in] normal Direction of the pointed part of the cone. |
294 | * @param[in] height Cone height (distance from base to the top). |
295 | * @param[in] radius Cone radius (distance from base center to outer edge). |
296 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cones. |
297 | * @param[in, out] meshData Mesh data that will be populated. |
298 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
299 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
300 | * @param[in] quality Represents the level of tessellation the cone will have. Higher level means |
301 | * higher quality but also more vertices and primitives. |
302 | * |
303 | * @note |
304 | * Provided MeshData must have some specific elements at least: |
305 | * Vector3 VES_POSITION |
306 | * Vector3 VES_NORMAL |
307 | * 32bit index buffer |
308 | * Enough space for ((quality + 1) * 4) * 3 + 1 vertices |
309 | * Enough space for (((quality + 1) * 4) * 6) indices |
310 | * Optionally it may also have: |
311 | * Vector2 VES_TEXCOORD |
312 | * Vector4 VES_TANGENT |
313 | * @note |
314 | * Primitives are output in the form of a triangle list. |
315 | */ |
316 | static void solidCone(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
317 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
318 | |
319 | /** |
320 | * Fills the mesh data with vertices representing a wireframe cylinder. |
321 | * |
322 | * @param[in] base World position of the cylinder base. |
323 | * @param[in] normal Orientation of the cylinder (height gets applied in this direction). |
324 | * @param[in] height Cylinder height (distance from base to the top). |
325 | * @param[in] radius Cylinder radius (distance from base center to outer edge). |
326 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cylinders. |
327 | * @param[in, out] meshData Mesh data that will be populated. |
328 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
329 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
330 | * @param[in] quality Represents the level of tessellation the cylinder will have. Higher level means |
331 | * higher quality but also more vertices and primitives. |
332 | * |
333 | * @note |
334 | * Provided MeshData must have some specific elements at least: |
335 | * Vector3 VES_POSITION |
336 | * 32bit index buffer |
337 | * Enough space for ((quality + 1) * 4) * 2) vertices |
338 | * Enough space for ((quality + 1) * 4) * 6) indices |
339 | * @note |
340 | * Primitives are output in the form of a line list. |
341 | */ |
342 | static void wireCylinder(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
343 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
344 | |
345 | /** |
346 | * Fills the mesh data with vertices representing a solid cylinder. |
347 | * |
348 | * @param[in] base World position of the cylinder base. |
349 | * @param[in] normal Orientation of the cylinder (height gets applied in this direction). |
350 | * @param[in] height Cylinder height (distance from base to the top). |
351 | * @param[in] radius Cylinder radius (distance from base center to outer edge). |
352 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cylinders. |
353 | * @param[in, out] meshData Mesh data that will be populated. |
354 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
355 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
356 | * @param[in] quality Represents the level of tessellation the cylinder will have. Higher level means |
357 | * higher quality but also more vertices and primitives. |
358 | * |
359 | * @note |
360 | * Provided MeshData must have some specific elements at least: |
361 | * Vector3 VES_POSITION |
362 | * Vector3 VES_NORMAL |
363 | * 32bit index buffer |
364 | * Enough space for ((quality + 1) * 4 + 1) * 4) vertices |
365 | * Enough space for ((quality + 1) * 4) * 12) indices |
366 | * Optionally it may also have: |
367 | * Vector2 VES_TEXCOORD |
368 | * Vector4 VES_TANGENT |
369 | * @note |
370 | * Primitives are output in the form of a triangle list. |
371 | */ |
372 | static void solidCylinder(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
373 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset, UINT32 quality = 10); |
374 | |
375 | /** |
376 | * Fills the mesh data with vertices representing a quad (4 triangles, two sided). |
377 | * |
378 | * @param[in] area Area in which to draw the quad. |
379 | * @param[in, out] meshData Mesh data that will be populated. |
380 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
381 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
382 | * |
383 | * @note |
384 | * Provided MeshData must have some specific elements at least: |
385 | * Vector3 VES_POSITION |
386 | * Vector3 VES_NORMAL |
387 | * 32bit index buffer |
388 | * Enough space for 8 vertices and 12 indices |
389 | * Optionally it may also have: |
390 | * Vector2 VES_TEXCOORD |
391 | * Vector4 VES_TANGENT |
392 | * @note |
393 | * Primitives are output in the form of a triangle list. |
394 | */ |
395 | static void solidQuad(const Rect3& area, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
396 | |
397 | /** |
398 | * Fills the mesh data with vertices representing a per-pixel line. |
399 | * |
400 | * @param[in] a Start point of the line. |
401 | * @param[in] b End point of the line. |
402 | * @param[in, out] meshData Mesh data that will be populated. |
403 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
404 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
405 | * |
406 | * @note |
407 | * Provided MeshData must have some specific elements at least: |
408 | * Vector3 VES_POSITION |
409 | * 32bit index buffer |
410 | * Enough space for 2 vertices and 2 indices |
411 | * @note |
412 | * Primitives are output in the form of a line list. |
413 | */ |
414 | static void pixelLine(const Vector3& a, const Vector3& b, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
415 | |
416 | /** |
417 | * Fills the mesh data with vertices representing an anti-aliased line of specific width. Antialiasing is done |
418 | * using alpha blending. |
419 | * |
420 | * @param[in] a Start point of the line. |
421 | * @param[in] b End point of the line. |
422 | * @param[in] up Up direction to which the line will run perpendicular to. |
423 | * @param[in] width Width of the line. |
424 | * @param[in] borderWidth Width of the anti-aliased border. |
425 | * @param[in] color Color of the line. |
426 | * @param[in, out] meshData Mesh data that will be populated by this method. |
427 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
428 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
429 | * |
430 | * @note |
431 | * Provided MeshData must have some specific elements at least: |
432 | * Vector3 VES_POSITION |
433 | * UINT32 VES_COLOR |
434 | * 32bit index buffer |
435 | * Enough space for 8 vertices and 30 indices |
436 | * @note |
437 | * Primitives are output in the form of a triangle list. |
438 | */ |
439 | static void antialiasedLine(const Vector3& a, const Vector3& b, const Vector3& up, float width, float borderWidth, const Color& color, |
440 | const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
441 | |
442 | /** |
443 | * Fills the mesh data with vertices representing per-pixel lines. |
444 | * |
445 | * @param[in] linePoints A list of start and end points for the lines. Must be a multiple of 2. |
446 | * @param[in, out] meshData Mesh data that will be populated. |
447 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
448 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
449 | * |
450 | * @note |
451 | * Provided MeshData must have some specific elements at least: |
452 | * Vector3 VES_POSITION |
453 | * 32bit index buffer |
454 | * Enough space for (numLines * 2) vertices and (numLines * 2) indices |
455 | * @note |
456 | * Primitives are output in the form of a line list. |
457 | */ |
458 | static void pixelLineList(const Vector<Vector3>& linePoints, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
459 | |
460 | /** |
461 | * Fills the mesh data with vertices representing anti-aliased lines of specific width. Antialiasing is done using |
462 | * alpha blending. |
463 | * |
464 | * @param[in] linePoints A list of start and end points for the lines. Must be a multiple of 2. |
465 | * @param[in] up Up direction to which the line will run perpendicular to. |
466 | * @param[in] width Width of the line. |
467 | * @param[in] borderWidth Width of the anti-aliased border. |
468 | * @param[in] color Color of the line. |
469 | * @param[in, out] meshData Mesh data that will be populated by this method. |
470 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
471 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
472 | * |
473 | * @note |
474 | * Provided MeshData must have some specific elements at least: |
475 | * Vector3 VES_POSITION |
476 | * UINT32 VES_COLOR |
477 | * 32bit index buffer |
478 | * Enough space for (numLines * 8) vertices and (numLines * 30) indices |
479 | * @note |
480 | * Primitives are output in the form of a triangle list. |
481 | */ |
482 | static void antialiasedLineList(const Vector<Vector3>& linePoints, const Vector3& up, float width, float borderWidth, |
483 | const Color& color, const SPtr<MeshData>& meshData, UINT32 vertexOffset, UINT32 indexOffset); |
484 | |
485 | /** |
486 | * Fills the provided buffers with position and index data representing an outline of an axis aligned box. Use |
487 | * getNumElementsWireAABox() to determine the required sizes of the output buffers. |
488 | * |
489 | * @param[in] box Box to create geometry for. |
490 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
491 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
492 | * @param[in] vertexStride Size of a single vertex, in bytes. |
493 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
494 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
495 | */ |
496 | static void wireAABox(const AABox& box, UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, |
497 | UINT32* outIndices, UINT32 indexOffset); |
498 | |
499 | /** |
500 | * Fills the provided buffers with position and index data representing a solid axis aligned box. Use |
501 | * getNumElementsAABox() to determine the required sizes of the output buffers. |
502 | * |
503 | * @param[in] box Box to create geometry for. |
504 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
505 | * @param[out] outNormals Pre-allocated output buffer that will store the vertex normal data. |
506 | * @param[out] outUV Pre-allocated output buffer that will store the vertex UV data. Set to null if not |
507 | * required. |
508 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
509 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
510 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
511 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
512 | */ |
513 | static void solidAABox(const AABox& box, UINT8* outVertices, UINT8* outNormals, UINT8* outUV, UINT32 vertexOffset, |
514 | UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
515 | |
516 | /** |
517 | * Fills the provided buffers with position and index data representing a sphere. Use getNumElementsSphere() to |
518 | * determine the required sizes of the output buffers. |
519 | * |
520 | * @param[in] sphere Sphere to create geometry for. |
521 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
522 | * @param[out] outNormals Pre-allocated output buffer that will store the vertex normal data. Can be null if |
523 | * normals aren't needed. |
524 | * @param[out] outUV Pre-allocated output buffer that will store the vertex UV data. Set to null if not |
525 | * required. |
526 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
527 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
528 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
529 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
530 | * @param[in] quality Represents the level of tessellation the sphere will have. Higher level means higher |
531 | * quality but also more vertices and primitives. |
532 | */ |
533 | static void solidSphere(const Sphere& sphere, UINT8* outVertices, UINT8* outNormals, UINT8* outUV, |
534 | UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality); |
535 | |
536 | /** |
537 | * Fills the provided buffers with position and index data representing an outline of an arc. Use |
538 | * getNumElementWiresArc() to determine the required sizes of the output buffers. |
539 | * |
540 | * @param[in] center Center of the arc to generate geometry for. |
541 | * @param[in] radius Radius of the arc to generate geometry for. |
542 | * @param[in] normal Normal around which the arc is generated. Arc geometry will be perpendicular to the |
543 | * normal. |
544 | * @param[in] startAngle Angle at which the arc starts. |
545 | * @param[in] amountAngle Angle that the arc spans. |
546 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
547 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
548 | * @param[in] vertexStride Size of a single vertex, in bytes. |
549 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
550 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
551 | * @param[in] quality Represents the level of tessellation the arc will have. Higher level means higher |
552 | * quality but also more vertices and primitives. |
553 | */ |
554 | static void wireArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle, |
555 | UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality); |
556 | |
557 | /** |
558 | * Fills the provided buffers with position and index data representing a solid arc. Use getNumElementsArc() to |
559 | * determine the required sizes of the output buffers. |
560 | * |
561 | * @param[in] center Center of the arc to generate geometry for. |
562 | * @param[in] radius Radius of the arc to generate geometry for. |
563 | * @param[in] normal Normal around which the arc is generated. Arc geometry will be perpendicular to the |
564 | * normal. |
565 | * @param[in] startAngle Angle at which the arc starts. |
566 | * @param[in] amountAngle Angle that the arc spans. |
567 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
568 | * @param[out] outNormals Pre-allocated output buffer that will store the vertex normal data. |
569 | * @param[out] outUV Pre-allocated output buffer that will store the vertex UV data. Set to null if not |
570 | * required. |
571 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
572 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
573 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
574 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
575 | * @param[in] quality Represents the level of tessellation the arc will have. Higher level means higher |
576 | * quality but also more vertices and primitives. |
577 | */ |
578 | static void solidArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, |
579 | Degree amountAngle, UINT8* outVertices, UINT8* outNormals, UINT8* outUV, UINT32 vertexOffset, |
580 | UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality); |
581 | |
582 | /** |
583 | * Fills the provided buffers with position and index data representing an outline of a camera frustum. Use |
584 | * getNumElementsFrustum() to determine the required sizes of the output buffers. |
585 | * |
586 | * @param[in] position Starting point for the frustum. |
587 | * @param[in] aspect Aspect ratio (width / height). |
588 | * @param[in] FOV Horizontal field of view angle. |
589 | * @param[in] near Distance to near clipping plane. |
590 | * @param[in] far Distance to far clipping plane. |
591 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
592 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
593 | * @param[in] vertexStride Size of a single vertex, in bytes. |
594 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
595 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
596 | */ |
597 | static void wireFrustum(const Vector3& position, float aspect, Degree FOV, float near, float far, |
598 | UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
599 | |
600 | /** |
601 | * Fills the provided buffers with position and index data representing a solid cone. Use getNumElementsCone() to |
602 | * determine the required sizes of the output buffers. |
603 | * |
604 | * @param[in] base World position of the cone base. |
605 | * @param[in] normal Direction of the pointed part of the cone. |
606 | * @param[in] height Cone height (distance from base to the top). |
607 | * @param[in] radius Cone radius (distance from base center to outer edge). |
608 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cones. |
609 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
610 | * @param[out] outNormals Pre-allocated output buffer that will store the vertex normal data. Can be null if |
611 | * normals aren't needed. |
612 | * @param[out] outUV Pre-allocated output buffer that will store the vertex UV data. Set to null if not |
613 | * required. |
614 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
615 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
616 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
617 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
618 | * @param[in] quality Represents the level of tessellation the cone will have. Higher level means higher |
619 | * quality but also more vertices and primitives. |
620 | */ |
621 | static void solidCone(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
622 | UINT8* outVertices, UINT8* outNormals, UINT8* outUV, UINT32 vertexOffset, UINT32 vertexStride, |
623 | UINT32* outIndices, UINT32 indexOffset, UINT32 quality); |
624 | |
625 | /** |
626 | * Fills the provided buffers with position and index data representing a wire cone. Use getNumElementsWireCone() to |
627 | * determine the required sizes of the output buffers. |
628 | * |
629 | * @param[in] base World position of the cone base. |
630 | * @param[in] normal Direction of the pointed part of the cone. |
631 | * @param[in] height Cone height (distance from base to the top). |
632 | * @param[in] radius Cone radius (distance from base center to outer edge). |
633 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cones. |
634 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
635 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
636 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
637 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
638 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
639 | * @param[in] quality Represents the level of tessellation the cone will have. Higher level means higher |
640 | * quality but also more vertices and primitives. |
641 | */ |
642 | static void wireCone(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
643 | UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, |
644 | UINT32 quality); |
645 | |
646 | /** |
647 | * Fills the provided buffers with position and index data representing a solid cylinder. Use getNumElementsCylinder() to |
648 | * determine the required sizes of the output buffers. |
649 | * |
650 | * @param[in] base World position of the cylinder base. |
651 | * @param[in] normal Orientation of the cylinder (height gets applied in this direction). |
652 | * @param[in] height Cylinder height (distance from base to the top). |
653 | * @param[in] radius Cylinder radius (distance from base center to outer edge). |
654 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cylinders. |
655 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
656 | * @param[out] outNormals Pre-allocated output buffer that will store the vertex normal data. Can be null if |
657 | * normals aren't needed. |
658 | * @param[out] outUV Pre-allocated output buffer that will store the vertex UV data. Set to null if not |
659 | * required. |
660 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
661 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
662 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
663 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
664 | * @param[in] quality Represents the level of tessellation the cylinder will have. Higher level means higher |
665 | * quality but also more vertices and primitives. |
666 | */ |
667 | static void solidCylinder(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
668 | UINT8* outVertices, UINT8* outNormals, UINT8* outUV, UINT32 vertexOffset, UINT32 vertexStride, |
669 | UINT32* outIndices, UINT32 indexOffset, UINT32 quality); |
670 | |
671 | /** |
672 | * Fills the provided buffers with position and index data representing a wire cylinder. Use getNumElementsWireCylinder() to |
673 | * determine the required sizes of the output buffers. |
674 | * |
675 | * @param[in] base World position of the cylinder base. |
676 | * @param[in] normal Orientation of the cylinder (height gets applied in this direction). |
677 | * @param[in] height Cylinder height (distance from base to the top). |
678 | * @param[in] radius Cylinder radius (distance from base center to outer edge). |
679 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical cylinders. |
680 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
681 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
682 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
683 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
684 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
685 | * @param[in] quality Represents the level of tessellation the cylinder will have. Higher level means higher |
686 | * quality but also more vertices and primitives. |
687 | */ |
688 | static void wireCylinder(const Vector3& base, const Vector3& normal, float height, float radius, Vector2 scale, |
689 | UINT8* outVertices, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, |
690 | UINT32 quality); |
691 | |
692 | /** |
693 | * Fills the provided buffers with position and index data representing a solid quad. Use getNumElementsQuad() to |
694 | * determine the required sizes of the output buffers. |
695 | * |
696 | * @param[in] area Area covered by the quad. |
697 | * @param[out] outVertices Pre-allocated output buffer that will store the vertex position data. |
698 | * @param[out] outNormals Pre-allocated output buffer that will store the vertex normal data. |
699 | * @param[out] outUV Pre-allocated output buffer that will store the vertex UV data. Set to null if not |
700 | * required. |
701 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
702 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and normal buffer) |
703 | * @param[out] outIndices Pre-allocated output buffer that will store the index data. Indices are 32bit. |
704 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
705 | */ |
706 | static void solidQuad(const Rect3& area, UINT8* outVertices, UINT8* outNormals, UINT8* outUV, UINT32 vertexOffset, |
707 | UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
708 | |
709 | /** Calculates number of vertices and indices required for geometry of a solid axis aligned box. */ |
710 | static void getNumElementsAABox(UINT32& numVertices, UINT32& numIndices); |
711 | |
712 | /** Calculates number of vertices and indices required for geometry of a wireframe axis aligned box. */ |
713 | static void getNumElementsWireAABox(UINT32& numVertices, UINT32& numIndices); |
714 | |
715 | /** Calculates number of vertices and indices required for geometry of a solid sphere of the specified quality. */ |
716 | static void getNumElementsSphere(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
717 | |
718 | /** Calculates number of vertices and indices required for geometry of a wire sphere of the specified quality. */ |
719 | static void getNumElementsWireSphere(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
720 | |
721 | /** Calculates number of vertices and indices required for geometry of a wire hemisphere of the specified quality. */ |
722 | static void getNumElementsWireHemisphere(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
723 | |
724 | /** Calculates number of vertices and indices required for geometry of a solid arc of the specified quality. */ |
725 | static void getNumElementsArc(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
726 | |
727 | /** Calculates number of vertices and indices required for geometry of a wire arc of the specified quality. */ |
728 | static void getNumElementsWireArc(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
729 | |
730 | /** Calculates number of vertices and indices required for geometry of a solid desc of the specified quality. */ |
731 | static void getNumElementsDisc(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
732 | |
733 | /** Calculates number of vertices and indices required for geometry of a wire disc of the specified quality. */ |
734 | static void getNumElementsWireDisc(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
735 | |
736 | /** Calculates number of vertices and indices required for geometry of a solid cone of the specified quality. */ |
737 | static void getNumElementsCone(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
738 | |
739 | /** Calculates number of vertices and indices required for geometry of a wireframe cone of the specified quality. */ |
740 | static void getNumElementsWireCone(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
741 | |
742 | /** Calculates number of vertices and indices required for geometry of a solid cylinder of the specified quality. */ |
743 | static void getNumElementsCylinder(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
744 | |
745 | /** Calculates number of vertices and indices required for geometry of a wireframe cylinder of the specified quality. */ |
746 | static void getNumElementsWireCylinder(UINT32 quality, UINT32& numVertices, UINT32& numIndices); |
747 | |
748 | /** Calculates number of vertices and indices required for geometry of a frustum. */ |
749 | static void getNumElementsFrustum(UINT32& numVertices, UINT32& numIndices); |
750 | |
751 | /** Calculates number of vertices and indices required for geometry of a quadrirateral. */ |
752 | static void getNumElementsQuad(UINT32& numVertices, UINT32& numIndices); |
753 | |
754 | static const UINT32 NUM_VERTICES_AA_LINE; |
755 | static const UINT32 NUM_INDICES_AA_LINE; |
756 | |
757 | protected: |
758 | /** |
759 | * Fills the provided buffers with vertices representing a per-pixel line. |
760 | * |
761 | * @param[in] a Start point of the line. |
762 | * @param[in] b End point of the line. |
763 | * @param[out] outVertices Output buffer that will store the vertex position data. |
764 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
765 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
766 | * @param[out] outIndices Output buffer that will store the index data. Indices are 32bit. |
767 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
768 | */ |
769 | static void pixelLine(const Vector3& a, const Vector3& b, UINT8* outVertices, |
770 | UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
771 | |
772 | /** |
773 | * Fills the provided buffers with vertices representing an antialiased line with a custom width. |
774 | * |
775 | * @param[in] a Start point of the line. |
776 | * @param[in] b End point of the line. |
777 | * @param[in] up Up direction to which the line will run perpendicular to. |
778 | * @param[in] width Width of the line. |
779 | * @param[in] borderWidth Width of the anti-aliased border. |
780 | * @param[in] color Color of the line. |
781 | * @param[out] outVertices Output buffer that will store the vertex position data. |
782 | * @param[out] outColors Output buffer that will store the vertex color data. |
783 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
784 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
785 | * @param[out] outIndices Output buffer that will store the index data. Indices are 32bit. |
786 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
787 | */ |
788 | static void antialiasedLine(const Vector3& a, const Vector3& b, const Vector3& up, float width, float borderWidth, |
789 | const Color& color, UINT8* outVertices, UINT8* outColors, UINT32 vertexOffset, UINT32 vertexStride, |
790 | UINT32* outIndices, UINT32 indexOffset); |
791 | |
792 | /** |
793 | * Fills the provided buffers with position data and indices representing an inner area of a polygon (basically a |
794 | * normal non-antialiased polygon). |
795 | * |
796 | * @param[in] points Points defining the polygon. First point is assumed to be the start and end point. |
797 | * @param[out] outVertices Output buffer that will store the vertex position data. |
798 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
799 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
800 | * @param[out] outIndices Output buffer that will store the index data. Indices are 32bit. |
801 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
802 | */ |
803 | static void pixelSolidPolygon(const Vector<Vector3>& points, UINT8* outVertices, |
804 | UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
805 | |
806 | /** |
807 | * Fills the provided buffers with vertices representing a pixel-wide polygon border. |
808 | * |
809 | * @param[in] points Points defining the polygon. First point is assumed to be the start and end point. |
810 | * @param[out] outVertices Output buffer that will store the vertex position data. |
811 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
812 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
813 | * @param[out] outIndices Output buffer that will store the index data. Indices are 32bit. |
814 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
815 | */ |
816 | static void pixelWirePolygon(const Vector<Vector3>& points, UINT8* outVertices, |
817 | UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
818 | |
819 | /** |
820 | * Fills the provided buffers with vertices representing an antialiased polygon. |
821 | * |
822 | * @param[in] points Points defining the polygon. First point is assumed to be the start and end point. |
823 | * @param[in] up Up direction to which the polygon will run perpendicular to. |
824 | * @param[in] borderWidth Width of the anti-aliased border. |
825 | * @param[in] color Color of the polygon. |
826 | * @param[out] outVertices Output buffer that will store the vertex position data. |
827 | * @param[out] outColors Output buffer that will store the vertex color data. |
828 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
829 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
830 | * @param[out] outIndices Output buffer that will store the index data. Indices are 32bit. |
831 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start writing at. |
832 | */ |
833 | static void antialiasedPolygon(const Vector<Vector3>& points, const Vector3& up, float borderWidth, const Color& color, UINT8* outVertices, UINT8* outColors, |
834 | UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset); |
835 | |
836 | private: |
837 | /** |
838 | * Calculates the center of the provided vertices. |
839 | * |
840 | * @param[in] vertices Buffer containing vertices. Vertices must be of three dimensions at least. |
841 | * @param[in] numVertices Number of vertices to calculate the center for. |
842 | * @param[in] vertexStride Number of bytes between two vertices in the buffer. |
843 | * @return Center point of the vertices. |
844 | */ |
845 | static Vector3 calcCenter(UINT8* vertices, UINT32 numVertices, UINT32 vertexStride); |
846 | |
847 | /** |
848 | * Subdivides the provided triangle so it approximates a curved surface of a sphere. |
849 | * |
850 | * @param[in] center Center of the sphere to approximate. |
851 | * @param[in] radius Radius of the sphere to approximate. |
852 | * @param[in] numLevels Number of times to subdivide the triangle. Higher number means better approximation. |
853 | * @param[in] a First corner of the triangle. Must be normalized. |
854 | * @param[in] b Second corner of the triangle. Must be normalized. |
855 | * @param[in] c Third corner of the triangle. Must be normalized. |
856 | * @param[out] outVertices Output buffer that will store the vertex position data. |
857 | * @param[out] outNormals Output buffer that will store the vertex normal data. |
858 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
859 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
860 | * @return Number of vertices generated (3 * (4 ^ numLevels)). |
861 | */ |
862 | static UINT32 subdivideTriangleOnSphere(const Vector3& center, float radius, UINT32 numLevels, |
863 | const Vector3& a, const Vector3& b, const Vector3& c, |
864 | UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride); |
865 | |
866 | /** |
867 | * Generates vertices that are part of an arc approximation. |
868 | * |
869 | * @param[in] center Determines world position of the arc. |
870 | * @param[in] up Determines rotation of the arc. Arc vertices will be perpendicular to this |
871 | * direction. |
872 | * @param[in] radius Distance of arc vertices from the center. |
873 | * @param[in] startAngle Angle in degrees to start the arc at. |
874 | * @param[in] angleAmount Angle in degrees to extend the arc from the start angle. |
875 | * @param[in] scale Scale to apply to the x/y axes, allowing you to create elliptical arcs. |
876 | * @param[in] numVertices Number of vertices to generate for the arc. Higher number means better arc |
877 | * approximation. Must be 2 or higher. |
878 | * @param[out] outVertices Output buffer that will store the vertex position data. |
879 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffer to start writing at. |
880 | * @param[in] vertexStride Size of a single vertex, in bytes. (Same for both position and color buffer) |
881 | */ |
882 | static void generateArcVertices(const Vector3& center, const Vector3& up, float radius, Degree startAngle, |
883 | Degree angleAmount, Vector2 scale, UINT32 numVertices, UINT8* outVertices, UINT32 vertexOffset, |
884 | UINT32 vertexStride); |
885 | |
886 | /** |
887 | * Calculates per-vertex tangents and bitangents based on the provided vertices, uv coordinates and indices. |
888 | * |
889 | * @param[in] positions Pointer to an array of vertex positions. |
890 | * @param[in] normals Pointer to an array of vertex normals. |
891 | * @param[in] uv Pointer to an array of vertex UV coordinates. |
892 | * @param[in] indices Set of 32-bit indices containing indexes into vertex array for each triangle. |
893 | * @param[in] numVertices Number of vertices in the @p vertices, @p normals and @p uv arrays. |
894 | * @param[in] numIndices Number of indices in the @p indices array. Must be a multiple of three. |
895 | * @param[in] vertexOffset Offset in number of vertices from the start of the buffers to start reading/writing. |
896 | * @param[in] indexOffset Offset in number of indices from the start of the buffer to start reading from. |
897 | * @param[in] vertexStride Number of bytes to advance the @p vertices, @p normals and @p uv arrays with each |
898 | * vertex. If set to zero them each array is advanced according to its own size. |
899 | * @param[out] tangents Pre-allocated buffer that will contain the calculated tangents & bitangents packed |
900 | * into 4D vector where first three components are the tangent, and 4th is the sign of |
901 | * the bitangent. Must be the same length as the vertex array. |
902 | */ |
903 | static void generateTangents(UINT8* positions, UINT8* normals, UINT8* uv, UINT32* indices, UINT32 numVertices, |
904 | UINT32 numIndices, UINT32 vertexOffset, UINT32 indexOffset, UINT32 vertexStride, |
905 | UINT8* tangents); |
906 | }; |
907 | |
908 | /** @} */ |
909 | } |