Open topic with navigation
Tutorial: Querying Position
Key Concepts
- Retrieve a node's position within a given coordinate
system with the <node3d>.getPosition(
coordinateSystem ) method.
- When getting the position in a node's parent coordinate
system, the modified offset encoded within the node's transformation matrix
is returned. When
the position is retrieved in the global coordinate system, the node's
transformation matrix offset is added to all of its parent's offsets to
obtain the global position.
Explanation
The next section gives some hard numbers regarding the position difference
we can see between the pigeons by demonstrating the use of the getPosition
method. Add and run the following code, then take a look at the output:
# default argument of getPosition is viz.ABS_PARENT
print("childPigeon's position
offset from parent:", childPigeon.getPosition())
print("worldPigeon's position
offset from parent:", worldPigeon.getPosition())
# Get the position in viz.ABS_GLOBAL not the default,viz.ABS_PARENT
print("childPigeon's global position:", childPigeon.getPosition(viz.ABS_GLOBAL))
print("worldPigeon's global position:", worldPigeon.getPosition(viz.ABS_GLOBAL))
Calling getPosition without any arguments
uses the default argument viz.ABS_PARENT
(absolute parent) and retrieves the position offset encoded in the node's
transformation matrix without any modification. Notice
that the value returned by getPosition is
the same for both pigeons. When the first parameter of getPosition
is supplied with viz.ABS_GLOBAL (absolute
global) it returns the node's position relative to the global/world origin.
Thus, as
we can see when we look at the world, childPigeon's
global position is different than worldPigeon's.