coeng
diff src/co_mesh.cc @ 8:8cce82794f90
seems to work nicely
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Feb 2015 05:14:20 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/co_mesh.cc Sun Feb 15 05:14:20 2015 +0200 1.3 @@ -0,0 +1,46 @@ 1.4 +#include "opengl.h" 1.5 +#include "co_mesh.h" 1.6 +#include "co_xform.h" 1.7 +#include "gobj.h" 1.8 + 1.9 +static CoMesh reg_co_mesh; 1.10 +static Component *cons_co_mesh() { return new CoMesh; } 1.11 + 1.12 +CoMesh::CoMesh() 1.13 +{ 1.14 + name = "mesh"; 1.15 + mesh = 0; 1.16 + 1.17 + register_component(name, cons_co_mesh); 1.18 +} 1.19 + 1.20 +CoMesh::~CoMesh() 1.21 +{ 1.22 + delete mesh; 1.23 +} 1.24 + 1.25 +void CoMesh::draw() const 1.26 +{ 1.27 + if(!mesh) return; 1.28 + 1.29 + CoXForm *co_xform = COCAST(CoXForm, gobj->get_component("xform")); 1.30 + if(co_xform) { 1.31 + glPushMatrix(); 1.32 + glMultTransposeMatrixf(co_xform->xform[0]); 1.33 + } 1.34 + 1.35 + mesh->draw(); 1.36 + 1.37 + if(co_xform) { 1.38 + glPopMatrix(); 1.39 + } 1.40 +} 1.41 + 1.42 + 1.43 +CoMesh *gobj_co_mesh(const GObject *obj, bool nofail) 1.44 +{ 1.45 + CoMesh *co = COCAST(CoMesh, obj->get_component("mesh")); 1.46 + if(co) return co; 1.47 + 1.48 + return nofail ? ®_co_mesh : 0; 1.49 +}