About
In 3D graphics a matrix is used to represent the transformation from one coordinate system to another. The typical use case is the transformation matrix that defines the position, rotation and scale of an object in 3D space.
The classic matrix classes available:
- Matrix32: A matrix composed of
Vector32
elements.
- Matrix64: A matrix composed of
Vector64
elements.
- Matrix: Defined as
Matrix64
.
See also Vector Manual (Classic).
- Warning
- A description of MAXON API matrix classes can be found here: Matrices.
Access
To retrieve and modify Matrix objects stored in a BaseObject respectively use:
- BaseObject::GetMg(): Returns the world (global) matrix representing the object's position, scale and rotation.
- BaseObject::SetMg(): Sets the world (global) matrix representing the object's position, scale and rotation.
For more object related matrices see BaseObject.
To retrieve and modify Matrix objects stored in a BaseContainer respectively use:
See also BaseContainer Manual.
To retrieve and modify Matrix objects stored in a GeData object (GeData type is DA_MATRIX) respectively use:
See also GeData Manual.
{
if (cube != nullptr)
{
doc->InsertObject(cube,
nullptr,
nullptr);
}
}
Definition: c4d_baseobject.h:248
void SetMg(const Matrix &m)
Definition: c4d_baseobject.h:516
static BaseObject * Alloc(Int32 type)
Definition: lib_description.h:355
Definition: c4d_gedata.h:83
const Matrix & GetMatrix() const
Definition: c4d_gedata.h:492
@ DTYPE_MATRIX
Matrix
Definition: lib_description.h:71
@ DTYPE_SUBCONTAINER
Sub-container.
Definition: lib_description.h:58
#define Ocube
Cube.
Definition: ge_prepass.h:1119
#define ID_USERDATA
User data ID.
Definition: lib_description.h:25
#define ConstDescID(...)
Definition: lib_description.h:594
const char * doc
Definition: pyerrors.h:226
Represents a level within a DescID.
Definition: lib_description.h:298
Components
A matrix is composed of four vector components:
- Matrix::off: The translation vector.
- Matrix::sqmat::v1: The X-axis coordinate in a left-handed coordinate system of a transformed X-axis aligned unit-vector.
- Matrix::sqmat::v2: The Y-axis coordinate in a left-handed coordinate system of a transformed Y-axis aligned unit-vector.
- Matrix::sqmat::v3: The Z-axis coordinate in a left-handed coordinate system of a transformed Z-axis aligned unit-vector.
const Matrix mg =
object->GetMg();
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
V off
The translation vector.
Definition: matrix.h:263
Functionality
Apply Transformation
A matrix is typically used to transform a given vector.
- Matrix::operator*() const: Transforms the given vector.
const Vector*
const points = pointObject->GetPointR();
const Int32 pointCount = pointObject->GetPointCount();
const Matrix mg = pointObject->GetMg();
{
if (points)
{
const Vector worldSpacePosition = mg * point;
if (sphere != nullptr)
{
doc->InsertObject(sphere,
nullptr,
nullptr);
}
}
}
Py_ssize_t i
Definition: abstract.h:645
maxon::Int32 Int32
Definition: ge_sys_math.h:56
#define Osphere
Sphere.
Definition: ge_prepass.h:1120
Edit Matrix
Basic operations to edit a matrix are done using operators or special functions:
const Matrix mgA = objectA->GetMg();
const Vector worldSpacePos = objectB->GetMg().off;
const Vector localSpacePos = inverse * worldSpacePos;
ApplicationOutput(
"Position @ in the local space of @"_s, localSpacePos, objectAName);
Definition: string.h:1237
Compare
Two matrices can be compared using the usual operators:
- Note
- For save comparison of floating point values see Compare.
Disc I/O
Matrix objects can be stored in a BaseFile or a HyperFile using:
if (bf == nullptr)
{
bf->WriteMatrix64(matrix);
bf->Close();
}
PyCompilerFlags const char * filename
Definition: ast.h:15
Definition: ge_autoptr.h:37
@ ANY
Show an error dialog for any error.
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
if (bf == nullptr)
{
bf->ReadMatrix64(&matrix);
@ READ
Open the file for reading.
if (hf == nullptr)
{
hf->WriteMatrix(matrix);
hf->Close();
}
if (hf == nullptr)
{
hf->ReadMatrix(&matrix);
See also BaseFile Manual on Matrix and HyperFile Manual on Matrix.
Utility Functions
Several utility functions can be used to easily create matrices:
Matrices also represent rotations. Several functions can be used to change and obtain the rotation stored in a matrix:
- Note
- Rotations are represented by vectors, see also Vector Manual (Classic).
Matrix utility:
- RebuildMatrix(): Recalculates a matrix making it orthogonal if one or more of its vectors is collapsed
const Vector vec { 100, 100, 100 };
object->SetMg(mg);
@ DEFAULT
Default order (HPB).
Further Reading