Hi Massimo,
You may find the quaternions in pyeuler useful:
http://code.google.com/p/pyeuclid/
I'm not sure, but I think using that terminology, if you have a
quaternion representing your position/orientation on the surface of the
sphere, then converting it to euler angles gives your (longitude,
latitude, heading) = their (heading, attitude, bank). Your motion
routines should all be straightforward: convert each of your directions
to quaternions, and then multiply.
You will end up with something like
current_pos = Quat()
frwd = Quaternion.new_rotate_euler(...)
left = Quaternion.new_rotate_euler(...)
rot = Quaternion.new_rotate_euler(...)
while True:
# to move forward
current_pos *= frwd
# to move back
current_pos /= back
# similarly for others
(long, lat, head) = current_pos.get_euler()
The details are probably a little off (I'm a little rusty on quats
myself, and it depends on the conventions you use), but I think that's
the gist of it. The link in the source for pyeuler
(http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm)
seems useful.
--Mike
Massimo Di Stefano wrote:
Hi All,
" i'm not expert programmer, just a biologist student :-/
with self-teached python experience
so apologize my questions if they are based on wrong assumptions "
for my study i need to write a code to inteface a joystick device
with an open source application similar to google earth.
this application is a 3d globe based on openscenegraphic (OSG),
it has a "tcp listner interface" that accept xml message to move a
camera-view around the globe
the message to move the globe is something like :
go_to_lat_lon(latitude longitude roll picth head)
i tried to code in python using pygame, the results is (my fault) an
"ugly" code
that is not able to update the position according with heading changes
(view direction).
exactly i have a 3 axis joystick
axis_x -> +/- longitude
axis_y -> +/- latitude
axis_z -> +/- 0-360° (heading)
axis_v = 0-1 (speed)
the code i wrote use the axis_x and axis_y to change longitude and
latitude and axis_z to change the view direction.
but it is totally wrong beacouse if i have heading = 0 = 360 (e.g.
look to north)
the code works as aspected ... but if i change direction (view turns)
the axis code is not update.
so if i look yo east and put the joysrick up (go ahead) it don't go to
east .. but go ever to north.
move the axis_y up move the planet to north
move the axis_y down move the planet to south
move axis_y left and right move the planet to west and east
but beacouse my code is totally separated by the heading changes, if i
change heading the joystik x/y axis action is immutate.
this beacouse i connect the x/y action to a code that simply do an
increase/decrease lon-lat values.
increase :
for i in arange(j , j+1):
lati = [sum(zlat)]
a = abs(axis_v) * abs(axis_x)
lati.insert( i+1,a )
zlat = array(lati)
lat = sum(zlat)
j = 0.1
for i in arange(j , j+1):
lati = [sum(zlat)]
a = abs(axis_v) * abs(axis_x)
lati = [sum(lati) - a]
zlat = array(lati)
lat = sum(zlat)
j = 0.1
i used the increase decrease code to handle all the avaiable
condition, North, South, East, Ovest, Ne, Nw , Se , Sw :
1)
axis_x < 0
axis_y == 0
2)
axis_x == 0
axis_y > 0
3)
axis_x > 0
axis_y == 0
4)
axis_x == 0
axis_y < 0
5)
axis_x < 0
axis_y > 0
6)
axis_x > 0
axis_y > 0
7)
axis_x > 0
axis_y < 0
8)
axis_x < 0
axis_y < 0
i hope exists already a function in opengl that can help me to solve
this problem
reading a lot on google seems my problem can be solved using complex
math like quaternion
or rotation around an arbitrary axis.
i can ignore roll and pich, beacouse i can chenge them using the
joystick hat .. an roll and pich are ininfluent on the lon-lat
position ... while the heading is strictly related to the position
beacouse it represent the movment direction.
plese apologize again my ugly code, this what i'm actually using :
http://www.geofemengineering.it/data/epi_joy.py
this the results :
http://www.geofemengineering.it/Site/Media/ossimplanet_joystick-2.mp4
while here i tried to learn quaternion .. but my brain is not hable
"yet" to undstand how to works with quaternion in a
"longitude - latitude" space :-(
http://www.geofemengineering.it/data/epiquath.py
i hope some one can help me!
please i'm italian so it is a bit hard to find the right word to
describe my problem
for eny more detailed explanaton, please ask me where i need to give
more precise informations.
thanks to help me!
ciao,
Massimo.