HUD - matching touches to object?
hi, what im tring to do is display images to be used as an HUD, ie no matter where the camera is, these objects will always be in the same position. i can do that no problem, but i want things to happen when the user touches these locations. the problem is i dont know exactly what coordinates on the screen the rasterized data fits on. is there anyway to match touches to rasterized images or a way to control where the images will sit on the 320x480 screen, or will i have to think about perspective and go through a long process to work things out manually?
why do dogs sniff each others butts?
check this out: http://www.lighthouse3d.com/opengl/picking/
maybe that is what you can use
maybe that is what you can use
Sir, e^iπ + 1 = 0, hence God exists; reply!
Since you're not sure where your graphics are rasterizing to, I presume you're using OpenGL ES. The normal answer to this would be to look into gluUnProject, but since glu isn't included in ES, you'd have to bring your own implementation. There's one here: http://webcvs.freedesktop.org/mesa/Mesa/...iew=markup
someone must have done this before. maybe a seperate drawing mode which uses orthogonal viewpoint? am i right in thinking in using an orthogonal viewpoint the dimensions of an object dont reduce as z is further back?
Yes, that's a common approach. The idea is pretty simple:
- Set up perspective projection
- Draw 3D objects
- Clear depth buffer and/or disable depth test
- Set up orthographic projection
- Draw 2D overlay
ThemsAllTook Wrote:Yes, that's a common approach. The idea is pretty simple:right, so if i do this, will a 2d rectangle 320x by 480y fill up the whole screen when its z value is zero?
- Set up perspective projection
- Draw 3D objects
- Clear depth buffer and/or disable depth test
- Set up orthographic projection
- Draw 2D overlay
cool mr croc Wrote:right, so if i do this, will a 2d rectangle 320x by 480y fill up the whole screen when its z value is zero?
Depends on how you set up your projection. To get 1-to-1 pixel correspondence, I think you want to do something like this: glOrthof(0, 320, 0, 480, -1, 1).
With orthographic projection, the z coordinate has no bearing on the projected position of a vertex. It's common to use two-component vertices (x and y) for 2D drawing in ortho mode, which implicitly sets z to 0.
thats sounds about right, cheers bruv
i think theres something i must be missing. ive got initwithcoder running setupview, drawview delcares some vertices. now ive added the HUD with the glorthof, i get a split second of things being drawn (not what i have in the hud), then its nothing but black.
Code:
- (void)drawView {
.............
glBindTexture(GL_TEXTURE_2D, textures[1]);
glVertexPointer(3, GL_FLOAT, 0, elementVerticies);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, &fontTexCoords[208]);
for (int i = 0; i < 5; i++) {
glPushMatrix();
{
glTranslatef(-1.0, -1.0, -2.0+(i*-2.0));
glRotatef(-90.0, 1.0, 0.0, 0.0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glPopMatrix();
glPushMatrix();
{
glTranslatef(1.0, -1.0, -2.0+(i*-2.0));
glRotatef(-90.0, 1.0, 0.0, 0.0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glPopMatrix();
}
[self setupOrtho];
glPushMatrix();
{
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glPopMatrix();
[self setupView]
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
[self checkGLError:NO];
}
-(void)setupOrtho {
glDisable(GL_DEPTH_TEST);
glOrthof(0, 320, 0, 480, -1, 1);
}
- (void)setupView {
const GLfloat zNear = 0.1, zFar = 1000.0, fieldOfView = 60.0;
GLfloat size;
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
// This give us the size of the iPhone display
CGRect rect = self.bounds;
glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / (rect.size.width / rect.size.height), zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}DoG Wrote:glLoadIdentity() and glMatrixMode() ftwplease continue
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| detecting 2 touches, is order of touch significant? | sefiroths | 4 | 9,376 |
Sep 30, 2011 07:29 AM Last Post: @iOS_blog |
|
| Advice regarding Views & Touches for iPhone game | Elphaba | 5 | 2,884 |
Jul 17, 2009 01:54 PM Last Post: Frank C. |
|

