goat3d
diff src/goat3d.cc @ 17:1d85d7dd0038
goatprim done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 27 Sep 2013 02:29:52 +0300 |
parents | cb6c1a945a11 |
children | b35427826b60 |
line diff
1.1 --- a/src/goat3d.cc Thu Sep 26 14:16:09 2013 +0300 1.2 +++ b/src/goat3d.cc Fri Sep 27 02:29:52 2013 +0300 1.3 @@ -360,42 +360,44 @@ 1.4 1.5 void goat3d_end(void) 1.6 { 1.7 - static int tri_offs[] = {0, 1, 2}; 1.8 - static int quad_offs[] = {0, 1, 2, 0, 2, 3}; 1.9 - int *index_offs; 1.10 - 1.11 - int num_faces, in_face_verts, out_face_verts; 1.12 switch(im_prim) { 1.13 case GOAT3D_TRIANGLES: 1.14 - in_face_verts = 3; 1.15 - out_face_verts = 3; 1.16 - index_offs = tri_offs; 1.17 + { 1.18 + int num_faces = (int)im_mesh->vertices.size() / 3; 1.19 + im_mesh->faces.resize(num_faces); 1.20 + 1.21 + int vidx = 0; 1.22 + for(int i=0; i<num_faces; i++) { 1.23 + im_mesh->faces[i].v[0] = vidx++; 1.24 + im_mesh->faces[i].v[1] = vidx++; 1.25 + im_mesh->faces[i].v[2] = vidx++; 1.26 + } 1.27 + } 1.28 break; 1.29 1.30 case GOAT3D_QUADS: 1.31 - in_face_verts = 4; 1.32 - out_face_verts = 6; 1.33 - index_offs = quad_offs; 1.34 + { 1.35 + int num_quads = (int)im_mesh->vertices.size() / 4; 1.36 + im_mesh->faces.resize(num_quads * 2); 1.37 + 1.38 + int vidx = 0; 1.39 + for(int i=0; i<num_quads; i++) { 1.40 + im_mesh->faces[i * 2].v[0] = vidx; 1.41 + im_mesh->faces[i * 2].v[1] = vidx + 1; 1.42 + im_mesh->faces[i * 2].v[2] = vidx + 2; 1.43 + 1.44 + im_mesh->faces[i * 2 + 1].v[0] = vidx; 1.45 + im_mesh->faces[i * 2 + 1].v[1] = vidx + 2; 1.46 + im_mesh->faces[i * 2 + 1].v[2] = vidx + 3; 1.47 + 1.48 + vidx += 4; 1.49 + } 1.50 + } 1.51 break; 1.52 1.53 default: 1.54 return; 1.55 }; 1.56 - 1.57 - num_faces = (int)im_mesh->vertices.size() / in_face_verts; 1.58 - if(!num_faces) { 1.59 - return; 1.60 - } 1.61 - 1.62 - im_mesh->faces.resize(num_faces); 1.63 - 1.64 - int vidx = 0; 1.65 - for(int i=0; i<num_faces; i++) { 1.66 - for(int j=0; j<out_face_verts; j++) { 1.67 - im_mesh->faces[i].v[j] = vidx + index_offs[j]; 1.68 - } 1.69 - vidx += 4; 1.70 - } 1.71 } 1.72 1.73 void goat3d_vertex3f(float x, float y, float z) 1.74 @@ -424,21 +426,25 @@ 1.75 void goat3d_normal3f(float x, float y, float z) 1.76 { 1.77 im_norm = Vector3(x, y, z); 1.78 + im_use[GOAT3D_MESH_ATTR_NORMAL] = true; 1.79 } 1.80 1.81 void goat3d_tangent3f(float x, float y, float z) 1.82 { 1.83 im_tang = Vector3(x, y, z); 1.84 + im_use[GOAT3D_MESH_ATTR_TANGENT] = true; 1.85 } 1.86 1.87 void goat3d_texcoord2f(float x, float y) 1.88 { 1.89 im_texcoord = Vector2(x, y); 1.90 + im_use[GOAT3D_MESH_ATTR_TEXCOORD] = true; 1.91 } 1.92 1.93 void goat3d_skin_weight4f(float x, float y, float z, float w) 1.94 { 1.95 im_skinw = Vector4(x, y, z, w); 1.96 + im_use[GOAT3D_MESH_ATTR_SKIN_WEIGHT] = true; 1.97 } 1.98 1.99 void goat3d_skin_matrix4i(int x, int y, int z, int w) 1.100 @@ -447,16 +453,18 @@ 1.101 im_skinmat.y = y; 1.102 im_skinmat.z = z; 1.103 im_skinmat.w = w; 1.104 + im_use[GOAT3D_MESH_ATTR_SKIN_MATRIX] = true; 1.105 } 1.106 1.107 void goat3d_color3f(float x, float y, float z) 1.108 { 1.109 - im_color = Vector4(x, y, z, 1.0f); 1.110 + goat3d_color4f(x, y, z, 1.0f); 1.111 } 1.112 1.113 void goat3d_color4f(float x, float y, float z, float w) 1.114 { 1.115 im_color = Vector4(x, y, z, w); 1.116 + im_use[GOAT3D_MESH_ATTR_COLOR] = true; 1.117 } 1.118 1.119 void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh)