How to rotate a scene around the "camera"

Problems with Canvas, OpenGL, etc...

How to rotate a scene around the "camera"

Postby cochks » Fri Jun 04, 2010 10:49 pm

Hi -

I'm very new to Android dev work and I have been combing through doc after doc trying to wrap my head around this. Any help pointing me in the right direction would be hugely helpful.

I basically want to position a bunch of 2D elements (text, background, button all contained as one) on a GLSurfaceView at coordinates that closely match their degree location 360 degrees around the view. Then as a user touches the screen right to left, the elements rotate as if they are rotating around the "camera" 360 degrees seamlessly.

I've been messing around with gluLookAt() and also glRotatef or glTranslatef, but nothing works and now I'm more confused than ever.

Even if someone could tell me where to look to just get an element to rotate around me 360 degrees, I'll dig in to figure out how to place the elements at specific coords.

Thanks for any thoughts!
KC
cochks
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 04, 2010 10:39 pm

Top

Re: How to rotate a scene around the "camera"

Postby seed » Mon Jun 07, 2010 3:46 pm

Don't mess with gluLookAt(). Set it once.

Before drawing your elements, do a glRotate().

Should be that easy.
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: How to rotate a scene around the "camera"

Postby cochks » Mon Jun 07, 2010 5:39 pm

Seed - You're a genius! Took me only a few minutes and a few tests to prove that what I wanted to be done could actually be done using glRotate(). I wasted some serious time with gluLookAt, so thanks for the suggestion. I have one more direction-setting question if you have time.

I need to dynamically load an array of text values. Each item i the array will turn into a 2D object on the screen. I need to create a background for each object (figure I'd use a texture) but then I need to put the text on top of the background and the entire object needs to be clickable. I was reading through the Android docs and found the SpriteText example. It looks crazy complicated, but I'm thinking that is the only way to accomplish what I want to do.

Is it that complicated with Android to add dynamic text to a 2D object added to GLSurfaceView or am I just missing something here?

Thank you so much!
cochks
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 04, 2010 10:39 pm

Re: How to rotate a scene around the "camera"

Postby seed » Mon Jun 07, 2010 8:34 pm

cochks wrote:I need to dynamically load an array of text values. Each item i the array will turn into a 2D object on the screen. I need to create a background for each object (figure I'd use a texture) but then I need to put the text on top of the background and the entire object needs to be clickable. I was reading through the Android docs and found the SpriteText example. It looks crazy complicated, but I'm thinking that is the only way to accomplish what I want to do.


Wish I was full of easy answers. Unfortunately, I am not. There is no easy way to draw text. Especially for your app which I assume you want the text to look printed on these rotating billboards and therefore need the text to rotate as well. Since the text is dynamic, this is a challenge.

The only way to do it that I know of is to draw text into a texture and then composite it into a 3D scene. This is what that crazy SpriteText thingy is doing. If your text is not changing that often, then you should be able to build each of your little billboards ahead of time by copying the bitmap and then writing text onto it directly and then using this composite as the texture for opengl.

Wish I could help more, but I haven't really had a need for dynamic text.

Seed
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: How to rotate a scene around the "camera"

Postby cochks » Mon Jun 07, 2010 9:13 pm

You might not be always full of "easy answers" but you always have very helpful responses, thank you. You made me think of something. Can I "fake" 3D? My billboards are basically 2D, no perspective. Even when I rotate, I'd like them to slide off and on the screen without much perspective anyway since I want to give the illusion of 360 rotate.

So, what if I just drawBitmaps, but place them in a view with coordinates that map to 360 degrees (using Math i havent quite figured out). Would I then be able to slide the view on x-axis based on some math that translates touch events (or even down the road header sensor data) into the new x for the view? I guess I'm just not sure what I would do once a user has gone all the way around because the view would end even though I wouldn't want it to. I'd want it to stitch together. I guess this is similar to using panoramic photos to fake 3D virtual reality. Any thoughts? Would this approach be a better way to execute?

Thanks again so much for helping a newbie through this. Oddly, I assumed the math required to rotate the ojects in 3D would be the tough part, boy was i wrong! ;)

KC
cochks
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 04, 2010 10:39 pm

Re: How to rotate a scene around the "camera"

Postby seed » Tue Jun 08, 2010 1:40 pm

cochks wrote:
So, what if I just drawBitmaps, but place them in a view with coordinates that map to 360 degrees (using Math i havent quite figured out). Would I then be able to slide the view on x-axis based on some math that translates touch events (or even down the road header sensor data) into the new x for the view? I guess I'm just not sure what I would do once a user has gone all the way around because the view would end even though I wouldn't want it to. I'd want it to stitch together. I guess this is similar to using panoramic photos to fake 3D virtual reality. Any thoughts? Would this approach be a better way to execute?

Thanks again so much for helping a newbie through this. Oddly, I assumed the math required to rotate the ojects in 3D would be the tough part, boy was i wrong! ;)

KC


I think you can do something like this using 2D parabolic transformations. Basically, you stretch the image so that it is taller towards the sides of the screen. I have never done this but remember skimming a web page on it once, I think. Lots of 3D effects can be simulated in 2D using skew and stretch type transforms on 2D images. Lots of the cube type apps are done this way. I am sure there are a lot of resources on the web as to how to do this.

Regards
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Top

Re: How to rotate a scene around the "camera"

Postby cochks » Tue Jun 08, 2010 1:59 pm

Excellent suggestion, I'll look into it.

Thanks again for your help, seed!
KC
cochks
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 04, 2010 10:39 pm

Top

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

Who is online

Users browsing this forum: No registered users and 1 guest