Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Line equasions for eight screen zones

Posted on 2000-03-25
2
Medium Priority
?
213 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 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.

609 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