Skip to content

Commit

Permalink
Add lambda cube
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesAverill committed Oct 18, 2023
1 parent 849b615 commit e2d6d65
Show file tree
Hide file tree
Showing 7 changed files with 6,645 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ OBJS="path_to_obj path_to_another_obj ..." make run
# Renders the demo shown below
OBJS="objs/uv_sphere.obj objs/torus.obj objs/star_destroyer.obj \
objs/pyramid.obj objs/cube.obj objs/blender_monkey.obj objs/arwing.obj" make run
# Renders the lambda cube below (uses a debug feature set at compile-time)
OBJS="objs/lambdacube.obj" make run
```

![demo](media/demo.gif)

![lambdacube](media/lambdacube.gif)

## Writeups

| Checkpoint | Summary |
Expand Down
14 changes: 13 additions & 1 deletion bin/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,29 @@ let input_dispatch key =
print_int (int_of_char key);
print_endline ""

let framecount = ref 0

let rotate_mode = false

let draw_scene () =
display_mode false;
clear_window black;
(* Draw each mesh at their offset *)
for i = 0 to List.length !to_draw - 1 do
if rotate_mode then (
update_euler 0 (0.125 *. Float.sin (0.025 *. float_of_int !framecount));
update_euler 1 0.25;
update_euler 2 (0.125 *. Float.cos (0.025 *. float_of_int !framecount))
);

let mesh, offset = List.nth !to_draw i in
draw_mesh mesh !euler (v3_add !translation offset)
done;
let input = wait_next_event [ Poll ] in
synchronize ();
display_mode true;
if input.keypressed then input_dispatch (read_key ())
if input.keypressed then input_dispatch (read_key ());
framecount := !framecount + 1

let rec main_loop () =
draw_scene ();
Expand All @@ -110,4 +121,5 @@ let start meshes =
to_draw := List.combine meshes mesh_positions;
auto_synchronize false;
open_graph (" " ^ string_of_int viewportw ^ "x" ^ string_of_int viewporth);
set_window_title "ZENITH";
main_loop ()
2 changes: 1 addition & 1 deletion lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let fov = 45.0
let aspect_ratio = 1.
let z_near = 0.1
let z_far = 50.
let rotation_incr = 7.5
let rotation_incr = 1.0
let translation_incr = 0.5
let draw_verts = false
let vert_radius = 3
Expand Down
Binary file added media/lambdacube.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added objs/lambdacube.blend
Binary file not shown.
82 changes: 82 additions & 0 deletions objs/lambdacube.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Blender MTL File: 'lambdacube.blend'
# Material Count: 8

newmtl Blue
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.000000 0.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl GB
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Gray
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.375081 0.375081 0.375081
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Green
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.000000 1.000000 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl RB
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 0.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl RG
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Red
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 0.000000 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl White
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
Loading

0 comments on commit e2d6d65

Please sign in to comment.