Collision
Author |
Message |
Mr. T
|
Posted: Mon Aug 21, 2006 11:45 pm Post subject: Collision |
|
|
I imported a picture of a ball, but in reality it's a square. I don't want to use rectangular collision detection, rather I want to make the ball seem more realisitic by using oval collision detection. How do you suppose I accomplish this? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Tue Aug 22, 2006 12:56 am Post subject: (No subject) |
|
|
use mathimatics....
as appose to a square, balls use a radius |
|
|
|
|
|
Mr. T
|
Posted: Tue Aug 22, 2006 1:19 am Post subject: Alex's Opinion |
|
|
you're misunderstanding..lemme try re-explaining
1. the pic appears to be a ball
2. in reality it is a square
3. i want to make the (square) pic to act like a real ball --> circular collision would be the natural conclusion
4. however, how would i use circular collision if the pic is a square and thus has no radius? |
|
|
|
|
|
TokenHerbz
|
Posted: Tue Aug 22, 2006 2:22 am Post subject: (No subject) |
|
|
Ohhh lol, thats a better question...
I must ask why the object is an actual square? when you want this as a ball.
Im sure you can change that, but if you dont, lets do the next best thing.
We need to get a radius which will fit in the box, and not out... it is easier if you know how large your box is, as you are importing a picture, you can set its size yourself.
When you've reached a radius, then use that for your box. but first a problem.
your box chords are x,y. I believe however, the balls x,y chords are in the center of the ball, which i dont know what your tring to accomplish, so cant help you 100%...
this will show you what i mean.
code: |
var balls: int := 1
var keys: array char of boolean
loop
Input.KeyDown(keys)
if keys (KEY_UP_ARROW) then
balls += 1
elsif keys (KEY_DOWN_ARROW) then
balls -= 1
end if
cls
drawbox(50,50,100,100,7)
drawoval(50,50,balls,balls,7)
View.Update
delay(20)
end loop
|
you can use math tho, to center the balls x,y with your picture, then for collition, your the ballx,y - radius, to get the left , and +radius to get the right.
If you post code, and explain the program your trying to write, im sure i can assist. |
|
|
|
|
|
pj_ladd12
|
Posted: Tue Aug 22, 2006 10:37 am Post subject: (No subject) |
|
|
just make a ball in turing (drawoval) around your pic, and use make those ball coordinates move with your actual pic....so when you do your colliision it is the drawball you will write in math.distance formula or whatever formula you wish to use |
|
|
|
|
|
richcash
|
Posted: Tue Aug 22, 2006 1:44 pm Post subject: (No subject) |
|
|
You could make it so easy if your pic size (rectangle) fits perfectly tight around the ball (meaning that all four sides of your "rectangle" are touching the ball). Then, the radius of the ball is in the center :
code: | ballx := x1 + (x2 - x1) div 2
bally := y1 + (y2 - y1) div 2 |
and the ball radius is also very easy to find :
code: | ball_x_radius := (x2 - x1) div 2
ball_y_radius := (y2 - y1) div 2 |
If you don't have it like that, well, I suggest you do, because it will be a whatdotcolour headache if you don't! |
|
|
|
|
|
Bored
|
Posted: Tue Aug 29, 2006 7:06 am Post subject: (No subject) |
|
|
problem with your solution richcash is that you might not know the size of the picture (otherwise you'd know the radius) therfore how would you know where x2 is. So it's best to replace (x2 - x1) with a Pic.Width or Pic.Height. You can look in the turing help files to find more information on these commands. |
|
|
|
|
|
jamonathin
|
Posted: Tue Aug 29, 2006 7:38 am Post subject: (No subject) |
|
|
You guys are thinking about this way to much. Just think of what a radius is: 1/2 ball width.
Therefore the radius of the ball is Pic.Width(pic) div 2.
Then if you can simply draw the pic at:
code: |
Pic.Draw (pic, x - (Pic.Width(pic) div 2), y - (Pic.Height(pic) div 2), picMerge) |
This results in the picture being drawn to the bottom left of x and y. Which will also be the exact middle of the ball (assume the dimensions are even). Then you can use whichever methods you like for circular detection. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
richcash
|
Posted: Tue Aug 29, 2006 1:54 pm Post subject: (No subject) |
|
|
Yes, you are right, I was assuming that you knew the size of the picture, but I was just giving a quick solution. I would assume that Mr. T already knew he could replace my (x2 - x1) with Pic.Width and (y2 - y1) with Pic.Height. However, the main point of my post was that it would be really easy if you had your picture perfectly fitting the oval (or at least centered). Imagine solving such a problem without this condition. Whatdotcolour might be able to do something, but imagine if the ball and background were multi-coloured! |
|
|
|
|
|
|
|