andrea.padovani Posted September 21, 2021 Share Posted September 21, 2021 Dear all, In my current project I've created behavior to rotate an object of a specific value any time a key is pressed on the keyboard with the following code: float angle = 5.0f; ObjNode->setTransform(ObjNode->getTransform() * Math::rotateY(angle)); Now I want to check what was the final value that my objects has, to trigger some other action when this value it's between 0F and90F for example. Documentation suggest that I can use ObjNode->getRotation(); to retrieve Math::quat, but I can't figure out on how to extract only Y rotation as numeric value. Looks like I also have some problem trying to print out to console/log some value for debug, I can't use the std::to_string(num_float); Link to comment
silent Posted September 22, 2021 Share Posted September 22, 2021 andrea.padovani You don't need to use std:: to log the floats in Log::message(), just use the %f placeholder: Log::message("My Float: %f\n", float); 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
cash-metall Posted September 22, 2021 Share Posted September 22, 2021 9 hours ago, andrea.padovani said: Documentation suggest that I can use ObjNode->getRotation(); to retrieve Math::quat, but I can't figure out on how to extract only Y rotation as numeric value. for getting euler angles from rotation you can use this: #include <UnigineMathLib.h> Unigine::Math::vec3 euler_angle = Unigine::Math::decomposeRotationZXY(obj->getRotation().getMat3()); float angle = euler_angle.y; //or float angle = obj->getRotation().getAngle(Unigine::Math::vec3_forvard); but in any case, be careful with the euler angles - remember that the order in which the rotation is applied is important, and that they can lead to gimballocks. 1 Link to comment
andrea.padovani Posted September 22, 2021 Author Share Posted September 22, 2021 3 hours ago, silent said: You don't need to use std:: to log the floats in Log::message(), just use the %f placeholder: Log::message("My Float: %f\n", float); .....ok, definitely my bad! I was trying every kind of conversion, ,chars array and other stuff, and basically because I forgot to #include<string> :-( After including string it's working fine your method, lot easier :D thanks! ;) 3 hours ago, cash-metall said: for getting euler angles from rotation you can use this: #include <UnigineMathLib.h> Unigine::Math::vec3 euler_angle = Unigine::Math::decomposeRotationZXY(obj->getRotation().getMat3()); float angle = euler_angle.y; //or float angle = obj->getRotation().getAngle(Unigine::Math::vec3_forvard); but in any case, be careful with the euler angles - remember that the order in which the rotation is applied is important, and that they can lead to gimballocks. thanks @cash-metall, it works perfectly for my needing! I'll take care of possible gimballocks. 1 Link to comment
Recommended Posts