coeng

view src/comp_xform.cc @ 3:66d1762eb203

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