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.math.linear.view.node; 26 27 public import des.math.linear.vector; 28 public import des.math.linear.matrix; 29 public import des.math.linear.view.transform; 30 31 interface Node : Transform 32 { 33 const @property 34 { 35 /+ local to parent transform +/ 36 mat4 matrix(); 37 38 const(Node) parent(); 39 40 final 41 { 42 vec3 baseX() { return vec3( matrix.col(0).data[0 .. 3] ); } 43 vec3 baseY() { return vec3( matrix.col(1).data[0 .. 3] ); } 44 vec3 baseZ() { return vec3( matrix.col(2).data[0 .. 3] ); } 45 46 /+ in parent system +/ 47 vec3 offset() { return vec3( matrix.col(3).data[0 .. 3] ); } 48 } 49 } 50 } 51 52 final class DimmyNode : Node 53 { 54 private: 55 Node _parent; 56 mat4 _matrix = mat4.diag(1); 57 58 public: 59 this( Node par = null ) { _parent = par; } 60 61 @property 62 { 63 mat4 matrix() const { return _matrix; } 64 ref mat4 matrix() { return _matrix; } 65 const(Node) parent() const { return _parent; } 66 void parent( Node par ) { _parent = par; } 67 } 68 69 void setOffset( in vec3 pnt ) { _matrix.setCol(3,vec4(pnt,1)); } 70 } 71 72 class TransformNode : Node 73 { 74 protected: 75 Node _parent; 76 77 public: 78 Transform transform; 79 80 this( Node par = null ) { _parent = par; } 81 82 @property 83 { 84 mat4 matrix() const 85 { 86 if( transform !is null ) 87 return transform.matrix; 88 else return mat4.diag(1); 89 } 90 91 const(Node) parent() const { return _parent; } 92 void parent( Node par ) { _parent = par; } 93 } 94 }