SpiderPig Posted March 16, 2018 Share Posted March 16, 2018 When turning an entity, GetRotation() will return correct for a while then the Z axis will pop to zero for a bit before it starts reading properly again. Below is some test code showing the problem. On my current project, sometimes the Turn() function will suddenly pop to random values, but I'm unable to reproduce this here yet. I'm using the latest BETA build. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* box; bool App::Start() { window = Window::Create("Turn Test",50,50, 1024, 768); window->Show(); context = Context::Create(window); world = World::Create(); DirectionalLight* light = DirectionalLight::Create(); light->SetRotation(35, 35, 35); Camera* camera = Camera::Create(); box = Model::Box(); box->Move(0, 0, 2); return true; } bool App::Loop() { if (window->KeyHit(Key::Escape) == true) { return false; } box->Turn(0.2, 0.2, 0.2); Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); std::stringstream ss; ss << "rot = " << box->GetRotation().ToString(); context->DrawShadowText(ss.str(), 20, 20); context->Sync(true); return true; } Quote Link to comment Share on other sites More sharing options...
gamecreator Posted March 16, 2018 Share Posted March 16, 2018 I had a similar issue a few years ago. Try GetRotation(true) versus GetRotation(false) to see if either gives you the correct value. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 16, 2018 Author Share Posted March 16, 2018 I tried that and and it seems to do the exact same thing. With the following code though, GetRotation(false) works but GetRotation(true) dosn't. I think the global xy & z will vary to the local rotation due to rotation on multiple axis's, but it shouldn't set to zero suddenly then back to some other number should it? Vec3 rot = box->GetRotation(); rot.x += 0.2f; rot.y += 0.2f; rot.z += 0.2f; box->SetRotation(rot); Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); std::stringstream ss; ss << "rot = " << box->GetRotation().ToString(); context->DrawShadowText(ss.str(), 20, 20); ss.str(""); ss << "rot = " << box->GetRotation(true).ToString(); context->DrawShadowText(ss.str(), 20, 40); Quote Link to comment Share on other sites More sharing options...
Josh Posted March 17, 2018 Share Posted March 17, 2018 It sounds like it is working correctly. Turning an object does not simply increment each pitch yaw and roll value. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Crazycarpet Posted March 17, 2018 Share Posted March 17, 2018 Euler angles are obtained from the Quaternion as such: Vector3 Quaternion::GetEulerAngles() const { float yy = y * y; float t0 = -2.f * (x * z + w * y); t0 = t0 > 1.f ? 1.f : t0; t0 = t0 < -1.f ? -1.f : t0; return Vector3( Math::ToDegrees(std::asinf(t0)), Math::ToDegrees(std::atan2(2.f * (x * y - w * z), -2.f * (yy + z * z) + 1.f)), Math::ToDegrees(std::atan2(2.f * (y * z - w * x), -2.f * (x * x + yy) + 1.f)) ); } So yeah, what Josh said. If you just simply incremented pitch, yaw, roll and that was it you'd experience gimble lock. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 19, 2018 Author Share Posted March 19, 2018 Ah okay. Thanks for the explanation. Quote Link to comment Share on other sites More sharing options...
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.