Exemple #1
0
GLUSAPI GLUSvoid GLUSAPIENTRY glusQuaternionRotateRzRyRxf(GLUSfloat quaternion[4], const GLUSfloat anglez, const GLUSfloat angley, const GLUSfloat anglex)
{
    GLUSfloat rotZ[4];
    GLUSfloat rotY[4];
    GLUSfloat rotX[4];

    glusQuaternionRotateRzf(rotZ, anglez);
    glusQuaternionRotateRyf(rotY, angley);
    glusQuaternionRotateRxf(rotX, anglex);

    glusQuaternionMultiplyQuaternionf(quaternion, rotZ, rotY);
    glusQuaternionMultiplyQuaternionf(quaternion, quaternion, rotX);
}
Exemple #2
0
GLUSboolean GLUSAPIENTRY glusCreateDomef(GLUSshape* shape, const GLUSfloat radius, const GLUSushort numberSlices)
{
    GLUSuint i, j;

    GLUSuint numberParallels = numberSlices / 4;
    GLUSuint numberVertices = (numberParallels + 1) * (numberSlices + 1);
    GLUSuint numberIndices = numberParallels * numberSlices * 6;

    GLUSfloat angleStep = (2.0f * GLUS_PI) / ((GLUSfloat) numberSlices);

    GLUSuint indexIndices;

    // used later to help us calculating tangents vectors
    GLUSfloat helpVector[3] = { 1.0f, 0.0f, 0.0f };
    GLUSfloat helpQuaternion[4];
    GLUSfloat helpMatrix[16];

    if (numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
    {
        return GLUS_FALSE;
    }

    if (!shape)
    {
        return GLUS_FALSE;
    }
    glusInitShapef(shape);

    shape->numberVertices = numberVertices;
    shape->numberIndices = numberIndices;

    shape->vertices = (GLUSfloat*) malloc(4 * numberVertices * sizeof(GLUSfloat));
    shape->normals = (GLUSfloat*) malloc(3 * numberVertices * sizeof(GLUSfloat));
    shape->tangents = (GLUSfloat*) malloc(3 * numberVertices * sizeof(GLUSfloat));
    shape->texCoords = (GLUSfloat*) malloc(2 * numberVertices * sizeof(GLUSfloat));
    shape->indices = (GLUSushort*) malloc(numberIndices * sizeof(GLUSushort));

    if (!glusCheckShapef(shape))
    {
        glusDestroyShapef(shape);

        return GLUS_FALSE;
    }

    for (i = 0; i < (GLUSuint)(numberParallels + 1); i++)
    {
        for (j = 0; j < (GLUSuint)(numberSlices + 1); j++)
        {
            GLUSuint vertexIndex = (i * (numberSlices + 1) + j) * 4;
            GLUSuint normalIndex = (i * (numberSlices + 1) + j) * 3;
            GLUSuint tangentIndex = (i * (numberSlices + 1) + j) * 3;
            GLUSuint texCoordsIndex = (i * (numberSlices + 1) + j) * 2;

            shape->vertices[vertexIndex + 0] = radius * sinf(angleStep * (GLUSfloat) i) * sinf(angleStep * (GLUSfloat) j);
            shape->vertices[vertexIndex + 1] = radius * cosf(angleStep * (GLUSfloat) i);
            shape->vertices[vertexIndex + 2] = radius * sinf(angleStep * (GLUSfloat) i) * cosf(angleStep * (GLUSfloat) j);
            shape->vertices[vertexIndex + 3] = 1.0f;

            shape->normals[normalIndex + 0] = shape->vertices[vertexIndex + 0] / radius;
            shape->normals[normalIndex + 1] = shape->vertices[vertexIndex + 1] / radius;
            shape->normals[normalIndex + 2] = shape->vertices[vertexIndex + 2] / radius;

            shape->texCoords[texCoordsIndex + 0] = (GLUSfloat) j / (GLUSfloat) numberSlices;
            shape->texCoords[texCoordsIndex + 1] = 1.0f - (GLUSfloat) i / (GLUSfloat) numberParallels;

            // use quaternion to get the tangent vector
            glusQuaternionRotateRyf(helpQuaternion, 360.0f * shape->texCoords[texCoordsIndex + 0]);
            glusQuaternionGetMatrix4x4f(helpMatrix, helpQuaternion);

            glusMatrix4x4MultiplyVector3f(&shape->tangents[tangentIndex], helpMatrix, helpVector);
        }
    }

    indexIndices = 0;
    for (i = 0; i < numberParallels; i++)
    {
        for (j = 0; j < numberSlices; j++)
        {
            shape->indices[indexIndices++] = i * (numberSlices + 1) + j;
            shape->indices[indexIndices++] = (i + 1) * (numberSlices + 1) + j;
            shape->indices[indexIndices++] = (i + 1) * (numberSlices + 1) + (j + 1);

            shape->indices[indexIndices++] = i * (numberSlices + 1) + j;
            shape->indices[indexIndices++] = (i + 1) * (numberSlices + 1) + (j + 1);
            shape->indices[indexIndices++] = i * (numberSlices + 1) + (j + 1);
        }
    }

    if (!glusFinalizeShapef(shape))
    {
        glusDestroyShapef(shape);

        return GLUS_FALSE;
    }

	return GLUS_TRUE;
}