Jump to content

[SOLVED] Trying to read back node rotation as "float" to trigger other logic


photo

Recommended Posts

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
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.

  • Thanks 1
Link to comment
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.

  • Like 1
Link to comment
  • silent changed the title to [SOLVED] Trying to read back node rotation as "float" to trigger other logic
×
×
  • Create New...