21 #include "CubeModel.h"
31 if (coordinates == NULL)
33 LOGE(
"Cannot use null pointer while calculating coordinates.");
43 *coordinates = (
float*) malloc (numberOfCubeTriangleCoordinates *
sizeof(
float));
46 if (*coordinates == NULL)
48 LOGE(
"Could not allocate memory for result array.");
76 (*coordinates)[currentIndex] = -1.0f;
78 (*coordinates)[currentIndex] = 1.0f;
80 (*coordinates)[currentIndex] = 1.0f;
83 (*coordinates)[currentIndex] = -1.0f;
85 (*coordinates)[currentIndex] = 1.0f;
87 (*coordinates)[currentIndex] = -1.0f;
90 (*coordinates)[currentIndex] = 1.0f;
92 (*coordinates)[currentIndex] = 1.0f;
94 (*coordinates)[currentIndex] = -1.0f;
98 (*coordinates)[currentIndex] = -1.0f;
100 (*coordinates)[currentIndex] = 1.0f;
102 (*coordinates)[currentIndex] = 1.0f;
105 (*coordinates)[currentIndex] = 1.0f;
107 (*coordinates)[currentIndex] = 1.0f;
109 (*coordinates)[currentIndex] = -1.0f;
112 (*coordinates)[currentIndex] = 1.0f;
114 (*coordinates)[currentIndex] = 1.0f;
116 (*coordinates)[currentIndex] = 1.0f;
121 (*coordinates)[currentIndex] = -1.0f;
123 (*coordinates)[currentIndex] = -1.0f;
125 (*coordinates)[currentIndex] = 1.0f;
128 (*coordinates)[currentIndex] = -1.0f;
130 (*coordinates)[currentIndex] = -1.0f;
132 (*coordinates)[currentIndex] = -1.0f;
135 (*coordinates)[currentIndex] = 1.0f;
137 (*coordinates)[currentIndex] = -1.0f;
139 (*coordinates)[currentIndex] = -1.0f;
143 (*coordinates)[currentIndex] = -1.0f;
145 (*coordinates)[currentIndex] = -1.0f;
147 (*coordinates)[currentIndex] = 1.0f;
150 (*coordinates)[currentIndex] = 1.0f;
152 (*coordinates)[currentIndex] = -1.0f;
154 (*coordinates)[currentIndex] = -1.0f;
157 (*coordinates)[currentIndex] = 1.0f;
159 (*coordinates)[currentIndex] = -1.0f;
161 (*coordinates)[currentIndex] = 1.0f;
166 (*coordinates)[currentIndex] = 1.0f;
168 (*coordinates)[currentIndex] = -1.0f;
170 (*coordinates)[currentIndex] = -1.0f;
173 (*coordinates)[currentIndex] = 1.0f;
175 (*coordinates)[currentIndex] = 1.0f;
177 (*coordinates)[currentIndex] = -1.0f;
180 (*coordinates)[currentIndex] = -1.0f;
182 (*coordinates)[currentIndex] = 1.0f;
184 (*coordinates)[currentIndex] = -1.0f;
188 (*coordinates)[currentIndex] = 1.0f;
190 (*coordinates)[currentIndex] = -1.0f;
192 (*coordinates)[currentIndex] = -1.0f;
195 (*coordinates)[currentIndex] = -1.0f;
197 (*coordinates)[currentIndex] = 1.0f;
199 (*coordinates)[currentIndex] = -1.0f;
202 (*coordinates)[currentIndex] = -1.0f;
204 (*coordinates)[currentIndex] = -1.0f;
206 (*coordinates)[currentIndex] = -1.0f;
211 (*coordinates)[currentIndex] = -1.0f;
213 (*coordinates)[currentIndex] = -1.0f;
215 (*coordinates)[currentIndex] = 1.0f;
218 (*coordinates)[currentIndex] = -1.0f;
220 (*coordinates)[currentIndex] = 1.0f;
222 (*coordinates)[currentIndex] = 1.0f;
225 (*coordinates)[currentIndex] = 1.0f;
227 (*coordinates)[currentIndex] = 1.0f;
229 (*coordinates)[currentIndex] = 1.0f;
233 (*coordinates)[currentIndex] = -1.0f;
235 (*coordinates)[currentIndex] = -1.0f;
237 (*coordinates)[currentIndex] = 1.0f;
240 (*coordinates)[currentIndex] = 1.0f;
242 (*coordinates)[currentIndex] = 1.0f;
244 (*coordinates)[currentIndex] = 1.0f;
247 (*coordinates)[currentIndex] = 1.0f;
249 (*coordinates)[currentIndex] = -1.0f;
251 (*coordinates)[currentIndex] = 1.0f;
256 (*coordinates)[currentIndex] = 1.0f;
258 (*coordinates)[currentIndex] = -1.0f;
260 (*coordinates)[currentIndex] = 1.0f;
263 (*coordinates)[currentIndex] = 1.0f;
265 (*coordinates)[currentIndex] = 1.0f;
267 (*coordinates)[currentIndex] = 1.0f;
270 (*coordinates)[currentIndex] = 1.0f;
272 (*coordinates)[currentIndex] = 1.0f;
274 (*coordinates)[currentIndex] = -1.0f;
278 (*coordinates)[currentIndex] = 1.0f;
280 (*coordinates)[currentIndex] = -1.0f;
282 (*coordinates)[currentIndex] = 1.0f;
285 (*coordinates)[currentIndex] = 1.0f;
287 (*coordinates)[currentIndex] = 1.0f;
289 (*coordinates)[currentIndex] = -1.0f;
292 (*coordinates)[currentIndex] = 1.0f;
294 (*coordinates)[currentIndex] = -1.0f;
296 (*coordinates)[currentIndex] = -1.0f;
301 (*coordinates)[currentIndex] = -1.0f;
303 (*coordinates)[currentIndex] = -1.0f;
305 (*coordinates)[currentIndex] = -1.0f;
308 (*coordinates)[currentIndex] = -1.0f;
310 (*coordinates)[currentIndex] = 1.0f;
312 (*coordinates)[currentIndex] = -1.0f;
315 (*coordinates)[currentIndex] = -1.0f;
317 (*coordinates)[currentIndex] = 1.0f;
319 (*coordinates)[currentIndex] = 1.0f;
323 (*coordinates)[currentIndex] = -1.0f;
325 (*coordinates)[currentIndex] = -1.0f;
327 (*coordinates)[currentIndex] = -1.0f;
330 (*coordinates)[currentIndex] = -1.0f;
332 (*coordinates)[currentIndex] = 1.0f;
334 (*coordinates)[currentIndex] = 1.0f;
337 (*coordinates)[currentIndex] = -1.0f;
339 (*coordinates)[currentIndex] = -1.0f;
341 (*coordinates)[currentIndex] = 1.0f;
347 (*coordinates)[i] = scalingFactor * (*coordinates)[i];
350 if (numberOfCoordinates != NULL)
364 LOGE(
"Cannot use null pointer while calculating coordinates.");
370 const int numberOfCubeNormalsCoordinates = 6 * 2 * 3 * 3;
372 int currentIndex = 0;
375 *normals = (
float*) malloc (numberOfCubeNormalsCoordinates *
sizeof(
float));
378 if (*normals == NULL)
380 LOGE(
"Could not allocate memory for result array.");
386 int numberOfCoordinatesForOneFace = 2 * 3;
389 for (
int i = 0; i < numberOfCoordinatesForOneFace; i++)
391 (*normals)[currentIndex] = 0;
393 (*normals)[currentIndex] = 1;
395 (*normals)[currentIndex] = 0;
400 for (
int i = 0; i < numberOfCoordinatesForOneFace; i++)
402 (*normals)[currentIndex] = 0;
404 (*normals)[currentIndex] = -1;
406 (*normals)[currentIndex] = 0;
411 for (
int i = 0; i < numberOfCoordinatesForOneFace; i++)
413 (*normals)[currentIndex] = 0;
415 (*normals)[currentIndex] = 0;
417 (*normals)[currentIndex] = -1;
422 for (
int i = 0; i < numberOfCoordinatesForOneFace; i++)
424 (*normals)[currentIndex] = 0;
426 (*normals)[currentIndex] = 0;
428 (*normals)[currentIndex] = 1;
433 for (
int i = 0; i < numberOfCoordinatesForOneFace; i++)
435 (*normals)[currentIndex] = 1;
437 (*normals)[currentIndex] = 0;
439 (*normals)[currentIndex] = 0;
444 for (
int i = 0; i < numberOfCoordinatesForOneFace; i++)
446 (*normals)[currentIndex] = -1;
448 (*normals)[currentIndex] = 0;
450 (*normals)[currentIndex] = 0;
454 if (numberOfCoordinates != NULL)
456 *numberOfCoordinates = numberOfCubeNormalsCoordinates;
static void getNormals(int *numberOfCoordinates, float **normals)
Create normals for a cube which was created with getTriangleRepresentation() function.
int numberOfCubeTriangleCoordinates
static void getTriangleRepresentation(float scalingFactor, int *numberOfCoordinates, float **coordinates)
Compute coordinates of points which make up a cube.