Solved

Line equasions for eight screen zones

Posted on 2000-03-25
2
156 Views
Last Modified: 2010-04-02
I am writing an RPG in C++, and I'm taking some mouse input. I want to divide the screen into eight zones (top-left, top, top-right, right, bottom-right, etcetera). I could use some help finding the equasions for those lines (i.e., if I have a mouse point (x, y), how do I know which of the 8 zones it is in?)
0
Comment
Question by:starhawk
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
Comment Utility
Is there no middle zone?  i.e I think you want 9 zones.

Divide the screen height and the screen width in both 3.  If the mouse's x coordinate is between 0 and 1/3 of the width, then the mouse is on one of the three left zones.  if the x coordinates is between 1/3 and 2/3 of the width it is in the one of the three middle zones, if between 2/3 and the screen with, it is one of the right zones.  Then do the same thing with the y coordinate.

example follows.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
const int TopLft = 0;
const int TopMdl = 1;
const int TopRht = 2;
const int MdlLft = 3;
const int MdlMdl = 4;
const int MdlRht = 5;
const int BtmLft = 6;
const int BtmMdl = 7;
const int BtmRht = 8;

int MouseX = ?;
int MouseY = ?;
int Width = ?;
int Height = ?;

int Zone;

if  (MouseX < Width/3)
   Zone = 0;
else if  (MouseX < 2*Width/3)
   Zone = 1;
else
   Zone = 2;

if  (MouseY < Height/3)
   ; // do nothing.
else if  (MouseY < 2*Height/3)
   Zone += 3;
else
   Zone += 6;

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now