ai_matrix.h
Go to the documentation of this file.
1 // Copyright 2020 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
30 struct 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 
51 AI_API AI_DEVICE AtMatrix AiM4Identity();
52 AI_API AtMatrix AiM4Translation(const AtVector& t);
53 AI_API AI_DEVICE AtMatrix AiM4RotationX(float x);
54 AI_API AI_DEVICE AtMatrix AiM4RotationY(float y);
55 AI_API AI_DEVICE AtMatrix AiM4RotationZ(float z);
56 AI_API AtMatrix AiM4Scaling(const AtVector& s);
57 AI_API AI_DEVICE AtMatrix AiM4Frame(const AtVector& o, const AtVector& u, const AtVector& v, const AtVector& w);
58 AI_API AI_DEVICE AtVector AiM4PointByMatrixMult(const AtMatrix& m, const AtVector& pin);
59 AI_API AI_DEVICE AtHPoint AiM4HPointByMatrixMult(const AtMatrix& m, const AtHPoint& pin);
60 AI_API AI_DEVICE AtVector AiM4VectorByMatrixMult(const AtMatrix& m, const AtVector& vin);
61 AI_API AI_DEVICE AtVector AiM4VectorByMatrixTMult(const AtMatrix& m, const AtVector& vin);
62 AI_API AI_DEVICE AtMatrix AiM4Mult(const AtMatrix& ma, const AtMatrix& mb);
63 AI_API AI_DEVICE AtMatrix AiM4Transpose(const AtMatrix& min);
64 AI_API AI_DEVICE AtMatrix AiM4Invert(const AtMatrix& min);
65 AI_API AI_PURE float AiM4Determinant(const AtMatrix& m);
66 AI_API AI_DEVICE AtMatrix AiM4Lerp(float t, const AtMatrix& ma, const AtMatrix& mb);
67 AI_API AI_PURE bool AiM4IsIdentity(const AtMatrix& m);
68 AI_API AI_PURE bool AiM4IsSingular(const AtMatrix& m);
69 
70 static 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} }};
74 static 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 /*\}*/
AI_API AtMatrix AiM4Translation(const AtVector &t)
Create a translation matrix from a translation vector.
Definition: ai_matrix.cpp:33
AI_API AI_PURE bool AiM4IsSingular(const AtMatrix &m)
Is this a singular matrix?
Definition: ai_matrix.cpp:195
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 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 AiM4Mult(const AtMatrix &ma, const AtMatrix &mb)
Multiply two matrices.
Definition: ai_matrix.cpp:162
Vector math types, operators and utilities.
This is enabled only inside of arnold and is disabled for client code.
3D point (single precision)
Definition: ai_vector.h:29
AI_API AI_DEVICE AtMatrix AiM4RotationY(float y)
Create a Y-axis rotation matrix.
Definition: ai_matrix.cpp:55
Definition: ai_matrix.h:30
DLL export prefix for API functions (necessary for multi-platform development)
AI_API AI_DEVICE AtMatrix AiM4Identity()
Create an identity matrix.
Definition: ai_matrix.cpp:22
Homogeneous point.
Definition: ai_vector.h:464
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_PURE float AiM4Determinant(const AtMatrix &m)
Determinant of a matrix.
Definition: ai_matrix.cpp:232
AI_API AI_DEVICE AtMatrix AiM4RotationX(float x)
Create a X-axis rotation matrix.
Definition: ai_matrix.cpp:44
AI_API AtMatrix AiM4Scaling(const AtVector &s)
Create a scaling matrix from a scaling vector.
Definition: ai_matrix.cpp:77
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 AtVector AiM4VectorByMatrixMult(const AtMatrix &m, const AtVector &vin)
Left-multiply a vector by a matrix.
Definition: ai_matrix.cpp:135
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_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 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

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