Yes, the problem here is that your accelerometer is reporting absoulte
rotation, and turn_* and rotate_* functions require relative
(differential) rotation.

The simplest idea is calculate the difference between the actual
orientation and the prior one (in the previous round). And that will
give you the "inertial rotation" for the object in that round.

But, beware, that will never be exact. I'm sure you will get the
effect you want to, but after several minutes of playing with it you
will get (probably) a difference between the object orientation on
soya and what orientation says your accelerometer. That will be
because you are "replaying" all the movements again, so you are losing
precision frame by frame.

If you get that problem, the solution is:
In begin_round you extract the object orientation from the
accelerometer and create a Coordinate System with this orientation.
and make a copy of the object corrdinate system in a variable.
In that way, you have 2 known states: a) where is actually your soya's
object  b) where you want to put it at the end of the round.
Coordinate Systems (and also bodies) have a function called
"interpolate" which recieves 3 arguments: initial_state , final_state,
factor. And with that function you can get a nice and smooth movement
without losing precision.

But that has also another problem: you got the accelerometer data at
the begin of the round, and your object has moved to it at the end of
the round. So you will have one round of delay, which generally is
1/25 seconds (40ms). Generally that isn't a problem.

Also, you can directly remove all the delay by directly putting the
object in the desired orientation in advance_time function. To do
that, i generally create a 4x4 matrix with the final orientation
(you'll fill it with the accelerometre data captured on the same frame
being rendered) and replace the object matrix with yours. Take in
account that in that matrix there is position, rotation and scale. So
replacing it will replace position and scale too.




2010/8/23 David Bliss <[email protected]>:
> I think you're looking at an old version of the code, Greg; I just looked at
> http://pastebin.com/mYiB9dWh, and saw a thread that was used an infinite
> loop to poll the serial port.
>
> Fabio, the easiest route would probably be keeping the previous rotation
> value around, finding the difference between the current and previous
> rotation values, and using that with turn_x(). I haven't seen APIs to
> support anything else (reset-then-turn, set-rotation), but if they're there
> (particularly set-rotation-relative-to-original-local-axis), that would be
> more straightforward.
>
> David Bliss
> Percopo 232
> 1-616-284-1273
> CM 1534
>
>
> On Sun, Aug 22, 2010 at 7:23 PM, Greg Ewing <[email protected]>
> wrote:
>>
>> Fabio Varesano wrote:
>>
>> > However, I'm stuck on how to rotate my cuboid according to the angles
>> > calculated from the accelerometer. If I use the code posted above the
>> > animation become really slow and sloppy till almost not working.
>>
>> If I understand your code correctly, you're reading one
>> sample from the accelerometer for each animation round.
>> But if the accelerometer is producing data faster than
>> the frame rate of your animation, this isn't going to
>> work.
>>
>> For example, if your animation is running at 60fps and
>> the accelerometer is producing 300 readings/sec (as you
>> indicated in one of your posts), then your animation is
>> only using accelerometer data at one-fifth of the rate
>> needed to keep up, so it will lag further and further
>> behind.
>>
>> What you need to do is, for each frame, take all the
>> accelerometer data that has come in since the last
>> frame, accumulate all their rotations and apply them
>> to the model, before rendering the frame. You may
>> want to use a separate thread to read the accelerometer
>> samples and put them in a queue for the animation
>> thread to process.
>>
>> --
>> Greg
>>
>> _______________________________________________
>> Soya-user mailing list
>> [email protected]
>> https://mail.gna.org/listinfo/soya-user
>
>
> _______________________________________________
> Soya-user mailing list
> [email protected]
> https://mail.gna.org/listinfo/soya-user
>
>

_______________________________________________
Soya-user mailing list
[email protected]
https://mail.gna.org/listinfo/soya-user

Reply via email to