coeng

view 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 source
1 #ifndef __APPLE__
2 #include <GL/glut.h>
3 #else
4 #include <GLUT/glut.h>
5 #endif
6 #include "co_dbgvis.h"
7 #include "gobj.h"
9 static CoSphereVis reg_co_sphere;
11 static Component *cons_sphere() { return new CoSphereVis; }
14 CoSphereVis::CoSphereVis()
15 : color(1, 1, 1)
16 {
17 name = "spherevis";
18 radius = 1.0;
19 co_xform = 0;
21 register_component(name, cons_sphere);
22 }
24 void CoSphereVis::update(float dt)
25 {
26 if(!co_xform) {
27 co_xform = COCAST(CoXForm, gobj->get_component("xform"));
28 }
29 }
31 void CoSphereVis::draw() const
32 {
33 if(co_xform) {
34 Matrix4x4 xform = co_xform->xform.transposed();
36 glPushMatrix();
37 glMultMatrixf(xform.m[0]);
38 }
40 float diffuse[] = { color.x, color.y, color.z, 1.0f };
41 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuse);
43 glutSolidSphere(radius, 16, 8);
45 if(co_xform) {
46 glPopMatrix();
47 }
48 }