nuclear@25: #include nuclear@25: #include "meshgen.h" nuclear@25: #include "mesh.h" nuclear@25: nuclear@25: // -------- sphere -------- nuclear@25: nuclear@25: #define SURAD(u) ((u) * 2.0 * M_PI) nuclear@25: #define SVRAD(v) ((v) * M_PI) nuclear@25: nuclear@25: static Vector3 sphvec(float theta, float phi) nuclear@25: { nuclear@25: return Vector3(sin(theta) * sin(phi), nuclear@25: cos(phi), nuclear@25: cos(theta) * sin(phi)); nuclear@25: } nuclear@25: nuclear@25: void gen_sphere(Mesh *mesh, float rad, int usub, int vsub, float urange, float vrange) nuclear@25: { nuclear@25: if(usub < 4) usub = 4; nuclear@25: if(vsub < 2) vsub = 2; nuclear@25: nuclear@25: int uverts = usub + 1; nuclear@25: int vverts = vsub + 1; nuclear@25: nuclear@25: int num_verts = uverts * vverts; nuclear@25: int num_quads = usub * vsub; nuclear@25: int num_tri = num_quads * 2; nuclear@25: nuclear@25: mesh->clear(); nuclear@25: Vector3 *varr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_VERTEX, 3, num_verts, 0); nuclear@25: Vector3 *narr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_NORMAL, 3, num_verts, 0); nuclear@25: Vector3 *tarr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_TANGENT, 3, num_verts, 0); nuclear@25: Vector2 *uvarr = (Vector2*)mesh->set_attrib_data(MESH_ATTR_TEXCOORD, 2, num_verts, 0); nuclear@25: unsigned int *idxarr = mesh->set_index_data(num_tri * 3, 0); nuclear@25: nuclear@25: float du = urange / (float)(uverts - 1); nuclear@25: float dv = vrange / (float)(vverts - 1); nuclear@25: nuclear@25: float u = 0.0; nuclear@25: for(int i=0; iclear(); nuclear@25: Vector3 *varr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_VERTEX, 3, num_verts, 0); nuclear@25: Vector3 *narr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_NORMAL, 3, num_verts, 0); nuclear@25: Vector3 *tarr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_TANGENT, 3, num_verts, 0); nuclear@25: Vector2 *uvarr = (Vector2*)mesh->set_attrib_data(MESH_ATTR_TEXCOORD, 2, num_verts, 0); nuclear@25: unsigned int *idxarr = mesh->set_index_data(num_tri * 3, 0); nuclear@25: nuclear@25: float du = urange / (float)(uverts - 1); nuclear@25: float dv = vrange / (float)(vverts - 1); nuclear@25: nuclear@25: float u = 0.0; nuclear@25: for(int i=0; iclear(); nuclear@25: Vector3 *varr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_VERTEX, 3, num_verts, 0); nuclear@25: Vector3 *narr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_NORMAL, 3, num_verts, 0); nuclear@25: Vector3 *tarr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_TANGENT, 3, num_verts, 0); nuclear@25: Vector2 *uvarr = (Vector2*)mesh->set_attrib_data(MESH_ATTR_TEXCOORD, 2, num_verts, 0); nuclear@25: unsigned int *idxarr = mesh->set_index_data(num_tri * 3, 0); nuclear@25: nuclear@25: float du = urange / (float)(uverts - 1); nuclear@25: float dv = vrange / (float)(vverts - 1); nuclear@25: nuclear@25: float u = 0.0; nuclear@25: for(int i=0; iclear(); nuclear@25: nuclear@25: int uverts = usub + 1; nuclear@25: int vverts = vsub + 1; nuclear@25: int num_verts = uverts * vverts; nuclear@25: nuclear@25: int num_quads = usub * vsub; nuclear@25: int num_tri = num_quads * 2; nuclear@25: nuclear@25: Vector3 *varr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_VERTEX, 3, num_verts, 0); nuclear@25: Vector3 *narr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_NORMAL, 3, num_verts, 0); nuclear@25: Vector3 *tarr = (Vector3*)mesh->set_attrib_data(MESH_ATTR_TANGENT, 3, num_verts, 0); nuclear@25: Vector2 *uvarr = (Vector2*)mesh->set_attrib_data(MESH_ATTR_TEXCOORD, 2, num_verts, 0); nuclear@25: unsigned int *idxarr = mesh->set_index_data(num_tri * 3, 0); nuclear@25: nuclear@25: float du = 1.0 / (float)usub; nuclear@25: float dv = 1.0 / (float)vsub; nuclear@25: nuclear@25: float u = 0.0; nuclear@25: for(int i=0; i