coeng

diff src/co_xform.cc @ 5:0e5da17d589c

decided to really work on this, so first a slight rename
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Feb 2015 01:35:42 +0200
parents src/comp_xform.cc@66d1762eb203
children 2f872a179914
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/co_xform.cc	Sat Feb 14 01:35:42 2015 +0200
     1.3 @@ -0,0 +1,44 @@
     1.4 +#include <assert.h>
     1.5 +#include "co_xform.h"
     1.6 +#include "gobj.h"
     1.7 +
     1.8 +static CoXForm reg_co_xform;
     1.9 +static CoPRS reg_co_prs;
    1.10 +
    1.11 +static Component *cons_xform() { return new CoXForm; }
    1.12 +static Component *cons_prs() { return new CoPRS; }
    1.13 +
    1.14 +CoXForm::CoXForm()
    1.15 +{
    1.16 +	name = "xform";
    1.17 +
    1.18 +	register_component(name, cons_xform);
    1.19 +}
    1.20 +
    1.21 +CoPRS::CoPRS()
    1.22 +{
    1.23 +	name = "prs";
    1.24 +
    1.25 +	register_component(name, cons_prs);
    1.26 +}
    1.27 +
    1.28 +void CoPRS::update()
    1.29 +{
    1.30 +	if(!gobj) return;
    1.31 +
    1.32 +	if(!co_xform) {
    1.33 +		Component *co = gobj->get_component("xform");
    1.34 +		if(!co || !(co_xform = dynamic_cast<CoXForm*>(co))) {
    1.35 +			assert(co_xform);
    1.36 +			return;
    1.37 +		}
    1.38 +	}
    1.39 +
    1.40 +	Matrix4x4 rmat = rot.get_rotation_matrix();
    1.41 +	Matrix4x4 tmat, smat;
    1.42 +
    1.43 +	tmat.set_translation(pos);
    1.44 +	smat.set_scaling(scale);
    1.45 +
    1.46 +	co_xform->xform = rmat * tmat * smat;
    1.47 +}