1 module des.space.node; 2 3 public import des.math.linear.vector; 4 public import des.math.linear.matrix; 5 public import des.space.transform; 6 7 import des.ts; 8 import des.arch.tree; 9 10 /// 11 interface SpaceNode : Transform, TNode!(SpaceNode,"space") 12 { 13 /++ past code 14 + --- 15 + mixin spaceTNodeHelper!(true,true); 16 + --- 17 + 18 + if `with_matrix_field` field realization for `matrix` property (with setters) 19 +/ 20 mixin template SpaceNodeHelper(bool with_matrix_field=true) 21 { 22 mixin spaceTNodeHelper!(true,true); 23 24 static if( with_matrix_field ) 25 { 26 protected mat4 self_mtr; 27 28 public @property 29 { 30 mat4 matrix() const { return self_mtr; } 31 mat4 matrix( in mat4 m ) { self_mtr = m; return m; } 32 33 vec3 offset() const { return vec3( self_mtr.col(3).data[0..3] ); } 34 vec3 offset( in vec3 o ) { self_mtr.setCol( 3, vec4( o, matrix[3][3] ) ); return o; } 35 } 36 } 37 } 38 39 const @property 40 { 41 /// local to parent transform 42 mat4 matrix(); 43 44 /// in parent system 45 vec3 offset(); 46 47 final 48 { 49 /// e1 50 vec3 baseX() { return vec3( matrix.col(0).data[0 .. 3] ); } 51 /// e2 52 vec3 baseY() { return vec3( matrix.col(1).data[0 .. 3] ); } 53 /// e3 54 vec3 baseZ() { return vec3( matrix.col(2).data[0 .. 3] ); } 55 } 56 } 57 } 58 59 final class DimmyNode : SpaceNode 60 { 61 mixin SpaceNodeHelper; 62 this( SpaceNode par = null ) { spaceParent = par; } 63 } 64 65 unittest 66 { 67 auto tsn = new DimmyNode; 68 69 assertEq( tsn.baseX, vec3( 1,0,0 ) ); 70 assertEq( tsn.baseY, vec3( 0,1,0 ) ); 71 assertEq( tsn.baseZ, vec3( 0,0,1 ) ); 72 assertEq( tsn.offset, vec3( 0,0,0 ) ); 73 74 tsn.offset = vec3( 1, 2, 3 ); 75 76 assertEq( vec4( tsn.matrix.col(3) ), vec4(1,2,3,1) ); 77 tsn.matrix = mat4.init; 78 assertEq( tsn.offset, vec3(0,0,0) ); 79 }