coeng
annotate 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 |
rev | line source |
---|---|
nuclear@2 | 1 #include <assert.h> |
nuclear@2 | 2 #include "comp_xform.h" |
nuclear@2 | 3 #include "gameobj.h" |
nuclear@2 | 4 |
nuclear@2 | 5 static Component *cons_xform() { return new CompXForm; } |
nuclear@2 | 6 static Component *cons_prs() { return new CompPRS; } |
nuclear@2 | 7 |
nuclear@2 | 8 CompXForm::CompXForm() |
nuclear@2 | 9 { |
nuclear@2 | 10 name = "xform"; |
nuclear@2 | 11 |
nuclear@2 | 12 register_component(name, cons_xform); |
nuclear@2 | 13 } |
nuclear@2 | 14 |
nuclear@2 | 15 CompPRS::CompPRS() |
nuclear@2 | 16 { |
nuclear@2 | 17 name = "prs"; |
nuclear@2 | 18 |
nuclear@2 | 19 register_component(name, cons_prs); |
nuclear@2 | 20 } |
nuclear@2 | 21 |
nuclear@2 | 22 void CompPRS::update() |
nuclear@2 | 23 { |
nuclear@2 | 24 if(!gobj) return; |
nuclear@2 | 25 |
nuclear@2 | 26 if(!co_xform) { |
nuclear@2 | 27 Component *co = gobj->get_component("xform"); |
nuclear@2 | 28 if(!co || !(co_xform = dynamic_cast<CompXForm*>(co))) { |
nuclear@2 | 29 assert(co_xform); |
nuclear@2 | 30 return; |
nuclear@2 | 31 } |
nuclear@2 | 32 } |
nuclear@2 | 33 |
nuclear@2 | 34 Matrix4x4 rmat = rot.get_rotation_matrix(); |
nuclear@2 | 35 Matrix4x4 tmat, smat; |
nuclear@2 | 36 |
nuclear@2 | 37 tmat.set_translation(pos); |
nuclear@2 | 38 smat.set_scaling(scale); |
nuclear@2 | 39 |
nuclear@2 | 40 co_xform->xform = rmat * tmat * smat; |
nuclear@2 | 41 } |