x


Rotation problem

Hi,

I'm using FLARToolKit (flash) to create an Augmented Reality-game in Unity. I have managed to send over the rotation values and by that rotate an object in Unity.

This works fine at first glance (see a small demo here: http://vimeo.com/15606701), how ever, if you tilt the marker to the left with the front still facing the camera and rotate the marker horizontally, the object will rotate vertically and vice versa.

It seems that the object rotates verticaly even if it "lies down". I made a small video of the problem here: ( http://jensborjesson.se/AR/rotationProblem.mov )

The code for the rotation is:

public void moveCSharp(string direction)
{
    string[] vec3 = direction.Split(' ');

    target = Quaternion.Euler(float.Parse(vec3[1]), float.Parse(vec3[0]), float.Parse(vec3[2]));
    transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 20f);

Does anyone have any idea what could be the problem?

Thanks in advance Jens

more ▼

asked Oct 18 '10 at 07:47 PM

Jens 1 gravatar image

Jens 1
3 3 3 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

It looks like maybe one of the axes is reversed. It almost seems logical if when you first turn the page on its side - if the cube went the other way (reverse the first axis you moved the cube on in that video) - it will all make sense, but kinda hard to visualize, so I'm not sure.

The best way to approach this is if you can post what you send from FLAR (what method of FLAR do you use to get the rotation and how do you send it to Unity).

Is the FLAR rotation is the rotation of the object or the camera? Is there a chance that the coordinate system of FLAR is not the same as Unity's? (RHS vs LHS if you know what I'm talking about).

Also - Euler angles are probably not the way to go. If you can get a Quaternion rotation from FLARToolkit, it will be much easier and neater to use in Unity. Since FLAR is based on ARToolkit - there must be a method to do this. In ARToolkit it's arUtilMat2QuatPos();

more ▼

answered Oct 18 '10 at 10:10 PM

Cyb3rManiak gravatar image

Cyb3rManiak
1.6k 1 4 17

Thanks for the quick answer. The reversed axes only happens in the situation as in the video and when it is lying flat on the table. The axis works fine when holding it straight up to the camera as seen in the other video.

I send and receives a string based on a 3D matrix of the rotation in FLAR. These are correct values (I print them out in the GUI). The difference is that these values goes between -180 to 180 while Euler in Unity automatically converts these values to 0 to 360. Also, FLAR and Unity have different orders of the x and y axis.

Oct 19 '10 at 12:01 AM Jens 1

That's why I'm saying you're better off using Quaternions. These flips will drive you mad.

Try and search how to extract the position and rotation in Vector3 and Quaternion from the matrix. As I said - there has to be some method in FLARToolkit that does this. guaranteed. If you can't find one, I'll try and look it up for you, but it's well worth the effort.

Oct 19 '10 at 12:13 AM Cyb3rManiak

I don't think you can send Vector3 and Quaternion through ExternalInterface (from flash to unity). And I still don't think that is the problem since everything is working just fine until the problem occurs

Oct 20 '10 at 10:38 AM Jens 1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3740
x2169
x665
x270
x3

asked: Oct 18 '10 at 07:47 PM

Seen: 1738 times

Last Updated: Oct 18 '10 at 07:47 PM