help with wheel of fortune - collision detection between pointer and triangle
Author |
Message |
kronos44
|
Posted: Sun Jun 10, 2007 12:45 pm Post subject: help with wheel of fortune - collision detection between pointer and triangle |
|
|
I'm making a wheel of fortune game and i need help with collision detection of polygons.
I need to know what triangle the pointer stops on (ie. pink, green (i havn't made cash values for them yet)).
The pointer is a polygon of three points and the triangles on the wheel are the same.
Here's one triangle:
%triangle 1
var x1 : array 1 .. 3 of int := init (250, 250, 375)
var y1 : array 1 .. 3 of int := init (250, 454, 411)
drawfillpolygon (x1, y1, 3, brightblue)
And the pointer:
%draw pointer
var xp : array 1 .. 3 of int := init (70, 30, 30)
var yp : array 1 .. 3 of int := init (250, 260, 240)
drawfillpolygon (xp, yp, 3, blue)
The wheel spins to a random degree between 540 and 1140 when someone presses enter,
so the pointer will pass through all of the triangles and then eventually stop on one.
When it stops i want to check which triangle the pointer is on (or just if its on triangle 1 for now)
Can someone help me out? Thx
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DIIST
![](http://compsci.ca/v3/uploads/user_avatars/248212014b7d9f60741cd.jpg)
|
Posted: Sun Jun 10, 2007 1:25 pm Post subject: Re: help with wheel of fortune - collision detection between pointer and triangle |
|
|
You can either use whatdotcolor collision detection or you can go search up in google different algorithms to find a point inside a polygon. There are several of them. Most involve intersections patterns but there are some that do weird angle summation tricks to find whether a point is inside or outside the polygon. Essientally you need to check all the points of polygon 1 if they are inside polygon 2. If one or more is, then the polygons overlap and you have collision.
|
|
|
|
|
![](images/spacer.gif) |
kronos44
|
Posted: Sun Jun 10, 2007 1:58 pm Post subject: Re: help with wheel of fortune - collision detection between pointer and triangle |
|
|
I used the whatdotcolour collision, it works great. Thx
|
|
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: Sun Jun 10, 2007 4:54 pm Post subject: Re: help with wheel of fortune - collision detection between pointer and triangle |
|
|
DIIST wrote: Essientally you need to check all the points of polygon 1 if they are inside polygon 2. If one or more is, then the polygons overlap and you have collision. wink
I'm not too sure what you mean there. If you mean that when two polygons intersect at least one corner from one of the polygons must be inside of the other polygon then that is not necessarily true, and therefore not a method of collision detection.
kronos44 wrote:
I used the whatdotcolour collision, it works great. Thx
If you're making this for fun with no time deadline, then I suggest you use a different approach.
For collision between two convex polygons, I explained it in my Collision Detection tutorial. There are also slower but easier-to-understand methods of collision detection specifically for triangles, which you can google.
|
|
|
|
|
![](images/spacer.gif) |
kronos44
|
Posted: Mon Jun 11, 2007 2:36 pm Post subject: Re: help with wheel of fortune - collision detection between pointer and triangle |
|
|
This is a project that has to be done as quick as possible. I'm having another problem though.
When I try to spin the wheel sometimes it gives me an error that says "Illegal picture ID number '0'"
The error message is for this line: wheelDegree := Pic.Rotate (wheel, i, centreX, centreY)
I'll attach the entire program that i have so far (its just a beta right now, nowhere near done).
I just put the players turns in loops for the spinning so i could see if it would work, thats when I
started getting that error.
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
wheelturning22.t |
Filesize: |
7.17 KB |
Downloaded: |
116 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Mazer
![](http://compsci.ca/v3/uploads/user_avatars/1323750815476d9f446d80c.png)
|
Posted: Mon Jun 11, 2007 6:50 pm Post subject: RE:help with wheel of fortune - collision detection between pointer and triangle |
|
|
Wait, wheel of fortune? Do you actually need collision detection or can you not just check the angle of the wheel?
|
|
|
|
|
![](images/spacer.gif) |
kronos44
|
Posted: Tue Jun 12, 2007 4:07 pm Post subject: Re: help with wheel of fortune - Illegal Picture ID number "0" |
|
|
what does that erro mean, why did it happen, and how can i fix it?
heres the line:
wheelDegree := Pic.Rotate (wheel, i, centreX, centreY)
|
|
|
|
|
![](images/spacer.gif) |
|
|