coolgirl97
|
Posted: Sat Jun 08, 2013 11:01 am Post subject: getting a 3d rotating sphere to bounce inside a 3d box that is rotating in turing... |
|
|
hey...
i got a 3d cube that rotates in all direction, and a 3d ball inside the cube to rotate.. i have inserted little dots on the sphere (i was supposed to do that).. and now i need help in getting the sphere to bounce inside the cube..
any ideas??
this is what i have so far
%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 R := 50
const N := 20
const PI := 3.14
var x1, y1, z1, x2, y2, z2, x3, y3, z3, vort_x1, vort_y1, vort_z1, vort_x12, vort_y12, vort_z12, vort_x13, vort_y13, vort_z13 : array 0 .. N - 1 of real
var xcm, ycm, zcm, xcm2, ycm2, zcm2, xcm3, ycm3, zcm3, theta1, phi1, psi1 : real
var ch1 : string (1)
theta1 := 1 % 1 rad = 57 degrees
const DELTA_PHI1 := 0.1
const DELTA_PSI1 := 0.1
const DELTA_THETA1 := 0.1
phi1 := 1
psi1 := 1
xcm := 650
ycm := 600
zcm := 300
xcm2 := 650
ycm2 := 600
zcm2 := 300
xcm3 := 650
ycm3 := 600
zcm3 := 300
const DELTA_TIME := 1
const TIME_DELAY := 100
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 : 0 .. N - 1
x1 (i) := R * cos (2 * PI * i / N)
y1 (i) := R * sin (2 * PI * i / N)
z1 (i) := 0
x2 (i) := R * sin (2 * PI * i / N)
y2 (i) := 0
z2 (i) := R * cos (2 * PI * i / N)
x3 (i) := 0
z3 (i) := R * cos (2 * PI * i / N)
y3 (i) := R * sin (2 * PI * i / N)
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
for i : 0 .. N - 1
vort_x1 (i) := (cos (theta1) * cos (phi1) * cos (psi1) - sin (phi1) * sin (psi1)) * x1 (i) -
(cos (theta1) * cos (phi1) * sin (psi1) + sin (phi1) * cos (psi1)) * y1 (i) +
sin (theta1) * cos (phi1) * z1 (i)
vort_y1 (i) := (cos (theta1) * sin (phi1) * cos (psi1) + cos (phi1) * sin (psi1)) * x1 (i) -
(cos (theta1) * sin (phi1) * sin (psi1) - cos (phi1) * cos (psi1)) * y1 (i) +
sin (theta1) * sin (phi1) * z1 (i)
vort_z1 (i) := -sin (theta1) * cos (psi1) * x1 (i) +
sin (theta1) * sin (psi1) * y1 (i) +
cos (theta1) * z1 (i)
end for
for i : 0 .. N - 1
vort_x12 (i) := (cos (theta1) * cos (phi1) * cos (psi1) - sin (phi1) * sin (psi1)) * x2 (i) -
(cos (theta1) * cos (phi1) * sin (psi1) + sin (phi1) * cos (psi1)) * y2 (i) +
sin (theta1) * cos (phi1) * z2 (i)
vort_y12 (i) := (cos (theta1) * sin (phi1) * cos (psi1) + cos (phi1) * sin (psi1)) * x2 (i) -
(cos (theta1) * sin (phi1) * sin (psi1) - cos (phi1) * cos (psi1)) * y2 (i) +
sin (theta1) * sin (phi1) * z2 (i)
vort_z12 (i) := -sin (theta1) * cos (psi1) * x2 (i) +
sin (theta1) * sin (psi1) * y2 (i) +
cos (theta1) * z2 (i)
end for
for i : 0 .. N - 1
vort_x13 (i) := (cos (theta1) * cos (phi1) * cos (psi1) - sin (phi1) * sin (psi1)) * x3 (i) -
(cos (theta1) * cos (phi1) * sin (psi1) + sin (phi1) * cos (psi1)) * y3 (i) +
sin (theta1) * cos (phi1) * z3 (i)
vort_y13 (i) := (cos (theta1) * sin (phi1) * cos (psi1) + cos (phi1) * sin (psi1)) * x3 (i) -
(cos (theta1) * sin (phi1) * sin (psi1) - cos (phi1) * cos (psi1)) * y3 (i) +
sin (theta1) * sin (phi1) * z3 (i)
vort_z13 (i) := -sin (theta1) * cos (psi1) * x3 (i) +
sin (theta1) * sin (psi1) * y3 (i) +
cos (theta1) * z3 (i)
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)
for i : 0 .. N - 1
%Start bouncing
drawline (round (xcm + vort_x1 (i)),
round (ycm + vort_y1 (i)),
round (xcm + vort_x1 ((i + 1) mod N)),
round (ycm + vort_y1 ((i + 1) mod N)),
blue)
drawfilloval (round (xcm + vort_x1 (i)), round (ycm + vort_y1 (i)), 3, 3, black)
drawline (round (xcm2 + vort_x12 (i)),
round (ycm2 + vort_y12 (i)),
round (xcm2 + vort_x12 ((i + 1) mod N)),
round (ycm2 + vort_y12 ((i + 1) mod N)),
blue)
drawfilloval (round (xcm2 + vort_x12 (i)), round (ycm2 + vort_y12 (i)), 3, 3, black)
drawline (round (xcm3 + vort_x13 (i)),
round (ycm3 + vort_y13 (i)),
round (xcm3 + vort_x13 ((i + 1) mod N)),
round (ycm3 + vort_y13 ((i + 1) mod N)),
blue)
drawfilloval (round (xcm3 + vort_x13 (i)), round (ycm3 + vort_y13 (i)), 3, 3, black)
%End bouncing
end for
delay (100)
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)
for i : 0 .. N - 1
drawline (round (xcm + vort_x1 (i)),
round (ycm + vort_y1 (i)),
round (xcm + vort_x1 ((i + 1) mod N)),
round (ycm + vort_y1 ((i + 1) mod N)),
white)
drawfilloval (round (xcm + vort_x1 (i)), round (ycm + vort_y1 (i)), 3, 3, white)
drawline (round (xcm2 + vort_x12 (i)),
round (ycm2 + vort_y12 (i)),
round (xcm2 + vort_x12 ((i + 1) mod N)),
round (ycm2 + vort_y12 ((i + 1) mod N)),
white)
drawfilloval (round (xcm2 + vort_x12 (i)), round (ycm2 + vort_y12 (i)), 3, 3, white)
drawline (round (xcm3 + vort_x13 (i)),
round (ycm3 + vort_y13 (i)),
round (xcm3 + vort_x13 ((i + 1) mod N)),
round (ycm3 + vort_y13 ((i + 1) mod N)),
white)
drawfilloval (round (xcm3 + vort_x13 (i)), round (ycm3 + vort_y13 (i)), 3, 3, white)
end for
if hasch then
getch (ch)
%Turn Upwards
if ch = chr (200) then
psi1 := psi1 + DELTA_PSI1
%Turn Downwards
elsif ch = chr (208) then
psi1 := psi1 - DELTA_PSI1
%Turn Right
elsif ch = chr (205) then
theta1 := theta1 + DELTA_THETA1
%Turn Left
elsif ch = chr (203) then
theta1 := theta1 - DELTA_THETA1
elsif ch = "1" then
psi := psi + DELTA_PSI
%Turn Downwards
elsif ch = "2" then
psi := psi - DELTA_PSI
%Turn Right
elsif ch = "3" then
theta := theta + DELTA_THETA
%Turn Left
elsif ch = "4" then
theta := theta - DELTA_THETA
end if
end if
end loop
Thank you! |
|
|