Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Please help...TURING!!
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
coolgirl97




PostPosted: Thu Jun 06, 2013 8:33 am   Post subject: Please help...TURING!!

hey... i was given this assignment where i have a box that needs to rotate in all direction when pressing the arrow keys. There needs to be a ball moving inside the box as well...

i've got the box to rotate, and tried to get the ball to bounce around... but i think there's something wrong with my coding... because it is not working..

can u please have a look below, and help?? thank you so much!!

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

%getting the cube
setscreen ("graphics:1280,1080")


%Variable for Colour
var box, background : int

%Variable for Size
var S : real

%Perspective Related Variables
var theta, phi, psi : real

%Location Related Variables
var x_cm, y_cm : real

%Cube Related Variables
var cube_x, cube_y, cube_z, vort_x, vort_y, vort_z, p_x, p_y : array 1 .. 8 of real

%---------------------------------------------------------------------------------------------

const DELTA_TIME := 1
const TIME_DELAY := 10
const DELTA_THETA := 0.1
const DELTA_PHI := 0.1
const DELTA_PSI := 0.1

background := 0
box := 7
S := 200

const ZV := 1500

var ch : string (1)

x_cm := 640
y_cm := 600

phi := 0
psi := 0
theta := 300

var t : real

const L := 75
const w := 20
t := 0

%---------------------------------------------------------------------------------------------

cube_x (1) := +S
cube_y (1) := +S
cube_z (1) := +S

cube_x (2) := -S
cube_y (2) := -S
cube_z (2) := -S

cube_x (3) := -S
cube_y (3) := +S
cube_z (3) := +S

cube_x (4) := +S
cube_y (4) := -S
cube_z (4) := -S

cube_x (5) := -S
cube_y (5) := -S
cube_z (5) := +S

cube_x (6) := +S
cube_y (6) := +S
cube_z (6) := -S

cube_x (7) := +S
cube_y (7) := -S
cube_z (7) := +S

cube_x (8) := -S
cube_y (8) := +S
cube_z (8) := -S

%---------------------------------------------------------------------------------------------

Draw.FillBox (0, 0, maxx, maxy, background)

%---------------------------------------------------------------------------------------------

%Rotative Formula
loop

for i : 1 .. 8
vort_x (i) := (cos (theta) * cos (phi) * cos (psi) - sin (phi) * sin (psi)) * cube_x (i) -
(cos (theta) * cos (phi) * sin (psi) + sin (phi) * cos (psi)) * cube_y (i) +
sin (theta) * cos (phi) * cube_z (i)
vort_y (i) := (cos (theta) * sin (phi) * cos (psi) + cos (phi) * sin (psi)) * cube_x (i) -
(cos (theta) * sin (phi) * sin (psi) - cos (phi) * cos (psi)) * cube_y (i) +
sin (theta) * sin (phi) * cube_z (i)
vort_z (i) := -sin (theta) * cos (psi) * cube_x (i) +
sin (theta) * sin (psi) * cube_y (i) +
cos (theta) * cube_z (i)
end for

for i : 1 .. 8
p_x (i) := vort_x (i) / (1 - vort_z (i) / ZV)
p_y (i) := vort_y (i) / (1 - vort_z (i) / ZV)
end for

%---------------------------------------------------------------------------------------------

%Cube Illustration
drawline (round (x_cm + p_x (1)), round (y_cm + p_y (1)), round (x_cm + p_x (3)), round (y_cm + p_y (3)), box)
drawline (round (x_cm + p_x (1)), round (y_cm + p_y (1)), round (x_cm + p_x (6)), round (y_cm + p_y (6)), box)
drawline (round (x_cm + p_x (1)), round (y_cm + p_y (1)), round (x_cm + p_x (7)), round (y_cm + p_y (7)), box)
drawline (round (x_cm + p_x (2)), round (y_cm + p_y (2)), round (x_cm + p_x (4)), round (y_cm + p_y (4)), box)
drawline (round (x_cm + p_x (2)), round (y_cm + p_y (2)), round (x_cm + p_x (5)), round (y_cm + p_y (5)), box)
drawline (round (x_cm + p_x (2)), round (y_cm + p_y (2)), round (x_cm + p_x (8)), round (y_cm + p_y (8)), box)
drawline (round (x_cm + p_x (3)), round (y_cm + p_y (3)), round (x_cm + p_x (5)), round (y_cm + p_y (5)), box)
drawline (round (x_cm + p_x (3)), round (y_cm + p_y (3)), round (x_cm + p_x (8)), round (y_cm + p_y (8)), box)
drawline (round (x_cm + p_x (4)), round (y_cm + p_y (4)), round (x_cm + p_x (6)), round (y_cm + p_y (6)), box)
drawline (round (x_cm + p_x (4)), round (y_cm + p_y (4)), round (x_cm + p_x (7)), round (y_cm + p_y (7)), box)
drawline (round (x_cm + p_x (5)), round (y_cm + p_y (5)), round (x_cm + p_x (7)), round (y_cm + p_y (7)), box)
drawline (round (x_cm + p_x (6)), round (y_cm + p_y (6)), round (x_cm + p_x (8)), round (y_cm + p_y (8)), box)

