?
Solved

Line equasions for eight screen zones

Posted on 2000-03-25
2
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 300 total points
ID: 2657088
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
ID: 2657095
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

765 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