1 module des.space.resolver; 2 3 public import des.math.linear.vector; 4 public import des.math.linear.matrix; 5 public import des.space.node; 6 7 /++ 8 resolve transform matrix from obj space node to cam space node 9 +/ 10 class Resolver 11 { 12 /// 13 mat4 opCall( const(SpaceNode) obj, const(SpaceNode) cam ) const 14 { 15 const(SpaceNode)[] obj_branch, cam_branch; 16 obj_branch ~= obj; 17 cam_branch ~= cam; 18 19 while( obj_branch[$-1] ) 20 obj_branch ~= obj_branch[$-1].spaceParent; 21 while( cam_branch[$-1] ) 22 cam_branch ~= cam_branch[$-1].spaceParent; 23 24 top: 25 foreach( cbi, cam_parent; cam_branch ) 26 foreach( obi, obj_parent; obj_branch ) 27 if( cam_parent == obj_parent ) 28 { 29 cam_branch = cam_branch[0 .. cbi]; 30 obj_branch = obj_branch[0 .. obi]; 31 break top; 32 } 33 34 mat4 obj_mtr, cam_mtr; 35 36 foreach( node; obj_branch ) 37 obj_mtr = node.matrix * obj_mtr; 38 39 foreach( node; cam_branch ) 40 cam_mtr = cam_mtr * node.matrix.speedTransformInv; 41 42 return cam_mtr * obj_mtr; 43 } 44 }