Difference between revisions of "Viewer coordinate frames"

From Second Life Wiki
Jump to navigation Jump to search
m (grammar / typo fix)
Line 22: Line 22:
:Child prims (not root prims) are positioned local to the root prim; their global position and angle effected by both the root prims rotation and position.
:Child prims (not root prims) are positioned local to the root prim; their global position and angle effected by both the root prims rotation and position.
:<h4> Attachments </h4>
:<h4> Attachments </h4>
:Objects that are attached are positioned local to the attach point; their global position and angle effected by the position and rotation of the avatar and the playing animations.
:Objects that are attached are positioned local to the attach point; their global position and angle are affected by the position and rotation of the avatar and the playing animations.


= Naming conventions =
= Naming conventions =

Revision as of 09:43, 27 August 2007

Coordinate frames

There are currently four different reference frames which are being used on the viewer. Note that there are a couple of cases in the code which do NOT follow this convention on the viewer: The rendering code uses "World" and "W" for Agent, and some of the character/joint code doesn't have a coordinate frame specified, but is specified in Agent. Also, common libraries (LLCamera and LLPrimitive in particular) do NOT use this convention. Be particularly careful when pulling values directly out of these.

Global

Absolute global coordinate frame, expressed using F64's. This is derived from the U32 x and y coords of the handles of regions, plus the region offset. Precise enough for ~1x10e9 regions on an edge with same precision as region-local coordinates.

Region

Origin is the origin of the region which "owns" the object.

Agent

Currently, the origin is the origin of the agent's current region. THIS DOES NOT necessarily have to be the case in the future. This should be used only for code involving rendering (pipeline, visibility/frustum calculations)

Local

Currently a catch-all for coordinate frames which are not one of the ones above. Generally object-relative positioning.

The local frame is used in two ways in LSL:

Child Prims

Child prims (not root prims) are positioned local to the root prim; their global position and angle effected by both the root prims rotation and position.

Attachments

Objects that are attached are positioned local to the attach point; their global position and angle are affected by the position and rotation of the avatar and the playing animations.

Naming conventions

ALL variables/class members dealing with values in one of these coordinate frames should be post-fixed appended with the coordinate frame that it's being used in. PLEASE do this - it greatly reduces errors.

For example:

mPositionGlobal, pos_global
mPositionRegion, pos_region
mPositionAgent, pos_agent

Conversion functions

In LLAgent and LLViewerRegion there are conversion functions for converting from one coordinate frame to the other. They have syntax of the form getPos<target>From<source() - i.e. getPosAgentFromGlobal() converts from the global coordinate frame to the agent coordinate frame.


Type conversion

In order to support the high-precision global coordinates, there is a new class LLVector3d, standing for LLVector3, double precision. It's somewhat inconsistent, but the only other alternative was renaming ALL of the math classes to use the GL style last-letter type convention, which I wasn't up to doing.

ALL math being done in global coordinates should be done using LLVector3ds. Currently, all functions which return global coordinates do so in LLVector3ds. The ONLY current exception to this is audio, which I am converting to regular LLVector3s before handing them off to the audio engine - I guess this will be the case until we convert the audio engine to use agent coords.


The LLVector3d class DELIBERATELY does not have ANY form of automatic type-conversion between it and the LLVector3 class. Since conversion back and forth isn't cheap (and potentially loses precision), you have to explicitly do a setVec() on the other class to convert back and forth.