Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Check for Point in Sector

Author
Message
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 7th Jul 2009 13:24 Edited at: 7th Jul 2009 13:28
A sector can be imagined as a slice from a circular cake.
This code will check to see if a point falls within a sector.
The sector can be any size and facing any direction.







HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 7th Jul 2009 15:02
This would work well with the pie chart code.

Dark Physics makes any hot drink go cold.
feiting shadow
17
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 7th Jul 2009 19:38 Edited at: 7th Jul 2009 19:39
oh my god...

any chance this could be modified to display images and create a GUI system that's like HowDo's pie-chart idea?

I'm unfamiliar with images and memblocks, but this might be worth getting that on my list of reading material.

I could just make images shaped like this but hard-coded for angles is probably easier, with images loading in arcs.

Edit: Similar to my button system (below somewhere), with mouseover and mouseclick being displayed differently.

Signed
------
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 10th Jul 2009 18:59
Nice work Scraggle. This a very clean way to have an AI "see" within a forward-viewing area.


Open MMORPG: It's your game!
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 11th Jul 2009 05:55
Quote: "This a very clean way to have an AI "see" within a forward-viewing area."


Perfect for a 'stealth' game's Gaurds.....

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Jul 2009 00:30 Edited at: 14th Jul 2009 00:40
Scraggle, you have inspired me. Here is a 3D version of your sector code (you might hardly recognize it).

Basics - same as yours, just added in a Vertical arc sector along with the Horizontal arc sector. Because there is a lot of 3D information, objects were used to pass data to the function instead of individual data items (coordinates, angles, arcs, and so on). It currently only works on a horizontal plain in a 3D environment; as opposed to allowing full 3D rotation.

The snippet is below in the code box. I've also upload a sample showing how the sector works using a Peripheral Vision demo. Objects within the sector's arc and radius become fully visible, while objects outside of the sector are dimmed.

Sector Code Snippet



This image shows the values that need to be passed to the function (and also what the sector looks like).



For the demo, use the WASD keys to move the camera around. Press the Space key to "lock" the camera's position current position (as far as the Peripheral Vision code is concerned) and move around to see what the arc looks like from the side.


Open MMORPG: It's your game!

Attachments

Login to view attachments
kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 14th Jul 2009 22:01 Edited at: 14th Jul 2009 22:05
RiiDii, I helped you out a little with rotation and 3D sectors.

You will need to make 1 vector and 4 matrices for it to work.

Untested but it should work.




Login to post a reply

Server time is: 2024-05-18 15:13:03
Your offset time is: 2024-05-18 15:13:03