coeng
annotate 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 |
rev | line source |
---|---|
nuclear@8 | 1 #include "opengl.h" |
nuclear@8 | 2 #include "co_mesh.h" |
nuclear@8 | 3 #include "co_xform.h" |
nuclear@8 | 4 #include "gobj.h" |
nuclear@8 | 5 |
nuclear@8 | 6 static CoMesh reg_co_mesh; |
nuclear@8 | 7 static Component *cons_co_mesh() { return new CoMesh; } |
nuclear@8 | 8 |
nuclear@8 | 9 CoMesh::CoMesh() |
nuclear@8 | 10 { |
nuclear@8 | 11 name = "mesh"; |
nuclear@8 | 12 mesh = 0; |
nuclear@8 | 13 |
nuclear@8 | 14 register_component(name, cons_co_mesh); |
nuclear@8 | 15 } |
nuclear@8 | 16 |
nuclear@8 | 17 CoMesh::~CoMesh() |
nuclear@8 | 18 { |
nuclear@8 | 19 delete mesh; |
nuclear@8 | 20 } |
nuclear@8 | 21 |
nuclear@8 | 22 void CoMesh::draw() const |
nuclear@8 | 23 { |
nuclear@8 | 24 if(!mesh) return; |
nuclear@8 | 25 |
nuclear@8 | 26 CoXForm *co_xform = COCAST(CoXForm, gobj->get_component("xform")); |
nuclear@8 | 27 if(co_xform) { |
nuclear@8 | 28 glPushMatrix(); |
nuclear@8 | 29 glMultTransposeMatrixf(co_xform->xform[0]); |
nuclear@8 | 30 } |
nuclear@8 | 31 |
nuclear@8 | 32 mesh->draw(); |
nuclear@8 | 33 |
nuclear@8 | 34 if(co_xform) { |
nuclear@8 | 35 glPopMatrix(); |
nuclear@8 | 36 } |
nuclear@8 | 37 } |
nuclear@8 | 38 |
nuclear@8 | 39 |
nuclear@8 | 40 CoMesh *gobj_co_mesh(const GObject *obj, bool nofail) |
nuclear@8 | 41 { |
nuclear@8 | 42 CoMesh *co = COCAST(CoMesh, obj->get_component("mesh")); |
nuclear@8 | 43 if(co) return co; |
nuclear@8 | 44 |
nuclear@8 | 45 return nofail ? ®_co_mesh : 0; |
nuclear@8 | 46 } |