This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Quaternion initialization

Tags: None
(comma "," separated)
Itun
Registered Member
Posts
7
Karma
0

Quaternion initialization

Tue May 24, 2011 9:46 pm
I looked here:http://eigen.tuxfamily.org/dox/TutorialGeometry.html and tried to do this:
Code: Select all
Quaternion<float> q = AngleAxis<float>(angleX * M_PI / 180, Vector3f::UnitX());

I returned a long log of errors with this one:
Code: Select all
../src/camera/Camera.cpp:23: error: conversion from `Eigen::AngleAxis<float>' to non-scalar type `Eigen::Quaternion<float, 0>' requested

How to initialize the quaternion?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Quaternion initialization

Wed May 25, 2011 6:30 am
ok, this is an annoying c++ issue, while the syntax Type obj = other; makes a call to the Type ctor (and not operator=), c++ does not accept to call an explicit ctor in this case, you either have to write:

Quaternion<float> q(AngleAxis<float>(angleX * M_PI / 180, Vector3f::UnitX()));

or

Quaternion<float> q = Quaternion<float>(AngleAxis<float>(angleX * M_PI / 180, Vector3f::UnitX()));


I'll fix the doc and put a warning about that very common issue.
Itun
Registered Member
Posts
7
Karma
0

Re: Quaternion initialization

Wed May 25, 2011 2:28 pm
Ok. In the same document:
Code: Select all
vec2 = gen1 * vec1;

Thus I do:
Code: Select all
   Vector3d         frustumDirection;
.
.
.
   Quaternion<double> q(AngleAxis<double>(angleX * M_PI / 180, Vector3d::UnitX()));
   frustumDirection = q * frustumDirection;


And is there more optimized method of transformation a vector, for instance:
Code: Select all
frustumDirection *= q;
OR
frustumDirection.transform(q);
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Quaternion initialization

Thu May 26, 2011 6:27 pm
frustumDirection *= q;

would means:

frustumDirection = frustumDirection * q;

that is not the same. And no there is no such shortcut. Note that in this case that would only optimize the writing, not the performance.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft