3D Cube rotationg unexpectedly on touch

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

3D Cube rotationg unexpectedly on touch

Postby keerthi » Thu Aug 12, 2010 7:20 am

Hi everyone ,im new to this forum ;)
hey buddies i am facing diffculty in solving some issues related to cube transformations :cry:

Im trying to rotate a 3D cube on touch. the distance moved to left or right is taken as the angle of rotation with respect to Y axis and the distance moved to up or down is taken as the angle of rotation with respect to X axis .
So these are the rotations im making
glrotate(angleXdistance, 0, 1, 0); // with respect to Y axis
glrotate(angleYdistance, 1, 0, 0); // with respect to X axis


so every time i add the angles with previous angles lik angleXdiatance + = angleXdiatance; in touch event

so the problem im facing is :
1.) when i rotate to right or left for 90 degree it rotates corectly ,and after when i rotate to up or down it rotates with respect to Z axis instead of Y axis
2.)when i rotate to right or left for 180 degree it rotates corectly ,and after when i rotate to up it rotates
down , to say in it rotates in opposite direction .

i could analyse that after 90/180 degree roataions the default axes changes , so it will roatate with respect to current axes , so i tried to chk the condition if it crosses 90 thn instead of rotating with respect to X rotate with respect to Z , and after 180 , reverse the rotation angle sign .. it works :D but nt always :evil: .. sm prblm occurs in sm other condition,,,

so i found out all posibilities , at certain angle of rotation , these are the current axes and thn passes those axes but still din work coz two rotations are happening so tht the number of possiblities increaes which is nt possible to find all conditions..

so if anyone has idea how to solve this issue plz help ... my cube and my head rotating unexpectedly :shock: plz help to rotate them correctly :roll:
i could see many examples or applications with such problem there also ...
keerthi
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Aug 12, 2010 6:40 am
Location: India

Top

Re: 3D Cube rotationg unexpectedly on touch

Postby MichaelEGR » Thu Aug 12, 2010 8:18 am

Indeed welcome to 3D... :)

This is iPhone related, but OpenGL ES is OpenGL ES, so all the concepts are the same (check mid way down for the info you seek):
http://www.sunsetlakesoftware.com/2008/ ... -opengl-es

Basically the problem you are facing (heh) is that you have to manage the touch input / rotation from the currentViewing perspective and the model coordinate system. It's quite possible to attempt this as described in the link above.

Now I haven't verified the following info recently at all or on various devices, but glGetFloatV didn't work right on the G1 early Android OS versions. I've been using something akin to the MatrixGrabber approach to keep a local matrix stack CPU side. This has worked fine for creating a camera / frustum for frustum culling, but is a pain to extend to unlimited usage. Ideally like I mentioned I have to verify glGetFloatV usage on the N1, Droid, and more modern devices myself and only fall back to the software method for devices that don't support glGetFloatV. It's been on my list for a while to figure out a reliable way to do this across all devices w/ Android 1.5+ support. Prob get to it soon. So I haven't even tried user perspective touch rotation recently.

So review the link above and verify that glGetFloatV is working on your device and try it out. Best of luck and report back if you can because I'm interested in your results.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: 3D Cube rotationg unexpectedly on touch

Postby keerthi » Thu Aug 12, 2010 8:54 am

hi thnaks for welcoming me ;)
no right now glgetfloatv is not working , i tried in android 2.2 os also .. but hv not tried in rea device..
hmm in iphone glgetflaot there but not glunproject , in android the other way ... hmmm ;-p

i din try that matrix grabber in andorid api sample , but instead i tried to calculate manually ..
in my task .. there is no translation , once scaling and all other are rotations..

so each time i calculate the current roatation marix and multiply with model view matrix
but i traced the values got from iphone getfloat api , and the calculated values .. the values match but not the matrix positions ,,

can u tell me one thing ..
if glrotate(angleA,1,0,0)
glrotate(angleB,0,1,0)
glrotate(angleC,0,0,1)

are rotations then for the composite rotation matrix , what is order of rotation ?? and the angles ??

http://www.songho.ca/opengl/gl_anglesto ... isrotation
i used the rotation matrices definiiton from this link...

so if i could calculate the matirx correctly then i could try the method suggested by you ;)
keerthi
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Aug 12, 2010 6:40 am
Location: India

Re: 3D Cube rotationg unexpectedly on touch

Postby MichaelEGR » Thu Aug 12, 2010 10:00 am

I'll try and continue the discussion soon, but given this line you wrote, "no right now glgetfloatv is not working , i tried in android 2.2 os also .. but hv not tried in rea device.." My advice is to ditch the simulator ASAP as it has only cursory connection to working with the real device. You'll find there are many quirks between various Android OS versions and device specific issues with OpenGL ES. It's a hardware specific API, so you just can't use the simulator.

I've been working for 18+ months now to create a reliable middleware platform that hides as many device specific bugs / issues as possible and it's gets pretty hairy at times. I'm barrelling towards release and I'm definitely going to explore the glGetFloatV issue (which devices support it, etc.) in more detail soon enough and provide a tutorial that accomplishes user view rotation of objects.

In brief though if you have any camera oriented code that sets a user view point. I use android.opengl.GLU and gluLookAt that will change the model view matrix and you'll need to grab the current model view matrix afterward. Also for sanities sake make sure you are correctly switching to the model view matrix and aren't currently operating on the projection matrix. Also get on a real device ASAP (broken record here!) ;P

So keep at it..
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: 3D Cube rotationg unexpectedly on touch

Postby keerthi » Thu Aug 12, 2010 10:14 am

oh i will try to get a new device ;) ,
hey but in log it displayed that the function glgetfloatv prototype not yet implemented !! but my app is simple , no need to change the view /camera , im just creating a cube , roatate on touch , when i click on any face the poto on that face should be displayed .. right now im struck in tht roataion issue and face detection ... have u worked on the face detection of cube ?? , its still bigger monster for me right now ;-p have spent lot time o these issues but not yet successful ...
Last edited by keerthi on Thu Aug 12, 2010 10:17 am, edited 1 time in total.
keerthi
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Aug 12, 2010 6:40 am
Location: India

Re: 3D Cube rotationg unexpectedly on touch

Postby keerthi » Thu Aug 12, 2010 10:16 am

and i wish that your effort since 18 months would soon get better results ;)
"Honest prayers are always answered and honest works are always rewarded " ;)
keerthi
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Aug 12, 2010 6:40 am
Location: India

Top

Re: 3D Cube rotationg unexpectedly on touch

Postby MichaelEGR » Thu Aug 12, 2010 10:40 am

thanks for the kind words.. Release is imminent (of course I've been saying that for a while), but the barrel is in the river and the waterfall is in sight. ;P I'm taking a very prudent and thorough approach to all of this and that simply takes a bit of time especially considering how unstable (low level audio and graphics APIs/dev) Android has been over it's short existence.

What Android device do you have now? It doesn't surprise me at all that glGetFloatV is not supported in the simulator likewise as I mentioned it wasn't supported on the G1 back when I tried to play around with this.. Lots of pressing and hair pulling moments since then too, so I haven't got back to it...

I've also discussed cube/face detection on here, so perhaps look through my posts.. Again though not something I've implemented as a demo yet; though it's a good one.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: 3D Cube rotationg unexpectedly on touch

Postby keerthi » Thu Aug 12, 2010 2:29 pm

hii , i tried that method as in the link u said ,in iphone but its not working ;(
could please help me ..
and ur post on face detection ,i had read before also ..it gave overview of various method prefectly ;)
but i guess i cant use the color picking method ..coz it doesnt support in android ,it always gives value 0 .. i guess may be as u said it wont wrk in simulator ..
and other mehtods lik ray casting im trying but struck in some concepts..
when i rotate the orientation of cube changes ,,.. so if i projrct a ray from near to far ,it will always be with some angle other than 90 .. co cube is rotated where as the frustrum is not .. so i cant check for the perpedicular condition to identify the face ...

am i going wrong with concepts ?? plz help me ..
keerthi
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Aug 12, 2010 6:40 am
Location: India

Re: 3D Cube rotationg unexpectedly on touch

Postby MichaelEGR » Thu Aug 12, 2010 2:59 pm

You are trying things the emulator simply just doesn't support. Your next step is to start working on a real device then the quest to achieve what you are attempting can continue. Bummer news if you don't have access to a device, but that unfortunately is a requirement with OpenGL ES. Don't continue banging your head against the emulator trying to get OpenGL to work because it's badly supported and worse outright broken.. :(
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest