[osg-users] Problem converting yaw,pitch,roll to quaternion

152 views
Skip to first unread message

Guido Knapen

unread,
Sep 3, 2015, 3:00:21 PM9/3/15
to osg-...@lists.openscenegraph.org
Hello everybody.

I'm new to this forum. For 16 hours I've been trying to solve my problem with no success. I've tried several different methods to convert but all fail.

Basicly I have this code to put some testing arrows in my scene which demonstrate yaw, pitch and roll.


Code:

for(int y = 0; y < 4; y++) // Vertical stuff
{
char *ID = 0;
float lat = 50.0 - 0.1f * y;
bool increaseYaw = false;
bool increasePitch = false;
bool increaseRoll = false;

switch(y)
{
case 0:
increaseYaw = true;
ID = "YAW";
break;
case 1:
increasePitch = true;
ID = "PITCH";
break;
case 2:
increaseRoll = true;
ID = "ROLL";
break;
case 3:
increaseYaw = true;
increasePitch = true;
ID = "YAW AND PITCH";
break;
case 4:
increaseYaw = true;
increaseRoll = true;
ID = "YAW AND ROLL";
break;
case 5:
increasePitch = true;
increaseRoll = true;
ID = "PITCH AND ROLL";
break;
case 6:
increaseYaw = true;
increasePitch = true;
increaseRoll = true;
ID = "YAW, PITCH AND ROLL";
break;
}

float yaw = 0.0f;
float pitch = 0.0f;
float roll = 0.0f;

for(int x = 0; x < 8; x++) // Horizontal stuff
{
float lon = 6.0f + 0.1f * x;

GuiLibViewerEntity *ve = mViewer->createViewerEntity( // align
ID,// align
GuiLib::GuiLibPosition(lat, lon, 1000.0), // align
20.0, // align
path, // align
x == 0);
ve->setRotationRadians(yaw, pitch, roll);
ve->setAutoScale(mAutoScale);

if(increaseYaw)
{
yaw += osg::PI / 4;
}

if(increasePitch)
{
pitch += osg::PI / 4;
}

if(increaseRoll)
{
roll += osg::PI / 4;
}
}
}




However my setRotationRadius does not work properly. One of methods which got me the closest to the proper result is this one:


Code:

void ViewerEntity::setRotationRadians(
float aYaw,
float aPitch,
float aRoll) {

osg::Matrixd mat;
mat.makeRotate(aPitch, PITCH_VEC, aYaw, YAW_VEC, aRoll, ROLL_VEC);

mModel->setLocalRotation (mat.getRotate());
}




Which generates this:
/file/d/0B7qBNqPzsL5PMWx1ZjVRR0VHbms/view?usp=sharing

EDIT: apparently I cant post images. however that's a google drive image feel free to add that to the google drive url.

As you can see the yaw, pitch and roll individually are rotated correctly. However when the yaw and pitch are combined the arrows which have a red circle around them have their yaw wrong by 180 degrees.

Can anybody please help me out?

Thanks in advance

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65014#65014





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Glenn Waldron

unread,
Sep 3, 2015, 3:08:54 PM9/3/15
to OpenSceneGraph Users

michael kapelko

unread,
Sep 4, 2015, 11:13:19 PM9/4/15
to OpenSceneGraph Users
Hi.
I use the following function to convert from degrees to quaternions:

Vec4 degreeToQuaternion(const Vec3 &degree) throw ()
{
    osg::Quat q;
    q.makeRotate(osg::DegreesToRadians(degree.x), osg::Vec3(1, 0, 0),
                 osg::DegreesToRadians(degree.y), osg::Vec3(0, 1, 0),
                 osg::DegreesToRadians(degree.z), osg::Vec3(0, 0, 1));
    return Vec4(q.x(), q.y(), q.z(), q.w());
}

Vec4 is like osg::Vec4 for my own code.

Guido Knapen

unread,
Sep 7, 2015, 4:06:08 AM9/7/15
to osg-...@lists.openscenegraph.org
Sorry for late response was not at work until today.


gwaldron wrote:
> Try this:
>
> --
>
>
>
> Good luck.
>
> Glenn Waldron
>

Tried something similar, only I didn't negate the last vector. Will try this approach.

[quote="kornerr"]Hi.

I use the following function to convert from degrees to quaternions:


> Vec4 degreeToQuaternion(const Vec3 &degree) throw ()
> {
> osg::Quat q;
> q.makeRotate(osg::DegreesToRadians(degree.x), osg::Vec3(1, 0, 0),
> osg::DegreesToRadians(degree.y), osg::Vec3(0, 1, 0),
> osg::DegreesToRadians(degree.z), osg::Vec3(0, 0, 1));
> return Vec4(q.x(), q.y(), q.z(), q.w());
> }Vec4 is like osg::Vec4 for my own code.

Tried exactly this. Will try it again.

Thanks for help so far, will report back with results.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65037#65037
Reply all
Reply to author
Forward
0 new messages