coeng
annotate src/co_xform.cc @ 7:af24cfbdf9b6
adding collision detection
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Feb 2015 10:08:00 +0200 |
parents | 0e5da17d589c |
children | 8cce82794f90 |
rev | line source |
---|---|
nuclear@2 | 1 #include <assert.h> |
nuclear@5 | 2 #include "co_xform.h" |
nuclear@5 | 3 #include "gobj.h" |
nuclear@2 | 4 |
nuclear@5 | 5 static CoXForm reg_co_xform; |
nuclear@5 | 6 static CoPRS reg_co_prs; |
nuclear@3 | 7 |
nuclear@5 | 8 static Component *cons_xform() { return new CoXForm; } |
nuclear@5 | 9 static Component *cons_prs() { return new CoPRS; } |
nuclear@2 | 10 |
nuclear@5 | 11 CoXForm::CoXForm() |
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@6 | 18 // ---- class CoPRS ---- |
nuclear@6 | 19 |
nuclear@5 | 20 CoPRS::CoPRS() |
nuclear@6 | 21 : scale(1, 1, 1) |
nuclear@2 | 22 { |
nuclear@2 | 23 name = "prs"; |
nuclear@2 | 24 |
nuclear@2 | 25 register_component(name, cons_prs); |
nuclear@2 | 26 } |
nuclear@2 | 27 |
nuclear@6 | 28 const char **CoPRS::update_before() const |
nuclear@6 | 29 { |
nuclear@6 | 30 static const char *before[] = { "xform", 0 }; |
nuclear@6 | 31 return before; |
nuclear@6 | 32 } |
nuclear@6 | 33 |
nuclear@6 | 34 void CoPRS::update(float dt) |
nuclear@2 | 35 { |
nuclear@2 | 36 if(!gobj) return; |
nuclear@2 | 37 |
nuclear@2 | 38 if(!co_xform) { |
nuclear@6 | 39 if(!(co_xform = COCAST(CoXForm, gobj->get_component("xform")))) { |
nuclear@2 | 40 assert(co_xform); |
nuclear@2 | 41 return; |
nuclear@2 | 42 } |
nuclear@2 | 43 } |
nuclear@2 | 44 |
nuclear@2 | 45 Matrix4x4 rmat = rot.get_rotation_matrix(); |
nuclear@2 | 46 Matrix4x4 tmat, smat; |
nuclear@2 | 47 |
nuclear@2 | 48 tmat.set_translation(pos); |
nuclear@2 | 49 smat.set_scaling(scale); |
nuclear@2 | 50 |
nuclear@2 | 51 co_xform->xform = rmat * tmat * smat; |
nuclear@2 | 52 } |