Posted: Wed May 29, 2013 5:47 pm Post subject: bouncing a ball... PLEASE HELP

I need to make a ball bounce within a box...
i got the box done and the bouncing boundaries for the x and y.... NOW I NEED TO ADD A Z.. so the ball can bounce front and back as well..
PLEASE HELP ME!!

This is what i have so far....
drawline (510,360,510,40, black)
drawline (510,360,190,360,black)
drawline (190,360,190,40, black)
drawline (190,40,510,40, black)

if x > x_right_boundary then
x0 := 2 * x_right_boundary - x
y0 := y
v0x := -v0x
t := 0
end if

if x < x_left_boundary then
x0 := 2 * x_left_boundary - x
v0x := -v0x
y0 := y
t := 0
end if

if y > y_top_boundary then
y0 := 2 * y_top_boundary - y
v0y := -v0y
x0 := x
t := 0
end if

if y < y_bottom_boundary then
y0 := 2 * y_bottom_boundary - y
v0y := -v0y
x0 := x
t := 0
end if
t := t + DELTA_TIME
cls
drawline (510,360,510,40, black)
drawline (510,360,190,360,black)
drawline (190,360,190,40, black)
drawline (190,40,510,40, black)

Posted: Wed May 29, 2013 5:55 pm Post subject: RE:bouncing a ball... PLEASE HELP

Your z coord would reflect how close the ball is to the user. When the z is bigger(or smaller), the ball would get bigger. So you could change the radius by some amount based on the z coord.

coolgirl97

Posted: Wed May 29, 2013 5:59 pm Post subject: Re: bouncing a ball... PLEASE HELP

Thanks,

but the thing is i'm really new to comp sci.. (have no idea y i took the course), and my teacher does not know how to teach :S
so...

how exactly do i add the z coord???

Thank you so much!!

Nathan4102

Posted: Wed May 29, 2013 6:02 pm Post subject: RE:bouncing a ball... PLEASE HELP

Well "z" would be another variable, just like x and y, and you'd increase it the same way you increase your other variables. Then when you draw the ball, just have the radius relative in some way to z, instead of the constant RADIUS.

E: You'd have to remember to make the ball "bounce" in the z plane as well, just like your x and y's.

coolgirl97

Posted: Wed May 29, 2013 6:18 pm Post subject: Re: bouncing a ball... PLEASE HELP

so would i do something like this??.. (sorry for all the questions btw)...

Posted: Wed May 29, 2013 6:39 pm Post subject: RE:bouncing a ball... PLEASE HELP

Youre only changing the x and y parameters of "drawfilloval". round(x) and round(y) should stay as the x and y parameters. The thing you need to change is the x and y radius(3'rd and 4'th parameter). Assuming we're looking at this ball straight down the z plane, as z increases, the ball would appear bigger, correct? Thus, as z increases, we need to draw the ball larger.

coolgirl97

Posted: Thu May 30, 2013 8:01 am Post subject: Re: bouncing a ball... PLEASE HELP

Okay... i kinda get what u r saying.. thank you!

but.. just one more question...

so instead of this:
if
z > z_front_boundary then
z0 := 2 * z_front _boundary - z
v0z := -v0z
x0 := x
t := 0

end if

if
z < z_back_boundary then
z0 := 2 * z_back_boundary - z
v0z := -v0z
x0 := x
t := 0

end if

will it be something like this?? :

if
z > z_front_boundary then
RADIUS := 20
v0z := -v0z
x0 := x
t := 0

end if

if
z < z_back_boundary then
RADIUS := 10
v0z := -v0z
x0 := x
t := 0
end if

THANK U SO MUCH !! <3

jr5000pwp

Posted: Thu May 30, 2013 8:21 am Post subject: Re: bouncing a ball... PLEASE HELP

I wouldn't do it like that personally. I would take more of an approach of

This allows for more logical update code, and better control over different scale/time/distance factors. Note that I used +- to note that both have their advantages and you should decide for yourself if your RADIUS constant should represent the highest radius of the lowest radius.

coolgirl97

Posted: Thu May 30, 2013 8:34 am Post subject: Re: bouncing a ball... PLEASE HELP

so... would depth_scale be a const???
and will i need to use it anywhere else other than drawfilloval?

ty!

coolgirl97

Posted: Thu May 30, 2013 8:38 am Post subject: Re: bouncing a ball... PLEASE HELP

okay, so this is what i have so far..

its prob all messed up, but can u tell me what i have to do to make it work??

Posted: Thu May 30, 2013 9:02 am Post subject: RE:bouncing a ball... PLEASE HELP

Firstly, your z boundaries aren't set.
Secondly, you'd want to declare a DEPTH_SCALE constant. This should probably be a real and you'll just need to play with it until it feels right.
Thirdly, you aren't doing checking for your z co-ordinate. You can probably just copy the x or y code you have and substitute z in, making sure to use the appropriate variables such as z_front_boundary.

coolgirl97

Posted: Thu May 30, 2013 12:54 pm Post subject: Re: bouncing a ball... PLEASE HELP