| OLD | NEW |
| 1 // | 1 // |
| 2 // Book: OpenGL(R) ES 2.0 Programming Guide | 2 // Book: OpenGL(R) ES 2.0 Programming Guide |
| 3 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner | 3 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner |
| 4 // ISBN-10: 0321502795 | 4 // ISBN-10: 0321502795 |
| 5 // ISBN-13: 9780321502797 | 5 // ISBN-13: 9780321502797 |
| 6 // Publisher: Addison-Wesley Professional | 6 // Publisher: Addison-Wesley Professional |
| 7 // URLs: http://safari.informit.com/9780321563835 | 7 // URLs: http://safari.informit.com/9780321563835 |
| 8 // http://www.opengles-book.com | 8 // http://www.opengles-book.com |
| 9 // | 9 // |
| 10 | 10 |
| 11 // ESShapes.c | 11 // ESShapes.c |
| 12 // | 12 // |
| 13 // Utility functions for generating shapes | 13 // Utility functions for generating shapes |
| 14 // | 14 // |
| 15 | 15 |
| 16 /// | 16 /// |
| 17 // Includes | 17 // Includes |
| 18 // | 18 // |
| 19 #include "esUtil.h" | 19 #include "esUtil.h" |
| 20 #include <stdlib.h> | 20 #include <stdlib.h> |
| 21 #include <math.h> | 21 #include <math.h> |
| 22 #include <string.h> | |
| 23 | 22 |
| 24 /// | 23 /// |
| 25 // Defines | 24 // Defines |
| 26 // | 25 // |
| 27 #define ES_PI (3.14159265f) | 26 #define ES_PI (3.14159265f) |
| 28 | 27 |
| 29 ////////////////////////////////////////////////////////////////// | 28 ////////////////////////////////////////////////////////////////// |
| 30 // | 29 // |
| 31 // Private Functions | 30 // Private Functions |
| 32 // | 31 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 /// \brief Generates geometry for a sphere. Allocates memory for the vertex dat
a and stores | 43 /// \brief Generates geometry for a sphere. Allocates memory for the vertex dat
a and stores |
| 45 /// the results in the arrays. Generate index list for a TRIANGLE_STRIP | 44 /// the results in the arrays. Generate index list for a TRIANGLE_STRIP |
| 46 /// \param numSlices The number of slices in the sphere | 45 /// \param numSlices The number of slices in the sphere |
| 47 /// \param vertices If not NULL, will contain array of float3 positions | 46 /// \param vertices If not NULL, will contain array of float3 positions |
| 48 /// \param normals If not NULL, will contain array of float3 normals | 47 /// \param normals If not NULL, will contain array of float3 normals |
| 49 /// \param texCoords If not NULL, will contain array of float2 texCoords | 48 /// \param texCoords If not NULL, will contain array of float2 texCoords |
| 50 /// \param indices If not NULL, will contain the array of indices for the triang
le strip | 49 /// \param indices If not NULL, will contain the array of indices for the triang
le strip |
| 51 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array | 50 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array |
| 52 /// if it is not NULL ) as a GL_TRIANGLE_STRIP | 51 /// if it is not NULL ) as a GL_TRIANGLE_STRIP |
| 53 // | 52 // |
| 54 int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **nor
mals, | 53 int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL
float **normals, |
| 55 GLfloat **texCoords, GLuint **indices ) | 54 GLfloat **texCoords, GLuint **indices ) |
| 56 { | 55 { |
| 57 int i; | 56 int i; |
| 58 int j; | 57 int j; |
| 59 int numParallels = numSlices / 2; | 58 int numParallels = numSlices / 2; |
| 60 int numVertices = ( numParallels + 1 ) * ( numSlices + 1 ); | 59 int numVertices = ( numParallels + 1 ) * ( numSlices + 1 ); |
| 61 int numIndices = numParallels * numSlices * 6; | 60 int numIndices = numParallels * numSlices * 6; |
| 62 float angleStep = (2.0f * ES_PI) / ((float) numSlices); | 61 float angleStep = (2.0f * ES_PI) / ((float) numSlices); |
| 63 | 62 |
| 64 // Allocate memory for buffers | 63 // Allocate memory for buffers |
| 65 if ( vertices != NULL ) | 64 if ( vertices != NULL ) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 /// \brief Generates geometry for a cube. Allocates memory for the vertex data
and stores | 130 /// \brief Generates geometry for a cube. Allocates memory for the vertex data
and stores |
| 132 /// the results in the arrays. Generate index list for a TRIANGLES | 131 /// the results in the arrays. Generate index list for a TRIANGLES |
| 133 /// \param scale The size of the cube, use 1.0 for a unit cube. | 132 /// \param scale The size of the cube, use 1.0 for a unit cube. |
| 134 /// \param vertices If not NULL, will contain array of float3 positions | 133 /// \param vertices If not NULL, will contain array of float3 positions |
| 135 /// \param normals If not NULL, will contain array of float3 normals | 134 /// \param normals If not NULL, will contain array of float3 normals |
| 136 /// \param texCoords If not NULL, will contain array of float2 texCoords | 135 /// \param texCoords If not NULL, will contain array of float2 texCoords |
| 137 /// \param indices If not NULL, will contain the array of indices for the triang
le strip | 136 /// \param indices If not NULL, will contain the array of indices for the triang
le strip |
| 138 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array | 137 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array |
| 139 /// if it is not NULL ) as a GL_TRIANGLE_STRIP | 138 /// if it is not NULL ) as a GL_TRIANGLE_STRIP |
| 140 // | 139 // |
| 141 int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, | 140 int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, |
| 142 GLfloat **texCoords, GLuint **indices ) | 141 GLfloat **texCoords, GLuint **indices ) |
| 143 { | 142 { |
| 144 int i; | 143 int i; |
| 145 int numVertices = 24; | 144 int numVertices = 24; |
| 146 int numIndices = 36; | 145 int numIndices = 36; |
| 147 | 146 |
| 148 GLfloat cubeVerts[] = | 147 GLfloat cubeVerts[] = |
| 149 { | 148 { |
| 150 -0.5f, -0.5f, -0.5f, | 149 -0.5f, -0.5f, -0.5f, |
| 151 -0.5f, -0.5f, 0.5f, | 150 -0.5f, -0.5f, 0.5f, |
| 152 0.5f, -0.5f, 0.5f, | 151 0.5f, -0.5f, 0.5f, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 20, 23, 22, | 270 20, 23, 22, |
| 272 20, 22, 21 | 271 20, 22, 21 |
| 273 }; | 272 }; |
| 274 | 273 |
| 275 *indices = malloc ( sizeof(GLuint) * numIndices ); | 274 *indices = malloc ( sizeof(GLuint) * numIndices ); |
| 276 memcpy( *indices, cubeIndices, sizeof( cubeIndices ) ); | 275 memcpy( *indices, cubeIndices, sizeof( cubeIndices ) ); |
| 277 } | 276 } |
| 278 | 277 |
| 279 return numIndices; | 278 return numIndices; |
| 280 } | 279 } |
| OLD | NEW |