coeng

view src/co_xform.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 0e5da17d589c
children 8cce82794f90
line source
1 #include <assert.h>
2 #include "co_xform.h"
3 #include "gobj.h"
5 static CoXForm reg_co_xform;
6 static CoPRS reg_co_prs;
8 static Component *cons_xform() { return new CoXForm; }
9 static Component *cons_prs() { return new CoPRS; }
11 CoXForm::CoXForm()
12 {
13 name = "xform";
15 register_component(name, cons_xform);
16 }
18 // ---- class CoPRS ----
20 CoPRS::CoPRS()
21 : scale(1, 1, 1)
22 {
23 name = "prs";
25 register_component(name, cons_prs);
26 }
28 const char **CoPRS::update_before() const
29 {
30 static const char *before[] = { "xform", 0 };
31 return before;
32 }
34 void CoPRS::update(float dt)
35 {
36 if(!gobj) return;
38 if(!co_xform) {
39 if(!(co_xform = COCAST(CoXForm, gobj->get_component("xform")))) {
40 assert(co_xform);
41 return;
42 }
43 }
45 Matrix4x4 rmat = rot.get_rotation_matrix();
46 Matrix4x4 tmat, smat;
48 tmat.set_translation(pos);
49 smat.set_scaling(scale);
51 co_xform->xform = rmat * tmat * smat;
52 }