1#ifndef ULT_SPHERE_SHAPE_H_INCLUDED
2#define ULT_SPHERE_SHAPE_H_INCLUDED
7#define ULT_UNIT_SPHERE_STRIDE sizeof(Ult::stUnitSphereVertex)
24static inline bool CreateSphereMesh(
30 if (!model) {
return false; }
33 int numFaces = hRes * (vRes*2) * 2;
34 int numIndices = numFaces * 3;
35 int numVerts = (hRes+1) * (vRes+1);
36 const float fPI = 3.141592654f;
38 stUnitSphereVertex* verts =
new stUnitSphereVertex[numVerts];
39 stUnitSphereVertex* vertPtr = verts;
44 unsigned int* indices =
new unsigned int[numFaces*3];
45 unsigned int* indexPtr = indices;
50 for (
int i=0; i<=hRes; i++) {
51 for (
int j=0; j<=vRes; j++) {
52 float ii = i/float(hRes);
53 float jj = j/float(vRes);
54 float theta = ii*2*fPI;
55 float phi = (jj-0.5f)*fPI;
56 float phi2 = phi + fPI * 0.5f;
57 float nx = cosf(theta)*cosf(phi);
58 float ny = sinf(theta)*cosf(phi);
61 vertPtr->x = radius * nx;
62 vertPtr->y = radius * ny;
63 vertPtr->z = radius * nz;
76 for (
int i=0; i<hRes; i++) {
77 for (
int j=0; j<vRes; j++) {
78 *indexPtr++ = (i+0) * (vRes+1) + j + 0;
79 *indexPtr++ = (i+1) * (vRes+1) + j + 1;
80 *indexPtr++ = (i+0) * (vRes+1) + j + 1;
82 *indexPtr++ = (i+0) * (vRes+1) + j + 0;
83 *indexPtr++ = (i+1) * (vRes+1) + j + 0;
84 *indexPtr++ = (i+1) * (vRes+1) + j + 1;
98 if (verts) {
delete[] verts; }
99 if (indices) {
delete[] indices; }
#define ULT_UNIT_SPHERE_STRIDE
Definition SphereShape.h:7
Definition ModelData.h:26
void Clear()
Definition ModelData.cpp:21
bool SetIndices(int totalIndices, unsigned int *indices)
Definition ModelData.cpp:36
bool AddDescriptorElement(ElementType type)
Definition ModelData.h:49
bool SetVertices(PrimitiveType type, int totalVertices, int stride, char *vertices)
Definition ModelData.cpp:53
@ ULT_TRI_LIST
Definition PrimitiveType.h:12
@ ULT_VERTEX_3F
Definition ElementType.h:13
@ ULT_TEX1_2F
Definition ElementType.h:16
@ ULT_NORMAL_3F
Definition ElementType.h:14
Definition SphereShape.h:13
float nx
Definition SphereShape.h:16
float x
Definition SphereShape.h:14
float tu1
Definition SphereShape.h:15
float tv1
Definition SphereShape.h:15
float nz
Definition SphereShape.h:16
float ny
Definition SphereShape.h:16
float z
Definition SphereShape.h:14
float y
Definition SphereShape.h:14