Blender meet android (via OSC-script) (and also 2 noob questions)

this is a simple example showing how to control objects in BGE with an android phone.

To work, it uses a free android market application called andOSC, and liblo + pyliblo libraries. You can get a little more info here

Also detailed instructions to get it working are inside the blend file, where the scripts are too.

hope you enjoy…

and now the questions:______________________________________ XD

i know it’s far to perfect implementation, i want to improve it, by stopping the rotation when the object reach the phone orientation.

Now i need to apply opposite rotation to stop it, because i used applytorque to get smooth movement, but i can’t find how to convert the orientation matrix i get from the object in order to get it stopped at the end of the roll.

I mean, andOSC send tree degrees (one for each axis), and applytorque get this vector (in radians), but when i call for cube.orientation blender gives me a matrix. How can i convert this matrix to one degree for axis?

The other question is…

I used a piece of code from mike pan’s example of mouse and camera movement in bge, to get orientation working:

cube.applyTorque([rx,ry,0], True)   
cube.applyTorque([0,0,rz], False)

why i cant use this —> cube.applyTorque([rx,ry,rz], True) ???
(the object gets crazy but i dont know why)

and sorry for such a long explanation…


blender-meet-android.blen.blend (687 KB)

Cool script.

I’m not sure I understand your bge question so this may be a dumb- but why applyTorque and not applyRotation?

Looks interesting!

Something like this would be useful for sculpting to rotate the model with left hand while sculpting with the tablet.

For that purpose maybe an option to rotate the view instead of an object would be nice.

@teldredge: if you apply rotation, the cube instantly jump to the next orientation (without smoothness, in a discrete way) and torque means (as i understand) that the object is impulsed in this directions (like with angular velocity, in a continuous way)
you can see the diferences changing applytorque with applyrotation, (and you must change also sens value to 0.1) and see the effects… You will see abrupt changes in the rotation.

But in any case, the applyrotation remains applying and i need to compare object orientation with phone orientation…

@Eclectiel: it will be cool feature but my script only works in the BGE and i don’t know if it’s possible to run an OSCserver out of the game engine …

I think the true/false on the applyTorque refer to local axes. When true x and y are calculated using the object x and y axes. For the z axis local is set to false so the object rotates about the global z axis.

If you think about it, this makes sense. As x and y axes are rotated, the object’s z axis rotates. If you rotate about this local z, there is no way to guarantee where it points so the model goes haywire.

  1. Install liblo and pyliblo modules and make it available for blender (by copying to your blender’s python folder)
    Usually I have no problem installing plugins. But here I have to unzip twice, the I get a whole tree of files. I don’t find What exactly do I have to copy and to where ?
  2. Install andOSC app in your phone from the android market (free app, grab it here)
  3. Setup ip address and port number in android (get it with ifconfig in a terminal)
    I prefer to work with the usb. As I allways have problem with IP.
    OSC on the Android says "IP Address : 192:168:0.1
    Port :56789
    Am I something with this information ?
    There are so many settings in the Android.

if you can import liblo in the blender console you have no need to copy anything…

did you compile liblo and pyliblo acording to it’s readme files? what os are you using?

and to work you need to connect the computer and the phone to the same wifi net.

@funkywyrm: thanks for the explanation. I think i undestand it better…

I surrender :frowning:

I have the same problem like filipc(can´t not find the file)
I use Ubuntu 10.10 and has install the python-liblo via Ubuntu Software Center.
And i users blender-2.56a-beta-linux-glibc27-i686

i think you installed pyliblo for python, not for python3…
try this dependencies…

sudo apt-get install python3 python3-dev build-essential liblo7 liblo-tools liblo-dev

then download pyliblo, unpack in a folder and do:

sudo python3 build
sudo python3 install

but i dont know if it will work with latest versions of blender…