-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk.rkt
37 lines (31 loc) · 1.22 KB
/
chunk.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#lang racket/base
(require glm
voxel-engine/block
voxel-engine/gl-drawable)
(provide (all-defined-out))
(struct chunk (layers)
#:transparent
#:name vx:chunk
#:constructor-name make-chunk)
(define (chunk make-block #:width width #:height [height #f] #:depth [depth #f])
(make-chunk (for/list ([i (in-range width)])
(for/list ([j (in-range (or height width))])
(for/list ([k (in-range (or depth width))])
(make-block i j k))))))
(define (draw-chunk C cube projection view position #:size [size 1])
(define-values (num-layers num-rows num-columns)
(values (length (chunk-layers C))
(length (car (chunk-layers C)))
(length (caar (chunk-layers C)))))
(for ([layer (in-list (chunk-layers C))]
[i (in-naturals)])
(for ([row (in-list layer)]
[j (in-naturals)])
(for ([B (in-list row)]
[k (in-naturals)])
(define position* (+ position (vec3 i j k)))
(define model (* (translate (mat4) position*)
(scale (mat4) (* size (vec3 1)))))
(draw-block B cube (* projection (transpose view) model))))))
(define (draw-block B cube mvp)
(gl-draw cube mvp))