Solved

# Line equasions for eight screen zones

Posted on 2000-03-25
194 Views
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
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
• 2

LVL 22

Accepted Solution

nietod earned 100 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

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

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
###### Suggested Courses
Course of the Month6 days, 5 hours left to enroll