-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCalcMatrix.py
More file actions
49 lines (38 loc) · 1.02 KB
/
CalcMatrix.py
File metadata and controls
49 lines (38 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pxr import Gf
# Identity matrix.
m = Gf.Matrix4f()
print(m)
# Initialize with rotation and translate.
rotV = Gf.Rotation(Gf.Vec3d(1, 0, 0), 90.0)
transV = Gf.Vec3f(10, 5, 2.3)
m1 = Gf.Matrix4f(rotV, transV)
print(m1)
# Get data.
for i in range(4):
print(f"{m1[i,0]} , {m1[i,1]} , {m1[i,2]} , {m1[i,3]}")
# Set identity.
m1.SetIdentity()
print(m1)
# Matrix multiplication.
rot1 = Gf.Rotation(Gf.Vec3d(1, 0, 0), 90.0)
m2 = Gf.Matrix4f(rot1, Gf.Vec3f())
rot2 = Gf.Rotation(Gf.Vec3d(0, 1, 0), 30.0)
m3 = Gf.Matrix4f(rot2, Gf.Vec3f())
m4 = m2 * m3 # Gf.Matrix4f * Gf.Matrix4f
print(m4)
rot3 = rot1 * rot2 # Gf.Rotation * Gf.Rotation
print(Gf.Matrix4f(rot3, Gf.Vec3f()))
# Inverse matrix.
m4Inv = m4.GetInverse()
print(m4Inv)
# vector3 * matrix4.
rotV = Gf.Rotation(Gf.Vec3d(1, 0, 0), 90.0)
transV = Gf.Vec3f(10, 5, 2.3)
m5 = Gf.Matrix4f(rotV, transV)
v1 = Gf.Vec3f(1.2, 1.0, 2.5)
v2 = m5.Transform(v1)
print(f"{v2}")
# vector3 * matrix4 (Ignore position).
v1 = Gf.Vec3f(1.2, 1.0, 2.5)
v2 = m5.TransformDir(v1)
print(f"{v2}")