 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members       Author Message
coolgirl97 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..

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)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)

%Ball bouncing

const DELTA_TIME := 0.10
const TIME_DELAY := 10
const x_right_boundary := 480
const x_left_boundary := 220
const y_top_boundary := 330
const y_bottom_boundary := 70
var x, y, x0, y0, v0x, v0y, t : real

x0 := 100
y0 := 100

v0x := 30
v0y := 10

t := 0

loop

x := x0 + v0x * t
y := y0 + v0y * t

delay (TIME_DELAY)

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)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)
end loop    Nathan4102 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)...

drawline (510,360,510,40, black)
drawline (510,360,190,360,black)
drawline (190,360,190,40, black)
drawline (190,40,510,40, black)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)

%Ball bouncing

const DELTA_TIME := 0.10
const TIME_DELAY := 10
const x_right_boundary := 480
const x_left_boundary := 220
const y_top_boundary := 330
const y_bottom_boundary := 70
[color=red]const z_front_boundary :=
const z_back_boundary :=[/color]
var x, y, [color=red]z[/color] , x0, y0[color=red], z0,[/color] v0x, v0y,[color=red] v0z[/color] ,t : real

x0 := 100
y0 := 100
[color=red]z0 := [/color]

v0x := 30
v0y := 10
[color=red]v0z :=[/color]

t := 0

loop

x := x0 + v0x * t
y := y0 + v0y * t
[color=red]z:= z0 + v0z * t[/color]
delay (TIME_DELAY)
delay (TIME_DELAY)
delay (TIME_DELAY)
delay (TIME_DELAY)
[/color]
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

[color=red]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[/color]

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)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)
end loop coolgirl97 Posted: Wed May 29, 2013 6:19 pm   Post subject: Re: bouncing a ball... PLEASE HELP

ignore.. the colour red thing...

i did it to show what i added.. but it is html coding, so you won't see the difference right away , anyways...

Thanks! Nathan4102 Posted: Wed May 29, 2013 6:26 pm   Post subject: RE:bouncing a ball... PLEASE HELP

No problem, and that should work, except you need to draw your circle based on your z coord aswell. onedirectionlover Posted: Wed May 29, 2013 6:31 pm   Post subject: Re: bouncing a ball... PLEASE HELP

i did... didn't i ??

delay (TIME_DELAY)

delay (TIME_DELAY)

delay (TIME_DELAY)    Nathan4102 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...

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
v0z := -v0z
x0 := x
t := 0

end if

if
z < z_back_boundary then
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??

Thank you so much.

drawline (510,360,510,40, black)
drawline (510,360,190,360,black)
drawline (190,360,190,40, black)
drawline (190,40,510,40, black)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)

%Ball bouncing

const DELTA_TIME := 0.10
const TIME_DELAY := 10
const x_right_boundary := 480
const x_left_boundary := 220
const y_top_boundary := 330
const y_bottom_boundary := 70
const z_front_boundary :=
const z_back_boundary :=
var x, y, z , x0, y0, z0, v0x, v0y, v0z ,t : real

x0 := 100
y0 := 100
z0 := 100

v0x := 30
v0y := 10
v0z := 20

t := 0

loop

x := x0 + v0x * t
y := y0 + v0y * t
z := z0 + v0z * t

delay (TIME_DELAY)

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)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)
end loop jr5000pwp 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

Thank you so much!!

I've kinda fixed up everything u told me...

is this correct?? :

drawline (510,360,510,40, black)
drawline (510,360,190,360,black)
drawline (190,360,190,40, black)
drawline (190,40,510,40, black)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)

%Ball bouncing

const DELTA_TIME := 0.10
const TIME_DELAY := 10
const x_right_boundary := 480
const x_left_boundary := 220
const y_top_boundary := 330
const y_bottom_boundary := 70
const z_front_boundary := 200
const z_back_boundary := 100
var x, y, z , x0, y0, z0, v0x, v0y, v0z ,t, DEPTH_SCALE : real

DEPTH_SCALE := 18

x0 := 100
y0 := 100
z0 := 100

v0x := 30
v0y := 10
v0z := 20

t := 0

loop

x := x0 + v0x * t
y := y0 + v0y * t
z := z0 + v0z * t

delay (TIME_DELAY)

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

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

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)

drawline (450,300,450,100, black)
drawline (450,300,250,300,black)
drawline (250,300,250,100, black)
drawline (250,100,450,100, black)

drawline (190,360,250,300, black)
drawline (450,300,510,360,black)
drawline (190,40,250,100, black)
drawline (510,40,450,100, black)
end loop Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First        Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: