LeapMatrix Class Reference
Inherits from | NSObject |
Declared in | LeapObjectiveC.h |
Overview
The LeapMatrix class represents a transformation matrix.
To use this class to transform a LeapVector, construct a matrix containing the
desired transformation and then use the [LeapMatrix transformPoint:] or
[LeapMatrix transformDirection:] functions to apply the transform.
Transforms can be combined by multiplying two or more transform matrices using
the [LeapMatrix times:] function.
Tasks
-
– initWithXBasis:yBasis:zBasis:origin:
Constructs a transformation matrix from the specified basis and translation vectors.
-
– initWithMatrix:
Constructs a copy of the specified Matrix object.
-
– initWithAxis:angleRadians:
Constructs a transformation matrix specifying a rotation around the specified vector.
-
– initWithAxis:angleRadians:translation:
Constructs a transformation matrix specifying a rotation around the specified vector
and a translation by the specified vector. -
– transformPoint:
Transforms a vector with this matrix by transforming its rotation,
scale, and translation. -
– transformDirection:
Transforms a vector with this matrix by transforming its rotation and
scale only. -
– times:
Multiply transform matrices.
-
– equals:
Compare LeapMatrix equality component-wise.
-
– toNSArray3x3
Converts a LeapMatrix object to a 9-element NSArray object.
-
– toNSArray4x4
Converts a LeapMatrix object to a 16-element NSArray object.
-
+ identity
Returns the identity matrix specifying no translation, rotation, and scale.
-
xBasis
The rotation and scale factors for the x-axis.
property -
yBasis
The rotation and scale factors for the y-axis.
property -
zBasis
The rotation and scale factors for the z-axis.
property -
origin
The translation factors for all three axes.
property
Properties
origin
The translation factors for all three axes.
@property (nonatomic, strong, readonly) LeapVector *origin
Discussion
The translation factors for all three axes.
Declared In
LeapObjectiveC.h
xBasis
The rotation and scale factors for the x-axis.
@property (nonatomic, strong, readonly) LeapVector *xBasis
Discussion
The rotation and scale factors for the x-axis.
Declared In
LeapObjectiveC.h
Class Methods
identity
Returns the identity matrix specifying no translation, rotation, and scale.
+ (LeapMatrix *)identity
Return Value
The identity matrix.
Discussion
Returns the identity matrix specifying no translation, rotation, and scale.
LeapMatrix *identity = [LeapMatrix identity];
Declared In
LeapObjectiveC.h
Instance Methods
equals:
Compare LeapMatrix equality component-wise.
- (BOOL)equals:(const LeapMatrix *)other
Parameters
- other
The LeapMatrix object to compare.
Return Value
YES, if the corresponding elements in the two matrices are equal.
Discussion
Compare LeapMatrix equality component-wise.
bool matricesAreEqual = [thisMatrix equals:thatMatrix];
Declared In
LeapObjectiveC.h
initWithAxis:angleRadians:
Constructs a transformation matrix specifying a rotation around the specified vector.
- (id)initWithAxis:(const LeapVector *)axis angleRadians:(float)angleRadians
Parameters
- axis
A LeapVector specifying the axis of rotation.
- angleRadians
The amount of rotation in radians.
Discussion
Constructs a transformation matrix specifying a rotation around the specified vector.
LeapMatrix *rotation = [[LeapMatrix alloc] initWithAxis:[LeapVector up]
angleRadians:LEAP_PI/3];
Declared In
LeapObjectiveC.h
initWithAxis:angleRadians:translation:
Constructs a transformation matrix specifying a rotation around the specified vector
and a translation by the specified vector.
- (id)initWithAxis:(const LeapVector *)axis angleRadians:(float)angleRadians translation:(const LeapVector *)translation
Parameters
- axis
A LeapVector specifying the axis of rotation.
- angleRadians
The angle of rotation in radians.
- translation
A LeapVector representing the translation part of the transform.
Discussion
Constructs a transformation matrix specifying a rotation around the specified vector
and a translation by the specified vector.
LeapMatrix *transform = [[LeapMatrix alloc] initWithAxis:[LeapVector zAxis]
angleRadians:LEAP_PI
translation:[[LeapVector alloc]
initWithX:5
y:3
z:1]];
Declared In
LeapObjectiveC.h
initWithMatrix:
Constructs a copy of the specified Matrix object.
- (id)initWithMatrix:(LeapMatrix *)matrix
Parameters
- matrix
the LeapMatrix to copy.
Discussion
Constructs a copy of the specified Matrix object.
LeapMatrix *copyMatrix = [[LeapMatrix alloc] initWithMatrix:otherMatrix];
Declared In
LeapObjectiveC.h
initWithXBasis:yBasis:zBasis:origin:
Constructs a transformation matrix from the specified basis and translation vectors.
- (id)initWithXBasis:(const LeapVector *)xBasis yBasis:(const LeapVector *)yBasis zBasis:(const LeapVector *)zBasis origin:(const LeapVector *)origin
Parameters
- xBasis
A LeapVector specifying rotation and scale factors for the x-axis.
- yBasis
A LeapVector specifying rotation and scale factors for the y-axis.
- zBasis
A LeapVector specifying rotation and scale factors for the z-axis.
- origin
A LeapVector specifying translation factors on all three axes.
Discussion
Constructs a transformation matrix from the specified basis and translation vectors.
LeapMatrix *newMatrix = [[LeapMatrix alloc] initWithXBasis:[LeapVector xAxis]
yBasis:[LeapVector yAxis]
zBasis:[LeapVector zAxis]
origin:[LeapVector zero]];
Declared In
LeapObjectiveC.h
times:
Multiply transform matrices.
- (LeapMatrix *)times:(const LeapMatrix *)other
Parameters
- other
A LeapMatrix to multiply on the right hand side.
Return Value
A new LeapMatrix representing the transformation equivalent to
applying the other transformation followed by this transformation.
Discussion
Multiply transform matrices.
LeapMatrix *product = [thisMatrix times:thatMatrix];
Combines two transformations into a single equivalent transformation.
Declared In
LeapObjectiveC.h
toNSArray3x3
Converts a LeapMatrix object to a 9-element NSArray object.
- (NSMutableArray *)toNSArray3x3
Discussion
Converts a LeapMatrix object to a 9-element NSArray object.
The elements of the matrix are inserted into the array in row-major order.
NSArray *matrix3x3Array = thisMatrix.toNSArray3x3;
float R2C1 = [[matrix3x3Array objectAtIndex:4] floatValue];
Translation factors are discarded.
Declared In
LeapObjectiveC.h
toNSArray4x4
Converts a LeapMatrix object to a 16-element NSArray object.
- (NSMutableArray *)toNSArray4x4
Discussion
Converts a LeapMatrix object to a 16-element NSArray object.
The elements of the matrix are inserted into the array in row-major order.
NSArray *matrix4x4Array = thisMatrix.toNSArray4x4;
float R4C3 = [[matrix4x4Array objectAtIndex:15] floatValue];
}
@end
Declared In
LeapObjectiveC.h
transformDirection:
Transforms a vector with this matrix by transforming its rotation and
scale only.
- (LeapVector *)transformDirection:(const LeapVector *)direction
Parameters
- direction
The LeapVector to transform.
Return Value
A new LeapVector representing the transformed original.
Discussion
Transforms a vector with this matrix by transforming its rotation and
scale only.
Declared In
LeapObjectiveC.h
transformPoint:
Transforms a vector with this matrix by transforming its rotation,
scale, and translation.
- (LeapVector *)transformPoint:(const LeapVector *)point
Parameters
- point
A LeapVector representing the 3D position to transform.
Return Value
A new LeapVector representing the transformed original.
Discussion
Transforms a vector with this matrix by transforming its rotation,
scale, and translation.
Translation is applied after rotation and scale.
LeapVector *point = [[LeapVector alloc] initWithX:10 y:100 z:-30];
LeapVector *transformedPoint = [thisMatrix transformPoint:point];
Declared In
LeapObjectiveC.h