34 int* numberOfVertices,
35 int* numberOfCoordinates,
39 ASSERT(samples > 0,
"Number of samples has to be greater than 0.");
41 ASSERT(roundedCubeCoordinates != NULL,
"Cannot use null pointer while calculating rounded cube coordinates.");
42 ASSERT(roundedCubeNormalVectors != NULL,
"Cannot use null pointer while calculating rounded cube normals.");
43 ASSERT(numberOfVertices != NULL,
"Invalid parameter: cannot use NULL pointer to store number of vertices.");
44 ASSERT(numberOfCoordinates != NULL,
"Invalid parameter: cannot use NULL pointer to store number of coordinates.");
45 ASSERT(numberOfNormals != NULL,
"Invalid parameter: cannot use NULL pointer to store number of normals.");
52 *numberOfVertices = samples / 2 * samples * 6;
59 *roundedCubeCoordinates =
new float[*numberOfCoordinates];
61 *roundedCubeNormalVectors =
new float[*numberOfNormals];
64 ASSERT(roundedCubeCoordinates != NULL,
"Pointer roundedCubeCoordinates is NULL.");
65 ASSERT(roundedCubeNormalVectors != NULL,
"Pointer roundedCubeNormalVectors is NULL.");
68 Vec3f vertex, normalVector;
74 int normalVectorIndex = 0;
81 float xyAngle = -
M_PI / 2.0f;
84 for (
int j = 0; j < samples / 2; j++)
87 float xzAngle = -
M_PI;
89 for (
int i = 0; i <
samples; i++)
93 vertex =
sample (xyAngle, xzAngle, n1, n2, scale);
101 *roundedCubeCoordinates,
102 *roundedCubeNormalVectors);
105 vertex =
sample (xyAngle + xyAngleDelta, xzAngle, n1, n2, scale);
106 normalVector =
calculateNormal(xyAngle + xyAngleDelta, xzAngle, n1, n2, scale);
113 *roundedCubeCoordinates,
114 *roundedCubeNormalVectors);
117 vertex =
sample (xyAngle + xyAngleDelta, xzAngle + xzAngleDelta, n1, n2, scale);
118 normalVector =
calculateNormal(xyAngle + xyAngleDelta, xzAngle + xzAngleDelta, n1, n2, scale);
125 *roundedCubeCoordinates,
126 *roundedCubeNormalVectors);
130 vertex =
sample (xyAngle, xzAngle, n1, n2, scale);
138 *roundedCubeCoordinates,
139 *roundedCubeNormalVectors);
142 vertex =
sample (xyAngle + xyAngleDelta,
143 xzAngle + xzAngleDelta,
148 xzAngle + xzAngleDelta,
158 *roundedCubeCoordinates,
159 *roundedCubeNormalVectors);
162 vertex =
sample (xyAngle, xzAngle + xzAngleDelta, n1, n2, scale);
163 normalVector =
calculateNormal(xyAngle, xzAngle + xzAngleDelta, n1, n2, scale);
170 *roundedCubeCoordinates,
171 *roundedCubeNormalVectors);
174 xzAngle += xzAngleDelta;
178 xyAngle += xyAngleDelta;
189 float cosPhi = cosf(xyAngle);
190 float cosBeta = cosf(xzAngle);
191 float sinPhi = sinf(xyAngle);
192 float sinBeta = sinf(xzAngle);
209 normal.x =
signum(cosPhi) * powf(fabs(cosPhi), 2 - n1) *
signum(cosBeta) * powf(fabs(cosBeta), 2 - n2) /
scale;
210 normal.y =
signum(sinPhi) * powf(fabs(sinPhi), 2 - n1) /
scale;
211 normal.z =
signum(cosPhi) * powf(fabs(cosPhi), 2 - n1) *
signum(sinBeta) * powf(fabs(sinBeta), 2 - n2) /
scale;
226 const float xyAngleCos = cosf(xyAngle);
227 const float xzAngleCos = cosf(xzAngle);
228 const float xyAngleSin = sinf(xyAngle);
229 const float xzAngleSin = sinf(xzAngle);
248 vertex.x = scale *
signum(xyAngleCos) * powf(fabs(xyAngleCos), n1) *
signum(xzAngleCos) * powf(fabs(xzAngleCos), n2);
249 vertex.y = scale *
signum(xyAngleSin) * powf(fabs(xyAngleSin), n1);
250 vertex.z = scale *
signum(xyAngleCos) * powf(fabs(xyAngleCos), n1) *
signum(xzAngleSin) * powf(fabs(xzAngleSin), n2);
256 const Vec3f& normalVector,
258 int& normalVectorIndex,
259 float* roundedCubeCoordinates,
260 float* roundedCubeNormalVectors)
263 roundedCubeCoordinates[vertexIndex++] = vertex.x;
264 roundedCubeCoordinates[vertexIndex++] = vertex.y;
265 roundedCubeCoordinates[vertexIndex++] = vertex.z;
266 roundedCubeCoordinates[vertexIndex++] = 1.0f;
269 roundedCubeNormalVectors[normalVectorIndex++] = normalVector.x;
270 roundedCubeNormalVectors[normalVectorIndex++] = normalVector.y;
271 roundedCubeNormalVectors[normalVectorIndex++] = normalVector.z;
272 roundedCubeNormalVectors[normalVectorIndex++] = 1.0f;
static void storeVertexAndNormalVectorInArray(const Vec3f &vertex, const Vec3f &normalVector, int &vertexIndex, int &normalVectorIndex, float *roundedCubeCoordinates, float *roundedCubeNormalVectors)
Put vertex and normal vector values into vertex array and normal vector array.
static Vec3f calculateNormal(float xyAngle, float xzAngle, float n1, float n2, float scale)
Compute normal vector of a super ellipsoid.
static Vec3f sample(float xyAngle, float xzAngle, float n1, float n2, float scale)
Compute vertex of a super ellipsoid.
float signum(float f)
Get the sign of a number.
#define M_PI
The value of pi.
static void create(int samples, float n1, float n2, float scale, float **roundedCubeCoordinates, float **roundedCubeNormalVectors, int *numberOfVertices, int *numberOfCoordinates, int *numberOfNormals)
Function that generates vertices and normal vectors of rounded cube.
static const int numberOfPointCoordinates
Number of coordinates for a point in 3D space.
float * roundedCubeNormalVectors
float * roundedCubeCoordinates