|
From: Jonathan B. <jbr...@ea...> - 2004-03-14 22:13:11
|
On Sun, 2004-03-14 at 15:52, Axawire wrote:
> hi
>
> i have created a few frame objects and moved them about in the scene and
> rotated them. if i select an object in a frame how do i get its pos in world
> co-ordinates (co-ordinates of the whole scene)?
>
> thanks
>
Simple case: the orientation of the frame has not changed (ie, up points
along +y and axis points along +x) simply add the object's pos to the
frame's pos.
Harder case: the orientation of the frame is different. In this case
you will need to calculate the unit vectors representing the axes of the
frames local coordinate system, and calculate the object's displacement
along those unit vectors.
# Requirements:
# frame has the following attributes: vector pos, vector axis, vector up
# (met by all primitive objects in Visual).
# local has the following attributes: double x, double y, double z.
# (met by vectors and primitive objects in Visual).
# frame.axis and frame.up are not colinear. (undefined coordinate
# system)
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 = cross(z_axis, x_axis))
return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis
HTH,
-Jonathan Brandmeyer
|