1 /+
2 The MIT License (MIT)
3 
4     Copyright (c) <2013> <Oleg Butko (deviator), Anton Akzhigitov (Akzwar)>
5 
6     Permission is hereby granted, free of charge, to any person obtaining a copy
7     of this software and associated documentation files (the "Software"), to deal
8     in the Software without restriction, including without limitation the rights
9     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10     copies of the Software, and to permit persons to whom the Software is
11     furnished to do so, subject to the following conditions:
12 
13     The above copyright notice and this permission notice shall be included in
14     all copies or substantial portions of the Software.
15 
16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22     THE SOFTWARE.
23 +/
24 
25 module des.space.node;
26 
27 public import des.math.linear.vector;
28 public import des.math.linear.matrix;
29 public import des.space.transform;
30 
31 import des.util.arch.tree;
32 
33 ///
34 interface SpaceNode : Transform, TNode!(SpaceNode,"space")
35 {
36     ///
37     mixin template SpaceNodeHelper(bool with_matrix_property=true)
38     {
39         mixin spaceTNodeHelper!(true,true,true);
40 
41         protected mat4 self_mtr;
42 
43         static if( with_matrix_property )
44             mat4 matrix() @property const { return self_mtr; }
45     }
46 
47     const @property
48     {
49         /// local to parent transform
50         mat4 matrix();
51 
52         final
53         {
54             ///
55             vec3 baseX() { return vec3( matrix.col(0).data[0 .. 3] ); }
56             ///
57             vec3 baseY() { return vec3( matrix.col(1).data[0 .. 3] ); }
58             ///
59             vec3 baseZ() { return vec3( matrix.col(2).data[0 .. 3] ); }
60 
61             /// in parent system
62             vec3 offset() { return vec3( matrix.col(3).data[0 .. 3] ); }
63         }
64     }
65 }
66 
67 final class DimmyNode : SpaceNode
68 {
69     mixin SpaceNodeHelper!false;
70 
71     this( SpaceNode par = null ) { spaceParent = par; }
72 
73     @property
74     {
75         mat4 matrix() const { return self_mtr; }
76         ref mat4 matrix() { return self_mtr; }
77     }
78 
79     void setOffset( in vec3 pnt ) { self_mtr.setCol(3,vec4(pnt,1)); }
80 }