ai_matrix.h
Go to the documentation of this file.
1// Copyright 2021 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_vector.h"
14#include "ai_api.h"
15#include "ai_matrix_private.h"
16
17#include <cstring>
18#include <stdint.h>
19
27#ifndef _ARNOLDDLL
28// Visual Studio will report a compile error if AtMatrix is templated, so we use this
29// one instead of the version in ai_matrix_private.h
30struct AtMatrix {
31 bool operator==(const AtMatrix& m) const
32 {
33 // watch out, this will return false for +0.0 == -0.0 and true for matching NaNs
34 return !memcmp(data, m.data, sizeof(AtMatrix));
35 }
36
37 constexpr const float* operator[](int t) const
38 {
39 return (const float*) &(data[t][0]);
40 }
41
42 float* operator[](int t)
43 {
44 return &(data[t][0]);
45 }
46
47 float data[4][4];
48};
49#endif
50
51AI_API AI_DEVICE AtMatrix AiM4Identity();
52AI_API AtMatrix AiM4Translation(const AtVector& t);
53AI_API AI_DEVICE AtMatrix AiM4RotationX(float x);
54AI_API AI_DEVICE AtMatrix AiM4RotationY(float y);
55AI_API AI_DEVICE AtMatrix AiM4RotationZ(float z);
56AI_API AtMatrix AiM4Scaling(const AtVector& s);
57AI_API AI_DEVICE AtMatrix AiM4Frame(const AtVector& o, const AtVector& u, const AtVector& v, const AtVector& w);
58AI_API AI_DEVICE AtVector AiM4PointByMatrixMult(const AtMatrix& m, const AtVector& pin);
59AI_API AI_DEVICE AtHPoint AiM4HPointByMatrixMult(const AtMatrix& m, const AtHPoint& pin);
60AI_API AI_DEVICE AtVector AiM4VectorByMatrixMult(const AtMatrix& m, const AtVector& vin);
61AI_API AI_DEVICE AtVector AiM4VectorByMatrixTMult(const AtMatrix& m, const AtVector& vin);
62AI_API AI_DEVICE AtMatrix AiM4Mult(const AtMatrix& ma, const AtMatrix& mb);
63AI_API AI_DEVICE AtMatrix AiM4Transpose(const AtMatrix& min);
64AI_API AI_DEVICE AtMatrix AiM4Invert(const AtMatrix& min);
65AI_API AI_PURE float AiM4Determinant(const AtMatrix& m);
66AI_API AI_DEVICE AtMatrix AiM4Lerp(float t, const AtMatrix& ma, const AtMatrix& mb);
67AI_API AI_PURE bool AiM4IsIdentity(const AtMatrix& m);
68AI_API AI_PURE bool AiM4IsSingular(const AtMatrix& m);
69
70static constexpr const AtMatrix AI_M4_IDENTITY = {{ {1, 0, 0, 0},
71 {0, 1, 0, 0},
72 {0, 0, 1, 0},
73 {0, 0, 0, 1} }};
74static constexpr const AtMatrix AI_M4_ZERO = {{ {0, 0, 0, 0},
75 {0, 0, 0, 0},
76 {0, 0, 0, 0},
77 {0, 0, 0, 0} }};
78
79/*\}*/
DLL export prefix for API functions (necessary for multi-platform development)
This is enabled only inside of arnold and is disabled for client code.
Vector math types, operators and utilities.
AI_API AI_PURE bool AiM4IsSingular(const AtMatrix &m)
Is this a singular matrix?
Definition: ai_matrix.cpp:195
AI_API AI_DEVICE AtMatrix AiM4Identity()
Create an identity matrix.
Definition: ai_matrix.cpp:22
AI_API AI_DEVICE AtVector AiM4VectorByMatrixTMult(const AtMatrix &m, const AtVector &vin)
Right-multiply a vector by a matrix.
Definition: ai_matrix.cpp:150
AI_API AI_DEVICE AtMatrix AiM4RotationX(float x)
Create a X-axis rotation matrix.
Definition: ai_matrix.cpp:44
AI_API AI_DEVICE AtMatrix AiM4Lerp(float t, const AtMatrix &ma, const AtMatrix &mb)
Linear interpolation of two matrices.
Definition: ai_matrix.cpp:208
AI_API AI_DEVICE AtVector AiM4VectorByMatrixMult(const AtMatrix &m, const AtVector &vin)
Left-multiply a vector by a matrix.
Definition: ai_matrix.cpp:135
AI_API AI_DEVICE AtMatrix AiM4Frame(const AtVector &o, const AtVector &u, const AtVector &v, const AtVector &w)
Create a matrix that transforms into a new coordinate frame.
Definition: ai_matrix.cpp:94
AI_API AtMatrix AiM4Scaling(const AtVector &s)
Create a scaling matrix from a scaling vector.
Definition: ai_matrix.cpp:77
AI_API AI_DEVICE AtMatrix AiM4RotationY(float y)
Create a Y-axis rotation matrix.
Definition: ai_matrix.cpp:55
AI_API AI_DEVICE AtVector AiM4PointByMatrixMult(const AtMatrix &m, const AtVector &pin)
Left-multiply a point by a matrix.
Definition: ai_matrix.cpp:108
AI_API AI_DEVICE AtMatrix AiM4RotationZ(float z)
Create a Z-axis rotation matrix.
Definition: ai_matrix.cpp:66
AI_API AI_DEVICE AtMatrix AiM4Invert(const AtMatrix &min)
Calculate the inverse of a matrix.
Definition: ai_matrix.cpp:219
AI_API AtMatrix AiM4Translation(const AtVector &t)
Create a translation matrix from a translation vector.
Definition: ai_matrix.cpp:33
AI_API AI_DEVICE AtMatrix AiM4Transpose(const AtMatrix &min)
Calculate the transpose of a matrix.
Definition: ai_matrix.cpp:173
AI_API AI_PURE bool AiM4IsIdentity(const AtMatrix &m)
Is this an identity matrix?
Definition: ai_matrix.cpp:184
AI_API AI_DEVICE AtHPoint AiM4HPointByMatrixMult(const AtMatrix &m, const AtHPoint &pin)
Left-multiply a 4D point by a matrix.
Definition: ai_matrix.cpp:120
AI_API AI_PURE float AiM4Determinant(const AtMatrix &m)
Determinant of a matrix.
Definition: ai_matrix.cpp:232
AI_API AI_DEVICE AtMatrix AiM4Mult(const AtMatrix &ma, const AtMatrix &mb)
Multiply two matrices.
Definition: ai_matrix.cpp:162
Homogeneous point.
Definition: ai_vector.h:465
Definition: ai_matrix.h:30
3D point (single precision)
Definition: ai_vector.h:30

© 2022 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com