Solved

Line equasions for eight screen zones

Posted on 2000-03-25
2
197 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 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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

729 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