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 > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-01-2011, 04:25 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 2
hendrikgruss is on a distinguished road
Default Convert Object Coordinates in Screen Coordinates

Hey guys,

I'm quite new to OpenGL ES, but now trying to get my first simple game running. There I got to a situation, where I wanted to know, when I touch at a point on the screen, what object is behind that point. So I need a function which converts the screen coordinate in a object coordinate or, what I suppose is easier, to convert the coordinates of an object in screen coordinates. Then I found this method: Software Prodigy: gluUnProject for iPhone / OpenGL ES
But I didn't get it running well, it only gives me the coordinates (0,0) back.
I don't know whether this is the right solution for my problem and I'm looking forward to your answers. Hopefully there are some easier functions for this and some tips and tricks

Greetings,
Hendrik Gruß
hendrikgruss is offline   Reply With Quote
Old 10-01-2011, 06:38 PM   #2 (permalink)
Programmer
 
Stinkee2's Avatar
 
Join Date: Nov 2010
Location: New York
Age: 17
Posts: 15
Stinkee2 is on a distinguished road
Default

Actually, in a week or so I was going to be looking into that for my stuff. I have a basic idea of it, but I still need to research the process of it. To my understanding this is one way it could work:

You have some form of spatial partitioning and frustum culling for your camera, then when you touch the screen you cast a ray through the view frustum and then run a test on all the objects in the frustum to see which ones intersect with the line. An optimization of this could be testing just the bounding areas of the objects and then doing more detailed tests on the objects in order from closest to farthest from the camera's position until you have an intersection with the object itself. This might be easier to understand than that:

Code:
ObjectList Objects;
RayCast Ray = Camera.CastRay(TouchPosition);
For each Object O in view frustum
{
    BoundingArea BV = O.GetBoundingArea();
    if(BV.IntersectsWithRay(Ray))
    {
        Objects.AddObjectToList(O);
    }
}
For each Object O in Objects (IMPORTANT: Ordered from nearest to farthest)
{
     if(O.IntersectsWithRay(Ray)) return O;
}
You'll have to figure out on your own how to order them from nearest to farthest from the camera, but I believe that is a pretty good method. There may be faster methods, but for now that's all I have.

I hope I helped!
__________________
This is a signature.

Last edited by Stinkee2; 10-01-2011 at 10:31 PM.
Stinkee2 is offline   Reply With Quote
Old 10-02-2011, 04:25 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 2
hendrikgruss is on a distinguished road
Default

Yes, I suppose this should work
But how do I get the data of the ray? I don't know where it should start or where it ends, so I can't calculate the intersection point.
Is there a simple way to get it or do I have to work with matrices like Projection and Modelview?
hendrikgruss is offline   Reply With Quote
Old 10-02-2011, 07:44 AM   #4 (permalink)
Programmer
 
Stinkee2's Avatar
 
Join Date: Nov 2010
Location: New York
Age: 17
Posts: 15
Stinkee2 is on a distinguished road
Default

The ray starts from (or passes through) a point on the near plane and ends at (or goes in the direction of) a point on the far plane of the camera view. I'm not sure how exactly you could calculate it. I have some ideas but they'd be no help to you right now. This might help you though: Picking
__________________
This is a signature.
Stinkee2 is offline   Reply With Quote
Reply

Bookmarks

Tags
coordinates, gluunproject, iphone, opengl es 1.1

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
» Online Users: 386
11 members and 375 guests
7twenty7, apatsufas, comicool, Creativ, Dalia, dansparrow, Duncan C, HemiMG, Murphy, pbart, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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