21 #include "SuperEllipsoidModel.h"
24 #include "Mathematics.h"
35 LOGE(
"Number of samples can't be 0.");
46 *numberOfCoordinates = samples / 2 * samples * 6 * 4;
49 *numberOfNormals = samples / 2 * samples * 6 * 3;
52 *roundedCubeCoordinates =
new float[*numberOfCoordinates];
54 if (roundedCubeCoordinates == NULL)
56 LOGE(
"Pointer roundedCubeCoordinates is NULL.");
61 *roundedCubeNormalVectors =
new float[*numberOfNormals];
63 if (roundedCubeNormalVectors == NULL)
65 LOGE(
"Pointer roundedCubeNormalVectors is NULL.");
70 *numberOfVertices = *numberOfCoordinates / 4;
73 Vec3f vertex, normalVector;
79 int normalVectorIndex = 0;
86 float xyAngle = -
M_PI / 2.0f;
89 for (
int j = 0; j < samples / 2; j++)
92 float xzAngle = -
M_PI;
94 for (
int i = 0; i <
samples; i++)
98 vertex =
sample (xyAngle, xzAngle, n1, n2, scale);
105 vertex =
sample (xyAngle + xyAngleDelta, xzAngle, n1, n2, scale);
106 normalVector =
calculateNormal(xyAngle + xyAngleDelta, xzAngle, n1, n2, scale);
112 vertex =
sample (xyAngle + xyAngleDelta, xzAngle + xzAngleDelta, n1, n2, scale);
113 normalVector =
calculateNormal(xyAngle + xyAngleDelta, xzAngle + xzAngleDelta, n1, n2, scale);
120 vertex =
sample (xyAngle, xzAngle, n1, n2, scale);
127 vertex =
sample (xyAngle + xyAngleDelta, xzAngle + xzAngleDelta, n1, n2, scale);
128 normalVector =
calculateNormal(xyAngle + xyAngleDelta, xzAngle + xzAngleDelta, n1, n2, scale);
134 vertex =
sample (xyAngle, xzAngle + xzAngleDelta, n1, n2, scale);
135 normalVector =
calculateNormal(xyAngle, xzAngle + xzAngleDelta, n1, n2, scale);
141 xzAngle += xzAngleDelta;
145 xyAngle += xyAngleDelta;
152 float cosPhi = cosf(xyAngle);
153 float cosBeta = cosf(xzAngle);
154 float sinPhi = sinf(xyAngle);
155 float sinBeta = sinf(xzAngle);
174 normal.
x =
signum(cosPhi) * powf(fabs(cosPhi), 2 - n1) *
signum(cosBeta) * powf(fabs(cosBeta), 2 - n2) /
scale;
175 normal.
y =
signum(sinPhi) * powf(fabs(sinPhi), 2 - n1) /
scale;
176 normal.
z =
signum(cosPhi) * powf(fabs(cosPhi), 2 - n1) *
signum(sinBeta) * powf(fabs(sinBeta), 2 - n2) /
scale;
187 const float xyAngleCos = cosf(xyAngle);
188 const float xzAngleCos = cosf(xzAngle);
189 const float xyAngleSin = sinf(xyAngle);
190 const float xzAngleSin = sinf(xzAngle);
212 vertex.
y = scale *
MaliSDK::signum(xyAngleSin) * powf(fabs(xyAngleSin), n1);
221 roundedCubeCoordinates[vertexIndex++] = vertex.
x;
222 roundedCubeCoordinates[vertexIndex++] = vertex.
y;
223 roundedCubeCoordinates[vertexIndex++] = vertex.
z;
224 roundedCubeCoordinates[vertexIndex++] = 1.0f;
227 roundedCubeNormalVectors[normalVectorIndex++] = normalVector.
x;
228 roundedCubeNormalVectors[normalVectorIndex++] = normalVector.
y;
229 roundedCubeNormalVectors[normalVectorIndex++] = normalVector.
z;
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.
A 3D floating point vector.
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.
float * roundedCubeNormalVectors
float * roundedCubeCoordinates
void normalize(void)
Normalize 3D floating point vector.