delay (TIME_DELAY)

drawline (round (x_cm + p_x (1)), round (y_cm + p_y (1)), round (x_cm + p_x (3)), round (y_cm + p_y (3)), white)
drawline (round (x_cm + p_x (1)), round (y_cm + p_y (1)), round (x_cm + p_x (6)), round (y_cm + p_y (6)), white)
drawline (round (x_cm + p_x (1)), round (y_cm + p_y (1)), round (x_cm + p_x (7)), round (y_cm + p_y (7)), white)
drawline (round (x_cm + p_x (2)), round (y_cm + p_y (2)), round (x_cm + p_x (4)), round (y_cm + p_y (4)), white)
drawline (round (x_cm + p_x (2)), round (y_cm + p_y (2)), round (x_cm + p_x (5)), round (y_cm + p_y (5)), white)
drawline (round (x_cm + p_x (2)), round (y_cm + p_y (2)), round (x_cm + p_x (8)), round (y_cm + p_y (8)), white)
drawline (round (x_cm + p_x (3)), round (y_cm + p_y (3)), round (x_cm + p_x (5)), round (y_cm + p_y (5)), white)
drawline (round (x_cm + p_x (3)), round (y_cm + p_y (3)), round (x_cm + p_x (8)), round (y_cm + p_y (8)), white)
drawline (round (x_cm + p_x (4)), round (y_cm + p_y (4)), round (x_cm + p_x (6)), round (y_cm + p_y (6)), white)
drawline (round (x_cm + p_x (4)), round (y_cm + p_y (4)), round (x_cm + p_x (7)), round (y_cm + p_y (7)), white)
drawline (round (x_cm + p_x (5)), round (y_cm + p_y (5)), round (x_cm + p_x (7)), round (y_cm + p_y (7)), white)
drawline (round (x_cm + p_x (6)), round (y_cm + p_y (6)), round (x_cm + p_x (8)), round (y_cm + p_y (8)), white)

%---------------------------------------------------------------------------------------------

% Manipulating the Cube

if hasch then
getch (ch)

%Turn Upwards

if ch = chr (200) then
psi := psi + DELTA_PSI

%Turn Downwards

elsif ch = chr (208) then
psi := psi - DELTA_PSI

%Turn Right

elsif ch = chr (205) then
theta := theta + DELTA_THETA

%Turn Left

elsif ch = chr (203) then
theta := theta - DELTA_THETA


end if

end if

% ______________________________________________________________________________________________________________________

const DELTATIME := 0.10
const TIMEDELAY := 10
var x, y, z, x0, y0, z0, v0x, v0y, v0z, T : real

const x_right_boundary := 1100
const x_left_boundary := 250
const y_top_boundary := 1000
const y_bottom_boundary := 250

const RADIUS := 0.025

const DEPTH_SCALE := 0.1

x0 := 100
y0 := 100
z0 := 100
v0x := 30
v0y := 10
v0z := 20
T := 0
x := x0 + v0x * T
y := y0 + v0y * T
z := z0 + v0z * T

drawoval (645, 600, 20, 20, black)

delay (TIME_DELAY)

drawfilloval (645, 600, 20, 20, white)
T := T + 1

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
end loop
Sponsor
Sponsor
Sponsor
sponsor
doller




PostPosted: Wed Aug 14, 2013 12:36 am   Post subject: Re: Please help...TURING!!

The information was useful and i got this site from Google.com
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: