coeng
annotate src/comp_xform.cc @ 4:49a2e70ac455
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 10 Feb 2015 17:21:30 +0200 |
parents | 4a1c9597f4d3 |
children |
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@3 | 5 static CompXForm reg_co_xform; |
nuclear@3 | 6 static CompPRS reg_co_prs; |
nuclear@3 | 7 |
nuclear@2 | 8 static Component *cons_xform() { return new CompXForm; } |
nuclear@2 | 9 static Component *cons_prs() { return new CompPRS; } |
nuclear@2 | 10 |
nuclear@2 | 11 CompXForm::CompXForm() |
nuclear@2 | 12 { |
nuclear@2 | 13 name = "xform"; |
nuclear@2 | 14 |
nuclear@2 | 15 register_component(name, cons_xform); |
nuclear@2 | 16 } |
nuclear@2 | 17 |
nuclear@2 | 18 CompPRS::CompPRS() |
nuclear@2 | 19 { |
nuclear@2 | 20 name = "prs"; |
nuclear@2 | 21 |
nuclear@2 | 22 register_component(name, cons_prs); |
nuclear@2 | 23 } |
nuclear@2 | 24 |
nuclear@2 | 25 void CompPRS::update() |
nuclear@2 | 26 { |
nuclear@2 | 27 if(!gobj) return; |
nuclear@2 | 28 |
nuclear@2 | 29 if(!co_xform) { |
nuclear@2 | 30 Component *co = gobj->get_component("xform"); |
nuclear@2 | 31 if(!co || !(co_xform = dynamic_cast<CompXForm*>(co))) { |
nuclear@2 | 32 assert(co_xform); |
nuclear@2 | 33 return; |
nuclear@2 | 34 } |
nuclear@2 | 35 } |
nuclear@2 | 36 |
nuclear@2 | 37 Matrix4x4 rmat = rot.get_rotation_matrix(); |
nuclear@2 | 38 Matrix4x4 tmat, smat; |
nuclear@2 | 39 |
nuclear@2 | 40 tmat.set_translation(pos); |
nuclear@2 | 41 smat.set_scaling(scale); |
nuclear@2 | 42 |
nuclear@2 | 43 co_xform->xform = rmat * tmat * smat; |
nuclear@2 | 44 } |