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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-14-2008, 07:16 AM   #1 (permalink)
CaptainRedmuff
New Member
 
Join Date: Jun 2008
Location: North Yorkshire, UK
Age: 27
Posts: 75
CaptainRedmuff is an unknown quantity at this point
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
 

» Advertisements
» Online Users: 525
23 members and 502 guests
Absentia, baja_yu, Batman, BuzzingDanZei, Chickenrig, eldakh94, eski, gbenna, headkaze, JoeRCruso, linkmx, LunarMoon, Mp808, poke, RickSDK, sacha1996, smithdale87, spiderguy84, TheTakeOver, toolifog, Triston, vbovio, wandou
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,548
Threads: 94,074
Posts: 402,711
Top Poster: BrianSlick (7,990)
Welcome to our newest member, mrtdmb
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:26 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.