coeng

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/comp_xform.cc	Thu Feb 05 11:04:07 2015 +0200
     1.3 @@ -0,0 +1,41 @@
     1.4 +#include <assert.h>
     1.5 +#include "comp_xform.h"
     1.6 +#include "gameobj.h"
     1.7 +
     1.8 +static Component *cons_xform() { return new CompXForm; }
     1.9 +static Component *cons_prs() { return new CompPRS; }
    1.10 +
    1.11 +CompXForm::CompXForm()
    1.12 +{
    1.13 +	name = "xform";
    1.14 +
    1.15 +	register_component(name, cons_xform);
    1.16 +}
    1.17 +
    1.18 +CompPRS::CompPRS()
    1.19 +{
    1.20 +	name = "prs";
    1.21 +
    1.22 +	register_component(name, cons_prs);
    1.23 +}
    1.24 +
    1.25 +void CompPRS::update()
    1.26 +{
    1.27 +	if(!gobj) return;
    1.28 +
    1.29 +	if(!co_xform) {
    1.30 +		Component *co = gobj->get_component("xform");
    1.31 +		if(!co || !(co_xform = dynamic_cast<CompXForm*>(co))) {
    1.32 +			assert(co_xform);
    1.33 +			return;
    1.34 +		}
    1.35 +	}
    1.36 +
    1.37 +	Matrix4x4 rmat = rot.get_rotation_matrix();
    1.38 +	Matrix4x4 tmat, smat;
    1.39 +
    1.40 +	tmat.set_translation(pos);
    1.41 +	smat.set_scaling(scale);
    1.42 +
    1.43 +	co_xform->xform = rmat * tmat * smat;
    1.44 +}