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