473,468 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Keep a point inside a region?

Hello all,

Quick question!

How would i keep a point inside a region? For example, the mouse pointer.
You should be able to move the mouse around in this region but not anywhere
outside it.

How would i go about doing this?

Thanks in advance,

Brian
Nov 16 '05 #1
4 4561
Do a test move that creates a point from the current point and the new
delta. If its inside the region, you check this ising Region.IsVisible, make
the move permanent. If not, discard it.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:OS**************@TK2MSFTNGP15.phx.gbl...
Hello all,

Quick question!

How would i keep a point inside a region? For example, the mouse pointer.
You should be able to move the mouse around in this region but not
anywhere outside it.

How would i go about doing this?

Thanks in advance,

Brian

Nov 16 '05 #2
Cheers Bob.. but that was probably a bad example as i've implemented it
using the mouse position myself but it's not really ideal as what i want to
do is ensure the position of a paddle is inside of a player's region.

Since the mouse controls the paddle.. i assumed simply using the mouse
positions with Region.IsVisible would work. But if you move the mouse
quickly outside of the region, it won't redraw it where it should (at the
edge of the region).. it'll simply freeze at the last place it was drawn.

I should really be using the X and Y position of the paddle but that does
not seem to work.. as the paddle will stick as soon as it goes outside of
the region, with no way to move it back inside the region (as it's already
outside, you're disregarding any movement it's attempting).

Quite difficult to word there.. and probably more difficult to understand.

The code i was using for the mouse position was:

Point paddle1Position = new Point(e.X, e.Y);
bool isVisibleInP1Reg = player1Rgn.IsVisible(paddle1Position);

if(isVisibleInP1Reg == true)
{
paddle1_x = e.X;
paddle1_y = e.Y;
}
else
{
//do nothing
}

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
Do a test move that creates a point from the current point and the new
delta. If its inside the region, you check this ising Region.IsVisible,
make the move permanent. If not, discard it.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:OS**************@TK2MSFTNGP15.phx.gbl...
Hello all,

Quick question!

How would i keep a point inside a region? For example, the mouse pointer.
You should be able to move the mouse around in this region but not
anywhere outside it.

How would i go about doing this?

Thanks in advance,

Brian


Nov 16 '05 #3
The game needs to capture the mouse and also probably get the current mouse
position and extrapolate a line from the last position to the current one to
see if it exits the region. Bresenhams line algorithm will give you all the
points between two coordinates.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
Cheers Bob.. but that was probably a bad example as i've implemented it
using the mouse position myself but it's not really ideal as what i want
to do is ensure the position of a paddle is inside of a player's region.

Since the mouse controls the paddle.. i assumed simply using the mouse
positions with Region.IsVisible would work. But if you move the mouse
quickly outside of the region, it won't redraw it where it should (at the
edge of the region).. it'll simply freeze at the last place it was drawn.

I should really be using the X and Y position of the paddle but that does
not seem to work.. as the paddle will stick as soon as it goes outside of
the region, with no way to move it back inside the region (as it's already
outside, you're disregarding any movement it's attempting).

Quite difficult to word there.. and probably more difficult to understand.

The code i was using for the mouse position was:

Point paddle1Position = new Point(e.X, e.Y);
bool isVisibleInP1Reg = player1Rgn.IsVisible(paddle1Position);

if(isVisibleInP1Reg == true)
{
paddle1_x = e.X;
paddle1_y = e.Y;
}
else
{
//do nothing
}

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
Do a test move that creates a point from the current point and the new
delta. If its inside the region, you check this ising Region.IsVisible,
make the move permanent. If not, discard it.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:OS**************@TK2MSFTNGP15.phx.gbl...
Hello all,

Quick question!

How would i keep a point inside a region? For example, the mouse
pointer. You should be able to move the mouse around in this region but
not anywhere outside it.

How would i go about doing this?

Thanks in advance,

Brian



Nov 16 '05 #4
Bob,

Cheers for the info.

Read up on that Bresenham's Line Algorithm.. seems a bit too complicated for
me, especially at this time of night.

Will come back to that problem in a couple of days.

Thanks again!

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
The game needs to capture the mouse and also probably get the current
mouse position and extrapolate a line from the last position to the
current one to see if it exits the region. Bresenhams line algorithm will
give you all the points between two coordinates.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
Cheers Bob.. but that was probably a bad example as i've implemented it
using the mouse position myself but it's not really ideal as what i want
to do is ensure the position of a paddle is inside of a player's region.

Since the mouse controls the paddle.. i assumed simply using the mouse
positions with Region.IsVisible would work. But if you move the mouse
quickly outside of the region, it won't redraw it where it should (at the
edge of the region).. it'll simply freeze at the last place it was drawn.

I should really be using the X and Y position of the paddle but that does
not seem to work.. as the paddle will stick as soon as it goes outside of
the region, with no way to move it back inside the region (as it's
already outside, you're disregarding any movement it's attempting).

Quite difficult to word there.. and probably more difficult to
understand.

The code i was using for the mouse position was:

Point paddle1Position = new Point(e.X, e.Y);
bool isVisibleInP1Reg = player1Rgn.IsVisible(paddle1Position);

if(isVisibleInP1Reg == true)
{
paddle1_x = e.X;
paddle1_y = e.Y;
}
else
{
//do nothing
}

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
Do a test move that creates a point from the current point and the new
delta. If its inside the region, you check this ising Region.IsVisible,
make the move permanent. If not, discard it.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Basquille" <re**********@please.com> wrote in message
news:OS**************@TK2MSFTNGP15.phx.gbl...
Hello all,

Quick question!

How would i keep a point inside a region? For example, the mouse
pointer. You should be able to move the mouse around in this region but
not anywhere outside it.

How would i go about doing this?

Thanks in advance,

Brian



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kai Grossjohann | last post by:
I have a table which contains a top-aligned table cell: .... <tr style="height:40"> ... <td colspan="1" rowspan="2" align="left" valign="top" style="overflow:hidden;">...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
16
by: Niels Jensen | last post by:
I have been developing a little project which draw's a hexgrid on a panel within a form similar to this - it:s used as a client from a e-mail based strategy game: ____ ____ / \...
2
by: Trammel | last post by:
Hi. I have been trying to make a simple application that will sit in the background and alert me of any changes in window focus (IE: Pop-up windows) on my system. I have used...
5
by: mrkbrndck | last post by:
Please see the code below as I am trying to use multithreading for copying files to a new location in a way that improves performance of the client windows application. The problem occurs when 2...
3
by: Peter Proost | last post by:
Hi group, I've got this bit of code (see below) which draws a basketball field in a picturebox (width:198, height:368) but now I was wondering what would be the easiest way to check inside the...
8
by: sternr | last post by:
Hey, I use the form's graphics object to draw points at random places on the form. After drawing the points, how can I know if a certain point on the form is colored? Thanks ahead --sternr
0
by: uncensored | last post by:
Hello everyone, I'm fairly new at .Net and I have a repeater inside a repeater problem. I will attach my code to this message but basically what I am able to tell when I run my page it tells me...
1
by: renu | last post by:
Hello, I have drawn polygon on window. And I want to check wheather given point is in that polygon region or not? How shold I find that? I have created object of class region GraphicsPath path...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.