coeng
diff src/co_dbgvis.cc @ 6:2f872a179914
first component test:
- prs, xform, physics components with dependencies
- topological sort of components to update them in the correct order
- debug visualization component
todo: remove draw() from components, doesn't make sense
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Feb 2015 07:27:12 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/co_dbgvis.cc Sat Feb 14 07:27:12 2015 +0200 1.3 @@ -0,0 +1,48 @@ 1.4 +#ifndef __APPLE__ 1.5 +#include <GL/glut.h> 1.6 +#else 1.7 +#include <GLUT/glut.h> 1.8 +#endif 1.9 +#include "co_dbgvis.h" 1.10 +#include "gobj.h" 1.11 + 1.12 +static CoSphereVis reg_co_sphere; 1.13 + 1.14 +static Component *cons_sphere() { return new CoSphereVis; } 1.15 + 1.16 + 1.17 +CoSphereVis::CoSphereVis() 1.18 + : color(1, 1, 1) 1.19 +{ 1.20 + name = "spherevis"; 1.21 + radius = 1.0; 1.22 + co_xform = 0; 1.23 + 1.24 + register_component(name, cons_sphere); 1.25 +} 1.26 + 1.27 +void CoSphereVis::update(float dt) 1.28 +{ 1.29 + if(!co_xform) { 1.30 + co_xform = COCAST(CoXForm, gobj->get_component("xform")); 1.31 + } 1.32 +} 1.33 + 1.34 +void CoSphereVis::draw() const 1.35 +{ 1.36 + if(co_xform) { 1.37 + Matrix4x4 xform = co_xform->xform.transposed(); 1.38 + 1.39 + glPushMatrix(); 1.40 + glMultMatrixf(xform.m[0]); 1.41 + } 1.42 + 1.43 + float diffuse[] = { color.x, color.y, color.z, 1.0f }; 1.44 + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuse); 1.45 + 1.46 + glutSolidSphere(radius, 16, 8); 1.47 + 1.48 + if(co_xform) { 1.49 + glPopMatrix(); 1.50 + } 1.51 +}