coeng

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