eqemu

diff src/objfile.cc @ 4:3d3656360a82

rendering properly, added picking, almost done...
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 17 Jul 2014 08:51:17 +0300
parents f9274bebe55e
children 9b5bb05ae53a
line diff
     1.1 --- a/src/objfile.cc	Thu Jul 17 02:35:19 2014 +0300
     1.2 +++ b/src/objfile.cc	Thu Jul 17 08:51:17 2014 +0300
     1.3 @@ -2,6 +2,7 @@
     1.4  #include <string.h>
     1.5  #include <ctype.h>
     1.6  #include <limits.h>
     1.7 +#include <assert.h>
     1.8  #include <vector>
     1.9  #include <map>
    1.10  #include <string>
    1.11 @@ -284,6 +285,9 @@
    1.12  
    1.13  	int nelem = obj->f.size() * 3;
    1.14  
    1.15 +	assert(sizeof(Vector3) == 3 * sizeof(float));
    1.16 +	assert(sizeof(Vector2) == 2 * sizeof(float));
    1.17 +
    1.18  	try {
    1.19  		robj = new Object;
    1.20  		varr = new Vector3[nelem];
    1.21 @@ -293,15 +297,15 @@
    1.22  	catch(...) {
    1.23  		return 0;
    1.24  	}
    1.25 -	/*if(obj->cur_obj.length() > 0) {
    1.26 +	if(obj->cur_obj.length() > 0) {
    1.27  		robj->set_name(obj->cur_obj.c_str());
    1.28 -	}*/
    1.29 +	}
    1.30  
    1.31  	// need at least one of each element
    1.32  	bool added_norm = false, added_tc = false;
    1.33  	if(obj->vn.empty()) {
    1.34  		obj->vn.push_back(Vector3(0, 0, 0));
    1.35 -		added_norm = true;;
    1.36 +		added_norm = true;
    1.37  	}
    1.38  	if(obj->vt.empty()) {
    1.39  		obj->vt.push_back(Vector2(0, 0));
    1.40 @@ -329,10 +333,13 @@
    1.41  		obj->vt.pop_back();
    1.42  	}
    1.43  
    1.44 -	Mesh *mesh = robj->get_mesh();
    1.45 +	Mesh *mesh = new Mesh;
    1.46  	mesh->set_attrib(MESH_ATTR_VERTEX, nelem, 3, &varr->x);
    1.47  	mesh->set_attrib(MESH_ATTR_NORMAL, nelem, 3, &narr->x);
    1.48  	mesh->set_attrib(MESH_ATTR_TEXCOORD, nelem, 2, &tarr->x);
    1.49 +	robj->set_mesh(mesh);
    1.50 +
    1.51 +	printf("loaded object %s: %d faces\n", obj->cur_obj.c_str(), nelem / 3);
    1.52  
    1.53  	delete [] varr;
    1.54  	delete [] narr;