- Home /
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
Answer by Cyb3rManiak · Oct 18, 2010 at 10:10 PM
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();
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.
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.
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
Your answer
Follow this Question
Related Questions
Different programming in Flash? 0 Answers
A node in a childnode? 1 Answer
Rotate only Y-axis of some object toward another 3 Answers
Problem with locking rotation 1 Answer
Transform rotation 2 Answers