SpiderPig Posted April 30, 2024 Posted April 30, 2024 I'm not positive I'm using it right... but no matter what I do the matrix's rotation (r) is always zero. Where as (i) is correct - Vec3(0,90,90); MakeDir() returns nothing, I checked. auto m = Mat4(); m.MakeDir(Vec3(0,0,1), 1); up_pivot->AlignToVector(Vec3(0,0,1), 1); auto i = up_pivot->GetRotation(); auto r = m.GetRotation(); Quote
Josh Posted April 30, 2024 Posted April 30, 2024 Strange...you would expect a lot of problems if these functions were off... Mat4 m; m.MakeDir(Vec3(0, 0, 1), 1); Print("Mat4"); Print(WString(m[0])); Print(WString(m[1])); Print(WString(m[2])); Print(WString(m[3])); Print("Quat"); auto q = m.GetQuaternion(); Print(WString(q)); Print("Euler"); auto r = q.Euler(); Print(WString(r)); Quote Let's build cool stuff and have fun.
Josh Posted April 30, 2024 Posted April 30, 2024 Oh, I think I know why. It's pointing straight down, so you activated Gimbal lock. Quote Let's build cool stuff and have fun.
Solution Josh Posted April 30, 2024 Solution Posted April 30, 2024 Use mat.GetQuaternion() to get the exact rotation. 1 Quote Let's build cool stuff and have fun.
SpiderPig Posted April 30, 2024 Author Posted April 30, 2024 Thankyou. But should this code give two different results? auto m = Mat4(); m.MakeDir(Vec3(0.0f, 0.0f, 1.0f), 1); Print("Mat4"); Print(WString(m[0])); Print(WString(m[1])); Print(WString(m[2])); Print(WString(m[3])); Print("Quat"); auto q = m.GetQuaternion(); Print(WString(q)); Print("Euler"); auto r = q.Euler(); Print(WString(r)); Print(""); Print("--------------------------------------------------------------"); Print(""); auto up_pivot = CreatePivot(nullptr); up_pivot->AlignToVector(Vec3(0.0f, 0.0f, 1.0f), 1); m = up_pivot->GetMatrix(); Print("Mat4"); Print(WString(m[0])); Print(WString(m[1])); Print(WString(m[2])); Print(WString(m[3])); Print("Quat"); q = m.GetQuaternion(); Print(WString(q)); Print("Euler"); r = q.Euler(); Print(WString(r)); Console Output. Mat4 1, -0, -0, 0 0, 0, 1, 0 0, 1, 0, 0 0, 0, 0, 1 Quat -0, -0, 0, 0.707107 Euler 0, -0, -0 -------------------------------------------------------------- Mat4 0, 1, -0, 0 0, 0, 1, 0 1, -0, -0, 0 0, 0, 0, 1 Quat -0.5, -0.5, -0.5, 0.5 Euler -0, 90, 90 Quote
Josh Posted April 30, 2024 Posted April 30, 2024 It may. Aligning an object to a vector is an ambiguous operation. Quote Let's build cool stuff and have fun.
Josh Posted April 30, 2024 Posted April 30, 2024 The entity method takes roll into account, and tries to make the best decision. The Mat4 method is simpler. 1 Quote Let's build cool stuff and have fun.
SpiderPig Posted April 30, 2024 Author Posted April 30, 2024 Oh okay, I thought maybe both did the exact same thing. How would I align a matrix to a vector? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.