Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am completely lost and needed some help. I have a ontouchListener for a bitmap and know how to check if the touch was within the boundaries of the bitmap. But say I want the center of the image to be at a custom coordinate like [0,0] and the entire image to be in the range of [-319...319] and [-239...239] . Does any one have any thoughts on how to best implement an eventX and eventY to a custom coordinate pair?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you need just to take into account a displacement, you simply have to know where your origin is in standard coordinate system (the one the listener returns).

Say that your (0,0) is at (150,322), this means that when you get P = (x,y) you can get P' = (x-150,y-322) to get the point in your coordinate system.

To make it clean try to transform your origin P = (x=150,y=322) => P' = (150-150,322-322) = (0,0); lets take a point that is 100 pixel on the right to your origin: P = (250,322) => P' = (250-150,322-322) = (100,0), that is what you need.

If your coordinate system is not simply a displacement of the one your system provides (rotation, shear, scale involved), a change of homogeneus coordinate system is required.

EDIT:

As pointed out, the requirement is that the coordinate system has to produce the same range coordinate even if the view area resizes.

I assume that the aspect-ratio of the view and the scaled coordinate system is not an issue.

Let say that the dimensions of your view area size is W x H and your system gives you values for x and y so x: [0,W] and y: [0,H]; we want that the transformed value to be x: [-w,w] and y: [-h,h]. Let start by computing the transformed x:

x' = x/W => x : [0,1];

x' = x/W · (2w) => x : [0,2w];

x' = ( x/W · (2w) ) - w => x' : [-w,w] and hence

y' = (y/H · (2h) ) - h => y' : [-h,h].

You have to know - or ask the view for - W and H and set w = 319 and h = 239.

share|improve this answer
    
Thank you for this I have been wondering some sort of algorithm to solve this. I do however need the displacement to be in between a specific amount. SO say they click the very right of the image. this needs to always be 319. and if they click the very left part of the image it should always be -319. with 0,0 always being the center of the image. Would this approach work for this sort of thing? I am still a little confused on this. –  Jared Jul 17 '11 at 8:29
    
Thank you for all your help I was able to get this working thanks to your easy to understand explanation. –  Jared Jul 18 '11 at 10:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.