diff --git a/a.out b/a.out index 20ffbef..85a57c9 100755 Binary files a/a.out and b/a.out differ diff --git a/display.cmi b/display.cmi index 2cd14a5..87de004 100644 Binary files a/display.cmi and b/display.cmi differ diff --git a/display.cmx b/display.cmx index 42e6acc..15dae57 100644 Binary files a/display.cmx and b/display.cmx differ diff --git a/display.ml b/display.ml index 3c22c26..4081ad2 100644 --- a/display.ml +++ b/display.ml @@ -408,7 +408,7 @@ let is_visible (pt0 : pt_3d) (hash : (int * int * int, coloredCube dynamic) Hash | Not_found -> (*Stdlib.print_endline " EMPTY"; *)true | ReturnBool b -> (*Printf.printf " Aborted to %b" b ; Stdlib.print_endline " "; *)b ;; -let is_visible_cube (cube : pt_3d array) (hash : (int * int * int, coloredCube dynamic) Hashtbl.t) = +let is_visible_poly (cube : pt_3d array) (hash : (int * int * int, coloredCube dynamic) Hashtbl.t) = (*Printf.printf "cube (%f, %f, %f)" cube.(0).x cube.(0).y cube.(0).z; Printf.printf "[of length %d]" (Array.length cube); Stdlib.print_endline " ";*) @@ -420,6 +420,24 @@ let is_visible_cube (cube : pt_3d array) (hash : (int * int * int, coloredCube d Stdlib.print_endline " "; *) !res ;; +let is_visible_cube (cube : pt_3d array) (hash : (int * int * int, coloredCube dynamic) Hashtbl.t) = + let r0 = is_visible cube.(0) hash + and r1 = is_visible cube.(1) hash + and r2 = is_visible cube.(2) hash + and r3 = is_visible cube.(3) hash + and r4 = is_visible cube.(4) hash + and r5 = is_visible cube.(5) hash + and r6 = is_visible cube.(6) hash + and r7 = is_visible cube.(7) hash in + (r1 || r2 || r3 || r4 || r5 || r6 || r7 || r0, [| + r0 || r1 || r2 || r3 ; + r4 || r5 || r6 || r7 ; + r0 || r1 || r5 || r4 ; + r1 || r2 || r6 || r5 ; + r2 || r3 || r7 || r6 ; + r3 || r0 || r4 || r7 + |]) ;; + let draw_texture (rect : (int * int) array) (text : texture) light = (*set_color white; fill_poly rect ;;*) @@ -449,7 +467,8 @@ let draw_texture (rect : (int * int) array) (text : texture) light = let draw_cube_p (cube : pt_3d array) (hash : (int * int * int, coloredCube dynamic) Hashtbl.t) screen_wd screen_ht fov r g b = let adjusted = adjust_to_camera cube in let (draw_faces, draw_cube) = are_faces_behind adjusted in - if draw_cube && (is_visible_cube cube hash) then begin + let (draw_cube_2, draw_faces_2) = is_visible_cube cube hash in + if draw_cube && draw_cube_2 then begin (*Printf.printf "drawing cube (%f, %f, %f)" cube.(0).x cube.(0).y cube.(0).z ; Stdlib.print_endline " ";*) let proj = project adjusted screen_wd screen_ht fov in @@ -499,10 +518,11 @@ let draw_cube_p (cube : pt_3d array) (hash : (int * int * int, coloredCube dynam swap distances i !idmax; swap order i !idmax; swap draw_faces i !idmax; + swap draw_faces_2 i !idmax; done; set_line_width 2; for i = 0 to 5 do - if draw_faces.(i) then begin + if draw_faces.(i) && draw_faces_2.(i) then begin let light = max (0.) (1. -. (distances.(i)) /. 12.5) in (*let face_R = int_of_float ((float_of_int r) *. light) and face_G = int_of_float ((float_of_int g) *. light) @@ -515,6 +535,12 @@ let draw_cube_p (cube : pt_3d array) (hash : (int * int * int, coloredCube dynam end done end ;; + +(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *) +(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *) +(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *) +(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *) +(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *) let sum_x (poly : pt_3d array) = let res = ref 0. in @@ -881,62 +907,6 @@ let cheesify (laby : tile array array array) = done done done;; -(* -(* z q s d for movement, p to go up, m to go down, a to rotate left, e to rotate right *) -let rec move_cam (cubes : pt_3d array array) b c =(* Printf.printf "[%b]" b; Stdlib.print_endline " " ; *)match c with - | 'z' -> - camera_xyz.z <- camera_xyz.z +. Float.cos ((float_of_int !camera_angle_y) *. 3.1415926535 /. 180.); - camera_xyz.x <- camera_xyz.x +. Float.sin ((float_of_int !camera_angle_y) *. 3.1415926535 /. 180.); - if b && (is_collision camera_xyz cubes) then move_cam cubes false 's' - | 'q' -> - camera_xyz.z <- camera_xyz.z +. Float.cos (((float_of_int !camera_angle_y) +. 90.) *. 3.1415926535 /. 180.); - camera_xyz.x <- camera_xyz.x +. Float.sin (((float_of_int !camera_angle_y) +. 90.) *. 3.1415926535 /. 180.); - if b && (is_collision camera_xyz cubes) then move_cam cubes false 'q' - | 's' -> - camera_xyz.z <- camera_xyz.z -. Float.cos ((float_of_int !camera_angle_y) *. 3.1415926535 /. 180.); - camera_xyz.x <- camera_xyz.x -. Float.sin ((float_of_int !camera_angle_y) *. 3.1415926535 /. 180.); - if b && (is_collision camera_xyz cubes) then move_cam cubes false 'z' - | 'd' -> - camera_xyz.z <- camera_xyz.z +. Float.cos (((float_of_int !camera_angle_y) -. 90.) *. 3.1415926535 /. 180.); - camera_xyz.x <- camera_xyz.x +. Float.sin (((float_of_int !camera_angle_y) -. 90.) *. 3.1415926535 /. 180.); - if b && (is_collision camera_xyz cubes) then move_cam cubes false 'q' - | 'p' -> - camera_xyz.y <- camera_xyz.y -. 1.; - if b && (is_collision camera_xyz cubes) then move_cam cubes false 'm' - | 'm' -> - camera_xyz.y <- camera_xyz.y +. 1.; - if b && (is_collision camera_xyz cubes) then move_cam cubes false 'p' - | 'a' -> camera_angle_y := !camera_angle_y + 15 - | 'e' -> camera_angle_y := !camera_angle_y - 15 - | _ -> () ;; - -let play laby = - cheesify laby; - let (cs, rs, gs, bs) = convert_laby laby in - - camera_xyz.z <- -. (1.5) ; - camera_xyz.x <- -. (float_of_int width) /. 2. ; - camera_xyz.y <- -. (float_of_int height) /. 2. ; - - (*print_cubes cs ;*) - - while true do - auto_synchronize false; - open_graph " 1500x1000"; - set_color black; - fill_poly [|(0, 0); (1500, 0); (1500, 1000); (0, 1000); (0, 0)|]; - set_color white; - - draw_multiples_cubes_colored cs rs gs bs hash __width__ __height__ fov render_distance ; - - auto_synchronize true; - - Printf.printf "current pos : (%f, %f, %f)" (-. camera_xyz.x) (-. camera_xyz.y) camera_xyz.z; - Stdlib.print_endline " "; - - let usr_input = get1char () in - move_cam cs.tab true usr_input - done ;;*) let rec move_cam_hash (cubes : coloredCube dynamic) b c =(* Printf.printf "[%b]" b; Stdlib.print_endline " " ; *)match c with | 'z' -> diff --git a/display.o b/display.o index c3549b7..5d08e10 100644 Binary files a/display.o and b/display.o differ