From: Jonathan B. <jdb...@un...> - 2004-03-15 18:58:51
|
Bruce Sherwood wrote: > I've added Jonathan's routine to the on-line documentation for "frame" > and also updated the Doc zip file that can be downloaded. Thanks, > Jonathan. > > This does leave open the question however as to whether there ought > not be a method in Visual for resolving pos and axis information. In > particular, I believe that even Jonathan's routine isn't really > complete if this frame is inside another frame: one should really > recurse up the enclosing frames. > > Bruce Sherwood > > Jonathan Brandmeyer wrote: > >> Let me amend that routine. You also have to normalize the y_axis vector >> (smacks self on head). >> >> def world_space_pos( frame, local): >> """Returns the position of local in world space.""" >> x_axis = norm(frame.axis) >> z_axis = norm(cross(frame.axis, frame.up)) >> y_axis = norm(cross(z_axis, x_axis)) >> return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis > Bruce is right: the above function should be named "parent_space_pos" instead. For completeness, here is what the recursive version would look like, in the event anyone needs it right now: def world_space_pos(frame, local): x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) parent_space = frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis if (frame.frame == None): return parent_space else: return world_space_pos(frame.frame, parent_space) |