Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2008, 08:16 AM   #1 (permalink)
New Member
 
Join Date: Jun 2008
Location: North Yorkshire, UK
Age: 27
Posts: 75
Question OpenGL Rotation Origin Problems

Hi guys,

I've had a browse around and can't seem to find any mention of this, i'm starting to make progress with learning OpenGL, but theres one thing thats totally throwing me off for the time being. Maybe someone will be kind enough to shed some light on this for me.

Currently, i am simply rendering a textured rectangle to the screen. I was thumbing through tutorials and wanted to improve my rendering by adding in some rotation and possibly throw in some alpha blending when i came across this post http://www.iphonedevsdk.com/forum/ip...d-opacity.html

Huzzah i thought, as i happily modded my blitting method to include rotations and was presented with a slightly rotated object, but all was not as expected. For some reason (which i'm sure is totally obvious), the rectangle is rotated about the top left point, ie: 0.0, 0.0 which is really what i would expect, 0.0, 0.0 being the origin and all... but i want my object to be rotated around its center point, not the origin of the screen.

I have set up my glOrthof and glViewport for landscape orientation as such:

Code:
glViewport(0.0, 0.0, backingWidth, backingHeight);

//other stuff here

glOrthof(0.0, backingHeight, backingWidth, 0.0, -1.0, 1.0);
This gives me a landscape orientation with the top left coords being 0.0, 0.0 and bottom right being 480.0, 320.0 which is my prefered coordinate system. As of such, this appears to be the main origin for all object rotations, which isn't really what i want. Is there any way i can translate an objects origin to rotate around its center point?

for example, if i were to render the rect:

Code:
my_rect = CGRectMake(backingWidth / 4, backingHeight / 4, backingWidth / 2, backingHeight / 2);
a small rect half the width and height of the device would be presented directly in the center of the screen. Any rotations made to this however would be about the origin of 0.0, 0.0 of the screen and not the object itself. Is there any way to fix this so that the object would rotate around its center piont, in this example being the center of the screen?

I dont mind changing the coordinate system if needs be, but i would still prefer to use the current 0.0, 0.0, 480.0, 320.0 landscape orientation as opposed to -1.0, 1.0, 1.0, -1.0 unless of course it would be a feasible endeavour to write a utility function to convert between the two coordinate systems when rendering?

Any help would be greatly appreciated, thanks for reading
CaptainRedmuff is offline   Reply With Quote
Old 09-15-2008, 04:00 AM   #2 (permalink)
New Member
 
Join Date: Jun 2008
Location: North Yorkshire, UK
Age: 27
Posts: 75
Default

Sorry to bump the post, but i could really use some help with this one.

It seems that rotations must be made around the origin of the screen/device (0.0, 0.0) but surely that can't be the case as not every object/model rendered is required to rotate around the origin, but rather its own origin, if that makes sense?

Is there a way to set the rotation origin, or translate the object to the screen origin, rotate and back again?

Using the coordinate system 0.0, 0.0, 480.0, 320.0 for landscape orientation works perfectly, but obviously this issue with rotating objects around the origin is completely holding up any progress i can make.

Please, if anyone knows of a method, or any tutorials that can outline what must be done, i would be very grateful for any help you guys can throw my way

Just for completeness, the code i'm using for rotation is:

Code:
glRotate(rotation, 0.0, 0.0, 1.0);
Simple as it may seem, that one single line has caused me a weekend of headaches and very little progress. I'm positive there must be a way to fix this, can anyone point me in the right direction please?

Thanks for reading.
CaptainRedmuff is offline   Reply With Quote
Old 09-21-2008, 06:59 PM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

I think you have to save the current transformation matrix (CTM) (glPushMatrix?), load the identity matrix, translate your object into the origin, rotate it, translate it back into its original position and restore the CTM (glPopMatrix?).
Norbert is offline   Reply With Quote
Reply

Bookmarks

Tags
landscape, opengl, rotation

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0