public class Frame extends Object implements Copyable
position()
, an
orientation()
and magnitude()
. The order of these transformations is
important: the Frame is first translated, then rotated around the new translated origin
and then scaled. This class API aims to conform that of the great
libQGLViewer
Frame, but it adds magnitude()
to it.
A Frame is useful to define the position, orientation and magnitude of an object, using
its matrix()
method, as shown below:
// Builds a Frame at position (0.5,0,0) and oriented such that its Y axis is along the (1,1,1)
// direction. One could also have used setPosition() and setOrientation().
Frame fr(new Vec(0.5,0,0), new Quat(new Vec(0,1,0), new Vec(1,1,1)));
scene.pushModelView();
scene.applyModelView(fr.matrix());
// Draw your object here, in the local fr coordinate system.
scene.popModelView();
Many functions are provided to transform a point from one coordinate system (Frame) to
an other: see coordinatesOf(Vec)
, inverseCoordinatesOf(Vec)
,
coordinatesOfIn(Vec, Frame)
, coordinatesOfFrom(Vec, Frame)
...
You may also want to transform a vector (such as a normal), which corresponds to
applying only the rotational part of the frame transformation: see
transformOf(Vec)
and inverseTransformOf(Vec)
.
The translation()
, rotation()
and uniform positive scaling()
that are encapsulated in a Frame can also be used to represent an angle preserving
transformation of space. Such a transformation can also be interpreted as a change of
coordinate system, and the coordinate system conversion functions actually allow you to
use a Frame as an angle preserving transformation. Use
inverseCoordinatesOf(Vec)
(resp. coordinatesOf(Vec)
) to apply the
transformation (resp. its inverse). Note the inversion.
The position, orientation and magnitude of a Frame are actually defined with respect to
a referenceFrame()
. The default referenceFrame()
is the world
coordinate system (represented by a null
referenceFrame()
). If you
setReferenceFrame(Frame)
to a different Frame, you must then differentiate:
translation()
, rotation()
and scaling()
, defined with respect to the referenceFrame()
.position()
, orientation()
and
magnitude()
, always defined with respect to the world coordinate system.
A Frame is actually defined by its translation()
with respect to its
referenceFrame()
, then by rotation()
of the coordinate system around
the new translated origin and then by a uniform positive scaling()
along its
rotated axes.
This terminology for local (translation()
, rotation()
and
scaling()
) and global ( position()
, orientation()
and
magnitude()
) definitions is used in all the methods' names and should be
sufficient to prevent ambiguities. These notions are obviously identical when the
referenceFrame()
is null
, i.e., when the Frame is defined in the world
coordinate system (the one you are left with after calling
AbstractScene.preDraw()
).
Frames can hence easily be organized in a tree hierarchy, which root is the world
coordinate system. A loop in the hierarchy would result in an inconsistent (multiple)
Frame definition. Therefore settingAsReferenceFrameWillCreateALoop(Frame)
checks this and prevents referenceFrame()
from creating such a loop.
This frame hierarchy is used in methods like coordinatesOfIn(Vec, Frame)
,
coordinatesOfFrom(Vec, Frame)
... which allow coordinates (or vector)
conversions from a Frame to any other one (including the world coordinate system).
An interesting feature of Frames is that their displacements can be constrained. When a
Constraint
is attached to a Frame, it filters the
input of translate(Vec)
and rotate(Rotation)
, and only the resulting
filtered motion is applied to the Frame. The default constraint()
null
resulting in no filtering. Use setConstraint(Constraint)
to attach a
Constraint to a frame.
Classical constraints are provided for convenience (see
LocalConstraint
,
WorldConstraint
and
EyeConstraint
) and new constraints can very
easily be implemented.
The GenericFrame
class inherits Frame and implements
all sorts of motion actions, so that a Frame (and hence an object) can be manipulated
in the scene by whatever user interaction means you can imagine.
Constructor and Description |
---|
Frame() |
Frame(boolean three_d)
Same as
this(null, new Vec(), three_d ? new Quat() : new Rot(), 1) . |
Frame(Frame referenceFrame,
Rotation r,
float s)
Same as
this(referenceFrame, new Vec(), r, 1) . |
Frame(Frame referenceFrame,
Vec p,
Rotation r)
Same as
this(referenceFrame, p, r, 1) . |
Frame(Frame referenceFrame,
Vec p,
Rotation r,
float s)
Creates a Frame with
referenceFrame as referenceFrame() , and
p , r and s as the frame translation() ,
rotation() and scaling() , respectively. |
Frame(Rotation r,
float s)
Same as
this(null, new Vec(), r, s) . |
Frame(Vec p,
Rotation r)
Same as
this(p, r, 1) . |
Frame(Vec p,
Rotation r,
float s)
Same as
this(null, p, r, s) . |
Modifier and Type | Method and Description |
---|---|
void |
alignWithFrame(Frame frame)
Convenience function that simply calls
alignWithFrame(frame, false, 0.85f) |
void |
alignWithFrame(Frame frame,
boolean move)
Convenience function that simply calls
alignWithFrame(frame, move, 0.85f) |
void |
alignWithFrame(Frame frame,
boolean move,
float threshold)
Aligns the Frame with
frame , so that two of their axis are parallel. |
void |
alignWithFrame(Frame frame,
float threshold)
Convenience function that simply calls
alignWithFrame(frame, false, threshold) |
Constraint |
constraint()
Returns the current
Constraint applied to the
Frame. |
Vec |
coordinatesOf(Vec src)
Returns the Frame coordinates of a point
src defined in the world coordinate
system (converts from world to Frame). |
Vec |
coordinatesOfFrom(Vec src,
Frame from)
Returns the Frame coordinates of the point whose position in the
from
coordinate system is src (converts from from to Frame). |
Vec |
coordinatesOfIn(Vec src,
Frame in)
Returns the
in coordinates of the point whose position in the Frame
coordinate system is src (converts from Frame to in ). |
boolean |
equals(Object obj) |
void |
fromMatrix(Mat pM)
Convenience function that simply calls
fromMatrix(pM, 1)) . |
void |
fromMatrix(Mat pM,
float scl)
Sets the Frame from a Mat representation: rotation in the upper left 3x3 matrix and
translation on the last column.
|
Frame |
get()
Returns a deep copy of the object.
|
int |
hashCode() |
Frame |
inverse()
Returns a Frame representing the inverse of the Frame space transformation.
|
Vec |
inverseCoordinatesOf(Vec src)
Returns the world coordinates of the point whose position in the Frame coordinate
system is
src (converts from Frame to world). |
Vec |
inverseTransformOf(Vec src)
Returns the world transform of the vector whose coordinates in the Frame coordinate
system is
src (converts vectors from Frame to world). |
boolean |
is2D() |
boolean |
is3D() |
Vec |
localCoordinatesOf(Vec src)
Returns the Frame coordinates of a point
src defined in the
referenceFrame() coordinate system (converts from referenceFrame()
to Frame). |
Vec |
localInverseCoordinatesOf(Vec src)
Returns the
referenceFrame() coordinates of a point src defined in
the Frame coordinate system (converts from Frame to referenceFrame() ). |
Vec |
localInverseTransformOf(Vec src)
Returns the
referenceFrame() transform of a vector src defined in
the Frame coordinate system (converts vectors from Frame to referenceFrame()
). |
Vec |
localTransformOf(Vec src)
Returns the Frame transform of a vector
src defined in the
referenceFrame() coordinate system (converts vectors from
referenceFrame() to Frame). |
float |
magnitude()
Returns the magnitude of the Frame, defined in the world coordinate system.
|
Mat |
matrix()
Returns the local transformation matrix represented by the Frame.
|
Rotation |
orientation()
Returns the orientation of the Frame, defined in the world coordinate system.
|
Vec |
position()
Returns the position of the Frame, defined in the world coordinate system.
|
void |
projectOnLine(Vec origin,
Vec direction)
Translates the Frame so that its
position() lies on the line defined by
origin and direction (defined in the world coordinate system). |
Frame |
referenceFrame()
Returns the reference Frame, in which coordinates system the Frame is defined.
|
void |
rotate(float x,
float y,
float z,
float w)
Same as
rotate(Rotation) but with float rotation parameters. |
void |
rotate(Rotation r)
Rotates the Frame by
r (defined in the Frame coordinate system):
rotation().compose(r) . |
void |
rotateAroundFrame(float roll,
float pitch,
float yaw,
Frame frame) |
void |
rotateAroundFrame(Rotation rotation,
Frame frame) |
void |
rotateAroundPoint(Rotation rotation,
Vec point)
|
Rotation |
rotation()
Returns the Frame rotation, defined with respect to the
referenceFrame()
(i.e, the current Rotation orientation). |
void |
scale(float s)
Scales the Frame according to
s , locally defined with respect to the
referenceFrame() . |
float |
scaling()
Returns the Frame scaling, defined with respect to the
referenceFrame() . |
void |
set(Frame otherFrame)
Same as
#setWorldMatrix(Frame) . |
void |
setConstraint(Constraint c)
Sets the
constraint() attached to the Frame. |
void |
setMagnitude(float m)
Sets the
magnitude() of the Frame, defined in the world coordinate system. |
void |
setMatrix(Frame otherFrame)
|
void |
setOrientation(float x,
float y,
float z,
float w)
Same as
setOrientation(Rotation) , but with float parameters. |
void |
setOrientation(Rotation q)
Sets the
orientation() of the Frame, defined in the world coordinate system. |
void |
setOrientationWithConstraint(Rotation orientation)
Same as
setOrientation(Rotation) , but if there's a constraint() it
is satisfied (without modifying orientation ). |
void |
setPosition(float x,
float y)
Same as
setPosition(Vec) , but with float parameters. |
void |
setPosition(float x,
float y,
float z)
Same as
setPosition(Vec) , but with float parameters. |
void |
setPosition(Vec p)
Sets the
position() of the Frame, defined in the world coordinate system. |
void |
setPositionWithConstraint(Vec position)
Same as
setPosition(Vec) , but if there's a constraint() it is
satisfied (without modifying position ). |
void |
setReferenceFrame(Frame rFrame)
Sets the
referenceFrame() of the Frame. |
void |
setRotation(float a)
Defines a 2D
Rotation . |
void |
setRotation(float x,
float y,
float z,
float w)
Same as
setRotation(Rotation) but with float Rotation parameters. |
void |
setRotation(Rotation r)
Set the current rotation.
|
void |
setRotationWithConstraint(Rotation rotation)
Same as
setRotation(Rotation) , but if there's a constraint() it's
satisfied. |
void |
setScaling(float s)
Sets the
scaling() of the frame, locally defined with respect to the
referenceFrame() . |
boolean |
settingAsReferenceFrameWillCreateALoop(Frame frame)
Returns
true if setting frame as the Frame's
referenceFrame() would create a loop in the Frame hierarchy. |
void |
setTranslation(float x,
float y)
Same as
setTranslation(Vec) , but with float parameters. |
void |
setTranslation(float x,
float y,
float z)
Same as
setTranslation(Vec) , but with float parameters. |
void |
setTranslation(Vec t)
Sets the
translation() of the frame, locally defined with respect to the
referenceFrame() . |
void |
setTranslationWithConstraint(Vec translation)
Same as
setTranslation(Vec) , but if there's a constraint() it is
satisfied. |
void |
setWorldMatrix(Frame otherFrame)
|
void |
setXAxis(Vec axis)
Rotates the frame so that its
xAxis() becomes axis defined in the
world coordinate system. |
void |
setYAxis(Vec axis)
Rotates the frame so that its
yAxis() becomes axis defined in the
world coordinate system. |
void |
setZAxis(Vec axis)
Rotates the frame so that its
zAxis() becomes axis defined in the
world coordinate system. |
Vec |
transformOf(Vec src)
Returns the Frame transform of a vector
src defined in the world coordinate
system (converts vectors from world to Frame). |
Vec |
transformOfFrom(Vec src,
Frame from)
Returns the Frame transform of the vector whose coordinates in the
from
coordinate system is src (converts vectors from from to Frame). |
Vec |
transformOfIn(Vec src,
Frame in)
Returns the
in transform of the vector whose coordinates in the Frame
coordinate system is src (converts vectors from Frame to in ). |
void |
translate(float x,
float y)
Same as
translate(Vec) but with float parameters. |
void |
translate(float x,
float y,
float z)
Same as
translate(Vec) but with float parameters. |
void |
translate(Vec t)
Translates the Frame according to
t , locally defined with respect to the
referenceFrame() . |
Vec |
translation()
Returns the Frame translation, defined with respect to the
referenceFrame() . |
Frame |
worldInverse()
Returns the
inverse() of the Frame world transformation. |
Mat |
worldMatrix()
Returns the global transformation matrix represented by the Frame.
|
Vec |
xAxis()
Same as
return xAxis(true) |
Vec |
xAxis(boolean positive)
Returns the x-axis of the frame, represented as a normalized vector defined in the
world coordinate system.
|
Vec |
yAxis()
Same as
return yAxis(true) |
Vec |
yAxis(boolean positive)
Returns the y-axis of the frame, represented as a normalized vector defined in the
world coordinate system.
|
Vec |
zAxis()
Same as
return zAxis(true) |
Vec |
zAxis(boolean positive)
Returns the z-axis of the frame, represented as a normalized vector defined in the
world coordinate system.
|
public Frame()
public Frame(boolean three_d)
this(null, new Vec(), three_d ? new Quat() : new Rot(), 1)
.Frame(Vec, Rotation, float)
public Frame(Rotation r, float s)
this(null, new Vec(), r, s)
.Frame(Vec, Rotation, float)
public Frame(Vec p, Rotation r)
this(p, r, 1)
.Frame(Vec, Rotation, float)
public Frame(Vec p, Rotation r, float s)
this(null, p, r, s)
.Frame(Frame, Vec, Rotation, float)
public Frame(Frame referenceFrame, Vec p, Rotation r)
this(referenceFrame, p, r, 1)
.Frame(Frame, Vec, Rotation, float)
public Frame(Frame referenceFrame, Rotation r, float s)
this(referenceFrame, new Vec(), r, 1)
.Frame(Frame, Vec, Rotation, float)
public Frame(Frame referenceFrame, Vec p, Rotation r, float s)
referenceFrame
as referenceFrame()
, and
p
, r
and s
as the frame translation()
,
rotation()
and scaling()
, respectively.public Frame get()
Copyable
Typical implementation should simple look like: return new Object(this)
.
public boolean is2D()
public boolean is3D()
public Frame referenceFrame()
The Frame translation()
, rotation()
and scaling()
are
defined with respect to the referenceFrame()
coordinate system. A
null
reference Frame (default value) means that the Frame is defined in the
world coordinate system.
Use position()
, orientation()
and magnitude()
to
recursively convert values along the reference Frame chain and to get values
expressed in the world coordinate system. The values match when the reference Frame
is null
.
Use setReferenceFrame(Frame)
to set this value and create a Frame hierarchy.
Convenient functions allow you to convert coordinates from one Frame to another: see
coordinatesOf(Vec)
, localCoordinatesOf(Vec)
,
coordinatesOfIn(Vec, Frame)
and their inverse functions.
Vectors can also be converted using transformOf(Vec)
,
transformOfIn(Vec, Frame)
, localTransformOf(Vec)
and their inverse
functions.
public void setReferenceFrame(Frame rFrame)
referenceFrame()
of the Frame.
The Frame translation()
, rotation()
and scaling()
are then
defined in the referenceFrame()
coordinate system.
Use position()
, orientation()
and magnitude()
to express
these in the world coordinate system.
Using this method, you can create a hierarchy of Frames. This hierarchy needs to be a
tree, which root is the world coordinate system (i.e., null
referenceFrame()
). No action is performed if setting refFrame
as the
referenceFrame()
would create a loop in the Frame hierarchy.
public final boolean settingAsReferenceFrameWillCreateALoop(Frame frame)
true
if setting frame
as the Frame's
referenceFrame()
would create a loop in the Frame hierarchy.public Constraint constraint()
Constraint
applied to the
Frame.
A null
value (default) means that no Constraint is used to filter the Frame
translation and rotation.
See the Constraint class documentation for details.
public void setConstraint(Constraint c)
constraint()
attached to the Frame.
A null
value means no constraint.
public final Vec translation()
referenceFrame()
.
Use position()
to get the result in world coordinates. These two values are
identical when the referenceFrame()
is null
(default).
public final void setTranslation(Vec t)
translation()
of the frame, locally defined with respect to the
referenceFrame()
.
Use setPosition(Vec)
to define the world coordinates position()
.
Use setTranslationWithConstraint(Vec)
to take into account the potential
constraint()
of the Frame.
public final void setTranslationWithConstraint(Vec translation)
setTranslation(Vec)
, but if there's a constraint()
it is
satisfied.public final void setTranslation(float x, float y)
setTranslation(Vec)
, but with float
parameters.public final void setTranslation(float x, float y, float z)
setTranslation(Vec)
, but with float
parameters.public final void translate(float x, float y, float z)
translate(Vec)
but with float
parameters.public final void translate(float x, float y)
translate(Vec)
but with float
parameters.public void translate(Vec t)
t
, locally defined with respect to the
referenceFrame()
.
If there's a constraint()
it is satisfied. Hence the translation actually
applied to the Frame may differ from t
(since it can be filtered by the
constraint()
). Use setTranslation(Vec)
to directly translate the
Frame without taking the constraint()
into account.
rotate(Rotation)
,
scale(float)
public final Vec position()
orientation()
,
magnitude()
,
setPosition(Vec)
,
translation()
public final void setPosition(Vec p)
position()
of the Frame, defined in the world coordinate system.
Use setTranslation(Vec)
to define the local Frame translation (with respect
to the referenceFrame()
). The potential constraint()
of the Frame
is not taken into account, use setPositionWithConstraint(Vec)
instead.
public final void setPosition(float x, float y)
setPosition(Vec)
, but with float
parameters.public final void setPosition(float x, float y, float z)
setPosition(Vec)
, but with float
parameters.public final void setPositionWithConstraint(Vec position)
setPosition(Vec)
, but if there's a constraint()
it is
satisfied (without modifying position
).public final Rotation rotation()
referenceFrame()
(i.e, the current Rotation orientation).
Use orientation()
to get the result in world coordinates. These two values
are identical when the referenceFrame()
is null
(default).
public final void setRotation(Rotation r)
Rotation
constructors.
Sets the rotation()
of the Frame, locally defined with respect to the
referenceFrame()
.
Use setOrientation(Rotation)
to define the world coordinates
orientation()
. The potential constraint()
of the Frame is not taken
into account, use setRotationWithConstraint(Rotation)
instead.
public final void setRotation(float x, float y, float z, float w)
setRotation(Rotation)
but with float
Rotation parameters.public final void setRotation(float a)
Rotation
.a
- anglepublic final void setRotationWithConstraint(Rotation rotation)
setRotation(Rotation)
, but if there's a constraint()
it's
satisfied.public final void rotate(Rotation r)
r
(defined in the Frame coordinate system):
rotation().compose(r)
.
If there's a constraint()
it is satisfied. Hence the rotation actually
applied to the Frame may differ from q
(since it can be filtered by the
constraint()
). Use setRotation(Rotation)
to directly rotate the
Frame without taking the constraint()
into account.
translate(Vec)
public final void rotate(float x, float y, float z, float w)
rotate(Rotation)
but with float
rotation parameters.public void rotateAroundPoint(Rotation rotation, Vec point)
rotate(Rotation)
by rotation
around point
.
point
is defined in the world coordinate system, while the rotation
axis is defined in the Frame coordinate system.
If the Frame has a constraint()
, rotation
is first constrained using
Constraint.constrainRotation(Rotation, Frame)
.
Hence the rotation actually applied to the Frame may differ from rotation
(since it can be filtered by the constraint()
).
The translation which results from the filtered rotation around point
is then
computed and filtered using
Constraint.constrainTranslation(Vec, Frame)
.
public void rotateAroundFrame(float roll, float pitch, float yaw, Frame frame)
public final Rotation orientation()
position()
,
magnitude()
,
setOrientation(Rotation)
,
rotation()
public final void setOrientation(Rotation q)
orientation()
of the Frame, defined in the world coordinate system.
Use setRotation(Rotation)
to define the local frame rotation (with respect
to the referenceFrame()
). The potential constraint()
of the Frame
is not taken into account, use setOrientationWithConstraint(Rotation)
instead.
public final void setOrientation(float x, float y, float z, float w)
setOrientation(Rotation)
, but with float
parameters.public final void setOrientationWithConstraint(Rotation orientation)
setOrientation(Rotation)
, but if there's a constraint()
it
is satisfied (without modifying orientation
).public final float scaling()
referenceFrame()
.
Use magnitude()
to get the result in world coordinates. These two values are
identical when the referenceFrame()
is null
(default).
setScaling(float)
public final void setScaling(float s)
scaling()
of the frame, locally defined with respect to the
referenceFrame()
.
Use setMagnitude(float)
to define the world coordinates magnitude()
.
public void scale(float s)
s
, locally defined with respect to the
referenceFrame()
.rotate(Rotation)
,
translate(Vec)
public float magnitude()
orientation()
,
position()
,
setPosition(Vec)
,
translation()
public final void setMagnitude(float m)
magnitude()
of the Frame, defined in the world coordinate system.
Use setScaling(float)
to define the local Frame scaling (with respect to the
referenceFrame()
).
public final void alignWithFrame(Frame frame)
alignWithFrame(frame, false, 0.85f)
public final void alignWithFrame(Frame frame, boolean move)
alignWithFrame(frame, move, 0.85f)
public final void alignWithFrame(Frame frame, float threshold)
alignWithFrame(frame, false, threshold)
public final void alignWithFrame(Frame frame, boolean move, float threshold)
frame
, so that two of their axis are parallel.
If one of the X, Y and Z axis of the Frame is almost parallel to any of the X, Y, or
Z axis of frame
, the Frame is rotated so that these two axis actually become
parallel.
If, after this first rotation, two other axis are also almost parallel, a second alignment is performed. The two frames then have identical orientations, up to 90 degrees rotations.
threshold
measures how close two axis must be to be considered parallel. It
is compared with the absolute values of the dot product of the normalized axis.
When move
is set to true
, the Frame position()
is also
affected by the alignment. The new Frame position()
is such that the
frame
frame position (computed with coordinatesOf(Vec)
, in the Frame
coordinates system) does not change.
frame
may be null
and then represents the world coordinate system
(same convention than for the referenceFrame()
).
public final void projectOnLine(Vec origin, Vec direction)
position()
lies on the line defined by
origin
and direction
(defined in the world coordinate system).
Simply uses an orthogonal projection. direction
does not need to be
normalized.
public void setXAxis(Vec axis)
xAxis()
becomes axis
defined in the
world coordinate system.
Attention: this rotation is not uniquely defined. See
Quat.fromTo(Vec, Vec)
.
xAxis()
,
setYAxis(Vec)
,
setZAxis(Vec)
public void setYAxis(Vec axis)
yAxis()
becomes axis
defined in the
world coordinate system.
Attention: this rotation is not uniquely defined. See
Quat.fromTo(Vec, Vec)
.
yAxis()
,
setYAxis(Vec)
,
setZAxis(Vec)
public void setZAxis(Vec axis)
zAxis()
becomes axis
defined in the
world coordinate system.
Attention: this rotation is not uniquely defined. See
Quat.fromTo(Vec, Vec)
.
zAxis()
,
setYAxis(Vec)
,
setZAxis(Vec)
public Vec xAxis()
return xAxis(true)
xAxis(boolean)
public Vec xAxis(boolean positive)
setXAxis(Vec)
,
yAxis()
,
zAxis()
public Vec yAxis()
return yAxis(true)
yAxis(boolean)
public Vec yAxis(boolean positive)
setYAxis(Vec)
,
xAxis()
,
zAxis()
public Vec zAxis()
return zAxis(true)
zAxis(boolean)
public Vec zAxis(boolean positive)
setZAxis(Vec)
,
xAxis()
,
yAxis()
public final Mat matrix()
This method could be used in conjunction with applyMatrix()
to modify the
AbstractScene.modelView()
matrix from a Frame
hierarchy. For example, with this Frame hierarchy:
Frame body = new Frame();
Frame leftArm = new Frame();
Frame rightArm = new Frame();
leftArm.setReferenceFrame(body);
rightArm.setReferenceFrame(body);
The associated drawing code should look like:
scene.pushModelView();
scene.applyMatrix(body.matrix());
drawBody();
scene.pushModelView();
scene.applyMatrix(leftArm.matrix());
drawArm();
scene.popModelView();
scene.pushModelView();
scene.applyMatrix(rightArm.matrix());
drawArm();
scene.popModelView();
scene.popModelView();
Note the use of nested pushModelView()
and popModelView()
blocks to
represent the frame hierarchy: leftArm
and rightArm
are both
correctly drawn with respect to the body
coordinate system.
Attention: In Processing this technique is inefficient because
papplet.applyMatrix
will try to calculate the inverse of the transform.
This matrix only represents the local Frame transformation (i.e., with respect to the
referenceFrame()
). Use worldMatrix()
to get the full Frame
transformation matrix (i.e., from the world to the Frame coordinate system). These
two match when the referenceFrame()
is null
.
The result is only valid until the next call to matrix()
or
worldMatrix()
. Use it immediately (as above).
public final Mat worldMatrix()
This method should be used in conjunction with applyMatrix()
to modify the
AbstractScene.modelView()
matrix from a Frame:
// Here the modelview matrix corresponds to the world coordinate system.
Frame fr = new Frame(pos, Rotation(from, to));
scene.pushModelView();
scene.applyMatrix(worldMatrix());
// draw object in the fr coordinate system.
scene.popModelView();
This matrix represents the global Frame transformation: the entire
referenceFrame()
hierarchy is taken into account to define the Frame
transformation from the world coordinate system. Use matrix()
to get the
local Frame transformation matrix (i.e. defined with respect to the
referenceFrame()
). These two match when the referenceFrame()
is
null
.
Attention: The result is only valid until the next call to matrix()
or worldMatrix()
. Use it immediately (as above).
public final void fromMatrix(Mat pM)
fromMatrix(pM, 1))
.fromMatrix(Mat, float)
public final void fromMatrix(Mat pM, float scl)
scl
.
Hence, if a code fragment looks like:
float [] m = new float [16]; m[0]=...;
gl.glMultMatrixf(m);
It is equivalent to write:
Frame fr = new Frame();
fr.fromMatrix(m);
applyMatrix(fr.matrix());
Using this conversion, you can benefit from the powerful Frame transformation methods
to translate points and vectors to and from the Frame coordinate system to any other
Frame coordinate system (including the world coordinate system). See
coordinatesOf(Vec)
and transformOf(Vec)
.
public void set(Frame otherFrame)
#setWorldMatrix(Frame)
.setWorldMatrix(Frame)
public void setWorldMatrix(Frame otherFrame)
position()
, orientation()
and magnitude()
values from
those of otherFrame
.
After calling set
a call to this.equals(otherFrame)
should return
true
.
setMatrix(Frame)
public void setMatrix(Frame otherFrame)
setWorldMatrix(Frame)
public final Frame inverse()
The the new Frame rotation()
is the
Rotation.inverse()
of the original rotation. Its
translation()
is the negated inverse rotated image of the original
translation. Its scaling()
is 1 / original scaling.
If a Frame is considered as a space rigid transformation, i.e., translation and rotation, but no scaling (scaling=1), the inverse() Frame performs the inverse transformation.
Only the local Frame transformation (i.e., defined with respect to the
referenceFrame()
) is inverted. Use worldInverse()
for a global
inverse.
The resulting Frame has the same referenceFrame()
as the Frame and a
null
constraint()
.
public final Frame worldInverse()
inverse()
of the Frame world transformation.
The orientation()
of the new Frame is the
Quat.inverse()
of the original orientation. Its
position()
is the negated and inverse rotated image of the original
position. The magnitude()
is the the original magnitude multiplicative
inverse.
The result Frame has a null
referenceFrame()
and a null
constraint()
.
Use inverse()
for a local (i.e., with respect to referenceFrame()
)
transformation inverse.
public final Vec coordinatesOfFrom(Vec src, Frame from)
from
coordinate system is src
(converts from from
to Frame).
coordinatesOfIn(Vec, Frame)
performs the inverse transformation.
public final Vec coordinatesOfIn(Vec src, Frame in)
in
coordinates of the point whose position in the Frame
coordinate system is src
(converts from Frame to in
).
coordinatesOfFrom(Vec, Frame)
performs the inverse transformation.
public final Vec localCoordinatesOf(Vec src)
src
defined in the
referenceFrame()
coordinate system (converts from referenceFrame()
to Frame).
localInverseCoordinatesOf(Vec)
performs the inverse conversion.
localTransformOf(Vec)
public final Vec coordinatesOf(Vec src)
src
defined in the world coordinate
system (converts from world to Frame).
inverseCoordinatesOf(Vec)
performs the inverse conversion.
transformOf(Vec)
converts vectors instead of coordinates.
public final Vec transformOfFrom(Vec src, Frame from)
from
coordinate system is src
(converts vectors from from
to Frame).
transformOfIn(Vec, Frame)
performs the inverse transformation.
public final Vec transformOfIn(Vec src, Frame in)
in
transform of the vector whose coordinates in the Frame
coordinate system is src
(converts vectors from Frame to in
).
transformOfFrom(Vec, Frame)
performs the inverse transformation.
public final Vec localInverseCoordinatesOf(Vec src)
referenceFrame()
coordinates of a point src
defined in
the Frame coordinate system (converts from Frame to referenceFrame()
).
localCoordinatesOf(Vec)
performs the inverse conversion.
localInverseTransformOf(Vec)
public final Vec inverseCoordinatesOf(Vec src)
src
(converts from Frame to world).
coordinatesOf(Vec)
performs the inverse conversion. Use
inverseTransformOf(Vec)
to transform vectors instead of coordinates.
public final Vec transformOf(Vec src)
src
defined in the world coordinate
system (converts vectors from world to Frame).
inverseTransformOf(Vec)
performs the inverse transformation.
coordinatesOf(Vec)
converts coordinates instead of vectors (here only the
rotational part of the transformation is taken into account).
public final Vec inverseTransformOf(Vec src)
src
(converts vectors from Frame to world).
transformOf(Vec)
performs the inverse transformation. Use
inverseCoordinatesOf(Vec)
to transform coordinates instead of vectors.
public final Vec localTransformOf(Vec src)
src
defined in the
referenceFrame()
coordinate system (converts vectors from
referenceFrame()
to Frame).
localInverseTransformOf(Vec)
performs the inverse transformation.
localCoordinatesOf(Vec)
public final Vec localInverseTransformOf(Vec src)
referenceFrame()
transform of a vector src
defined in
the Frame coordinate system (converts vectors from Frame to referenceFrame()
).
localTransformOf(Vec)
performs the inverse transformation.
localInverseCoordinatesOf(Vec)
Processing Library proscene by Jean Pierre Charalambos. (c) 2014-2017 National University of Colombia