coeng

view src/comp_xform.cc @ 2:4a1c9597f4d3

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 05 Feb 2015 11:04:07 +0200
parents
children 66d1762eb203
line source
1 #include <assert.h>
2 #include "comp_xform.h"
3 #include "gameobj.h"
5 static Component *cons_xform() { return new CompXForm; }
6 static Component *cons_prs() { return new CompPRS; }
8 CompXForm::CompXForm()
9 {
10 name = "xform";
12 register_component(name, cons_xform);
13 }
15 CompPRS::CompPRS()
16 {
17 name = "prs";
19 register_component(name, cons_prs);
20 }
22 void CompPRS::update()
23 {
24 if(!gobj) return;
26 if(!co_xform) {
27 Component *co = gobj->get_component("xform");
28 if(!co || !(co_xform = dynamic_cast<CompXForm*>(co))) {
29 assert(co_xform);
30 return;
31 }
32 }
34 Matrix4x4 rmat = rot.get_rotation_matrix();
35 Matrix4x4 tmat, smat;
37 tmat.set_translation(pos);
38 smat.set_scaling(scale);
40 co_xform->xform = rmat * tmat * smat;
41 }