|
@@ -1,6 +1,6 @@
|
|
|
(cl:defpackage :ocm.nvg
|
|
(cl:defpackage :ocm.nvg
|
|
|
- (:use :cl :cffi-c-ref :alexandria)
|
|
|
|
|
- (:export run))
|
|
|
|
|
|
|
+ (:use :cl :cffi-c-ref :alexandria)
|
|
|
|
|
+ (:export run))
|
|
|
(cl:in-package :ocm.nvg)
|
|
(cl:in-package :ocm.nvg)
|
|
|
|
|
|
|
|
(defun aget (alist key)
|
|
(defun aget (alist key)
|
|
@@ -95,18 +95,31 @@
|
|
|
(nil "highway" "secondary")))
|
|
(nil "highway" "secondary")))
|
|
|
(push (osm-fix obj) *objects*)))
|
|
(push (osm-fix obj) *objects*)))
|
|
|
|
|
|
|
|
-(defparameter +granularity+ (expt 10 8))
|
|
|
|
|
|
|
+(defparameter +granularity+ (expt 10 9))
|
|
|
|
|
+;; Web mercator
|
|
|
(defun node-x (node)
|
|
(defun node-x (node)
|
|
|
- (float (/ (ocm.osm::node-lon node) +granularity+)))
|
|
|
|
|
|
|
+ (float
|
|
|
|
|
+ (* (expt 2 *zoom*)
|
|
|
|
|
+ (/ (+ (/ (ocm.osm::node-lon node) +granularity+) 180) 360))))
|
|
|
(defun node-y (node)
|
|
(defun node-y (node)
|
|
|
- (float (- (/ (ocm.osm::node-lat node) +granularity+))))
|
|
|
|
|
|
|
+ (let* ((lat (/ (ocm.osm::node-lat node) +granularity+))
|
|
|
|
|
+ (lat-rad (/ (* lat pi) 180)))
|
|
|
|
|
+ (float
|
|
|
|
|
+ (* (expt 2 (1- *zoom*))
|
|
|
|
|
+ (- 1 (/ (log (+ (tan lat-rad) (/ 1 (cos lat-rad))))
|
|
|
|
|
+ pi))))))
|
|
|
|
|
+
|
|
|
|
|
+(defun offset-x (node)
|
|
|
|
|
+ (coerce (- (node-x node) (node-x *corner*)) 'single-float))
|
|
|
|
|
+(defun offset-y (node)
|
|
|
|
|
+ (coerce (- (node-y node) (node-y *corner*)) 'single-float))
|
|
|
|
|
|
|
|
(defun render-path (nodes)
|
|
(defun render-path (nodes)
|
|
|
(%nvg:begin-path *context*)
|
|
(%nvg:begin-path *context*)
|
|
|
(let ((start (car nodes)))
|
|
(let ((start (car nodes)))
|
|
|
- (%nvg:move-to *context* (node-x start) (node-y start))
|
|
|
|
|
|
|
+ (%nvg:move-to *context* (offset-x start) (offset-y start))
|
|
|
(loop for node in (cdr nodes)
|
|
(loop for node in (cdr nodes)
|
|
|
- do (%nvg:line-to *context* (node-x node) (node-y node)))))
|
|
|
|
|
|
|
+ do (%nvg:line-to *context* (offset-x node) (offset-y node)))))
|
|
|
|
|
|
|
|
(defparameter +highway-color+ '(150 100 0 255))
|
|
(defparameter +highway-color+ '(150 100 0 255))
|
|
|
(defparameter +highway-primary-color+ '(150 30 0 255))
|
|
(defparameter +highway-primary-color+ '(150 30 0 255))
|
|
@@ -212,17 +225,31 @@
|
|
|
|
|
|
|
|
(%nvg:end-frame *context*))
|
|
(%nvg:end-frame *context*))
|
|
|
|
|
|
|
|
|
|
+(defun render-test ()
|
|
|
|
|
+ (%nvg:begin-path *context*)
|
|
|
|
|
+ (%nvg:rect *context* 100f0 100f0 120f0 30f0)
|
|
|
|
|
+ (%nvg:circle *context* 120f0 120f0 5f0)
|
|
|
|
|
+ (%nvg:path-winding *context* (cffi:foreign-bitfield-value '%nvg:solidity :hole))
|
|
|
|
|
+
|
|
|
|
|
+ (c-with ((color %nvg:color))
|
|
|
|
|
+ (%nvg:fill-color *context* (%nvg:rgba (color &)
|
|
|
|
|
+ (round (* 127.5 (+ 1 (sin (%glfw:get-timer-value)))))
|
|
|
|
|
+ 192 192 255)))
|
|
|
|
|
+ (%nvg:fill *context*)
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+(defparameter +translate-step+ 1)
|
|
|
|
|
+(defparameter +scale-step+ 0.3)
|
|
|
(defvar *pressed-keys* nil)
|
|
(defvar *pressed-keys* nil)
|
|
|
(defun process-keys ()
|
|
(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+ 80f0)
|
|
|
|
|
-(defparameter +scale-step+ 0.3)
|
|
|
|
|
|
|
+ (let ((step (* +translate-step+ (expt 2 *zoom*))))
|
|
|
|
|
+ (when (member %glfw:+key-left+ *pressed-keys*) (decf (ocm.osm::node-lon *corner*) step))
|
|
|
|
|
+ (when (member %glfw:+key-right+ *pressed-keys*) (incf (ocm.osm::node-lon *corner*) step))
|
|
|
|
|
+ (when (member %glfw:+key-up+ *pressed-keys*) (decf (ocm.osm::node-lat *corner*) step))
|
|
|
|
|
+ (when (member %glfw:+key-down+ *pressed-keys*) (incf (ocm.osm::node-lat *corner*) step))
|
|
|
|
|
+ (when (member %glfw:+key-minus+ *pressed-keys*) (decf *zoom* +scale-step+))
|
|
|
|
|
+ (when (member %glfw:+key-equal+ *pressed-keys*) (incf *zoom* +scale-step+))))
|
|
|
|
|
+
|
|
|
(glfw:define-key-callback on-keys (window key scancode action mod-keys)
|
|
(glfw:define-key-callback on-keys (window key scancode action mod-keys)
|
|
|
(declare (ignorable window key scancode action mod-keys))
|
|
(declare (ignorable window key scancode action mod-keys))
|
|
|
(format t "KEY: ~{~A ~}~%" (list key scancode action mod-keys))
|
|
(format t "KEY: ~{~A ~}~%" (list key scancode action mod-keys))
|
|
@@ -232,13 +259,7 @@
|
|
|
((or
|
|
((or
|
|
|
(eql key %glfw:+key-escape+)
|
|
(eql key %glfw:+key-escape+)
|
|
|
(eql key %glfw:+key-q+))
|
|
(eql key %glfw:+key-q+))
|
|
|
- (%glfw:set-window-should-close window %glfw:+true+))
|
|
|
|
|
- ((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+))))
|
|
|
|
|
|
|
+ (%glfw:set-window-should-close window %glfw:+true+))))
|
|
|
(when (eql action %glfw:+release+)
|
|
(when (eql action %glfw:+release+)
|
|
|
(setf *pressed-keys* (delete key *pressed-keys*)))
|
|
(setf *pressed-keys* (delete key *pressed-keys*)))
|
|
|
(print (list *scale* *pos-x* *pos-y*)))
|
|
(print (list *scale* *pos-x* *pos-y*)))
|
|
@@ -302,9 +323,15 @@
|
|
|
(gl:viewport 0 0 *frame-width* *frame-height*)
|
|
(gl:viewport 0 0 *frame-width* *frame-height*)
|
|
|
|
|
|
|
|
;; reset
|
|
;; reset
|
|
|
- (setf *scale* 540f0
|
|
|
|
|
- *pos-x* -162910.0
|
|
|
|
|
- *pos-y* 324540.0)
|
|
|
|
|
|
|
+ ;; (setf *scale* 540f0
|
|
|
|
|
+ ;; *pos-x* -162910.0
|
|
|
|
|
+ ;; *pos-y* 324540.0)
|
|
|
|
|
+ (setf *zoom* 20
|
|
|
|
|
+ *corner* (ocm.osm::make-node :LAT 59931756500 :LON 30293207600))
|
|
|
|
|
+
|
|
|
|
|
+ (setf *scale* 1f0
|
|
|
|
|
+ *pos-x* 0.0
|
|
|
|
|
+ *pos-y* 0.0)
|
|
|
|
|
|
|
|
;; Creating NanoVG context
|
|
;; Creating NanoVG context
|
|
|
(let ((*context* (nvg:make-context)))
|
|
(let ((*context* (nvg:make-context)))
|