|
|
@@ -34,11 +34,21 @@
|
|
|
(defvar *pos-x* 0f0)
|
|
|
(defvar *pos-y* 0f0)
|
|
|
|
|
|
+(defvar *objects* nil "List of OSM referenced objects to render")
|
|
|
+
|
|
|
+(defun load-test-objects ()
|
|
|
+ (setf *objects* nil)
|
|
|
+ (ocm.osm::with-related (obj "spb.osm.pbf" '(
|
|
|
+ (nil "natural" "water")
|
|
|
+ (nil "natural" "wood")
|
|
|
+ (nil "natural" "scrub")))
|
|
|
+ (push obj *objects*)))
|
|
|
+
|
|
|
(defparameter +granularity+ (expt 10 8))
|
|
|
(defun node-x (node)
|
|
|
- (float (/ (ocm.osm::node-lat node) +granularity+)))
|
|
|
-(defun node-y (node)
|
|
|
(float (/ (ocm.osm::node-lon node) +granularity+)))
|
|
|
+(defun node-y (node)
|
|
|
+ (float (- (/ (ocm.osm::node-lat node) +granularity+))))
|
|
|
|
|
|
(defun render-path (nodes)
|
|
|
(%nvg:begin-path *context*)
|
|
|
@@ -134,46 +144,49 @@
|
|
|
|
|
|
(defun render ()
|
|
|
(%nvg:begin-frame *context* *window-width* *window-height* *pixel-ratio*)
|
|
|
-
|
|
|
(%nvg:transform *context* *scale* 0f0 0f0 *scale* *pos-x* *pos-y*)
|
|
|
|
|
|
- (render-objects ocm.osm::+water+)
|
|
|
+ (render-objects *objects*)
|
|
|
|
|
|
- (%nvg:begin-path *context*)
|
|
|
- (%nvg:rect *context* 0f0 0f0 120f0 30f0)
|
|
|
- (c-with ((color %nvg:color))
|
|
|
- (%nvg:fill-color *context* (%nvg:rgba (color &)
|
|
|
- (round (* 127.5 (+ 1 (sin (* 2 (%glfw:get-time))))))
|
|
|
- 192 192 255)))
|
|
|
- (%nvg:fill *context*)
|
|
|
-
|
|
|
- (%nvg:end-frame *context*)
|
|
|
- )
|
|
|
+ (%nvg:end-frame *context*))
|
|
|
+
|
|
|
+(defun process-keys ()
|
|
|
+ (when (member %glfw:+key-left+ *pressed-keys*) (incf *pos-x* +translate-step+))
|
|
|
+ (when (member %glfw:+key-right+ *pressed-keys*) (decf *pos-x* +translate-step+))
|
|
|
+ (when (member %glfw:+key-up+ *pressed-keys*) (incf *pos-y* +translate-step+))
|
|
|
+ (when (member %glfw:+key-down+ *pressed-keys*) (decf *pos-y* +translate-step+))
|
|
|
+ (when (member %glfw:+key-minus+ *pressed-keys*) (decf *scale* +scale-step+))
|
|
|
+ (when (member %glfw:+key-equal+ *pressed-keys*) (incf *scale* +scale-step+)))
|
|
|
|
|
|
-(defparameter +translate-step+ 10f0)
|
|
|
-(defparameter +scale-step+ 0.1)
|
|
|
+(defparameter +translate-step+ 80f0)
|
|
|
+(defparameter +scale-step+ 0.3)
|
|
|
+(defvar *pressed-keys* nil)
|
|
|
(glfw:define-key-callback on-keys (window key scancode action mod-keys)
|
|
|
(declare (ignorable window key scancode action mod-keys))
|
|
|
(format t "KEY: ~{~A ~}~%" (list key scancode action mod-keys))
|
|
|
(when (eql action %glfw:+press+)
|
|
|
+ (pushnew key *pressed-keys*)
|
|
|
(cond
|
|
|
((or
|
|
|
(eql key %glfw:+key-escape+)
|
|
|
(eql key %glfw:+key-q+))
|
|
|
(%glfw:set-window-should-close window %glfw:+true+))
|
|
|
- ((eql key %glfw:+key-left+) (decf *pos-x* +translate-step+))
|
|
|
- ((eql key %glfw:+key-right+) (incf *pos-x* +translate-step+))
|
|
|
- ((eql key %glfw:+key-up+) (decf *pos-y* +translate-step+))
|
|
|
- ((eql key %glfw:+key-down+) (incf *pos-y* +translate-step+))
|
|
|
+ ((eql key %glfw:+key-left+) (incf *pos-x* +translate-step+))
|
|
|
+ ((eql key %glfw:+key-right+) (decf *pos-x* +translate-step+))
|
|
|
+ ((eql key %glfw:+key-up+) (incf *pos-y* +translate-step+))
|
|
|
+ ((eql key %glfw:+key-down+) (decf *pos-y* +translate-step+))
|
|
|
((eql key %glfw:+key-minus+) (decf *scale* +scale-step+))
|
|
|
((eql key %glfw:+key-equal+) (incf *scale* +scale-step+))))
|
|
|
+ (when (eql action %glfw:+release+)
|
|
|
+ (setf *pressed-keys* (delete key *pressed-keys*)))
|
|
|
(print (list *scale* *pos-x* *pos-y*)))
|
|
|
|
|
|
(glfw:define-framebuffer-size-callback on-fb-size (window width height)
|
|
|
(declare (ignorable window))
|
|
|
(setf *frame-width* (float width)
|
|
|
*frame-height* (float height)
|
|
|
- *pixel-ratio* (/ *frame-width* *window-width*)))
|
|
|
+ *pixel-ratio* (/ *frame-width* *window-width*))
|
|
|
+ (gl:viewport 0 0 *frame-width* *frame-height*))
|
|
|
|
|
|
(glfw:define-window-size-callback on-win-size (window width height)
|
|
|
(declare (ignorable window))
|
|
|
@@ -181,7 +194,10 @@
|
|
|
*window-height* (float height)
|
|
|
*pixel-ratio* (/ *frame-width* *window-width*)))
|
|
|
|
|
|
-(Defun create-window ()
|
|
|
+(glfw::define-error-callback on-error (err desc)
|
|
|
+ (format *error-output* "GLFW error ~A: ~A~%" err desc))
|
|
|
+
|
|
|
+(defun create-window ()
|
|
|
(if (uiop:featurep :bodge-gl2)
|
|
|
(glfw:with-window-hints ((%glfw:+context-version-major+ 2)
|
|
|
(%glfw:+context-version-minor+ 1)
|
|
|
@@ -199,6 +215,7 @@
|
|
|
(defun main ()
|
|
|
;; Initializing window and OpenGL context
|
|
|
(glfw:with-init ()
|
|
|
+ (%glfw:set-error-callback (cffi:callback on-error))
|
|
|
(c-let ((window %glfw:window :from (create-window))
|
|
|
(width :int :alloc t)
|
|
|
(height :int :alloc t))
|
|
|
@@ -220,11 +237,12 @@
|
|
|
(setf *window-width* (float width)
|
|
|
*window-height* (float height)
|
|
|
*pixel-ratio* (/ *frame-width* *window-width*))
|
|
|
+ (gl:viewport 0 0 *frame-width* *frame-height*)
|
|
|
|
|
|
;; reset
|
|
|
- (setf *scale* 1f0
|
|
|
- *pos-x* 0f0
|
|
|
- *pos-y* 0f0)
|
|
|
+ (setf *scale* 300f0
|
|
|
+ *pos-x* -90270.0
|
|
|
+ *pos-y* 180380.0)
|
|
|
|
|
|
;; Creating NanoVG context
|
|
|
(let ((*context* (nvg:make-context)))
|
|
|
@@ -233,7 +251,10 @@
|
|
|
(gl:clear-color 1f0 1f0 1f0 1f0)
|
|
|
(gl:clear :color-buffer-bit :depth-buffer-bit :stencil-buffer-bit)
|
|
|
|
|
|
- ;; Actually drawing into nanovg context and onto display
|
|
|
+ ;; Step
|
|
|
+ (process-keys)
|
|
|
+
|
|
|
+ ;; Actually drawing into nanovg context and onto display
|
|
|
(render)
|
|
|
|
|
|
(%glfw:swap-buffers (window &))
|