;;;; -*- mode:lisp;coding:utf-8 -*-
;;;;**************************************************************************
;;;;FILE:               radar-map.lisp
;;;;LANGUAGE:           Common-Lisp
;;;;SYSTEM:             Common-Lisp
;;;;USER-INTERFACE:     NONE
;;;;DESCRIPTION
;;;;
;;;;    This program draws in a glut window a radar map
;;;;    including airport runways and multiplayer planes.
;;;;
;;;;AUTHORS
;;;;    <PJB> Pascal J. Bourguignon <pjb@ogamita.com>
;;;;MODIFICATIONS
;;;;    2011-04-10 <PJB> Created.
;;;;BUGS
;;;;LEGAL
;;;;    GPL
;;;;
;;;;    Copyright Pascal J. Bourguignon 2011 - 2011
;;;;
;;;;    This program is free software; you can redistribute it and/or
;;;;    modify it under the terms of the GNU General Public License
;;;;    as published by the Free Software Foundation; either version
;;;;    2 of the License, or (at your option) any later version.
;;;;
;;;;    This program is distributed in the hope that it will be
;;;;    useful, but WITHOUT ANY WARRANTY; without even the implied
;;;;    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;;;    PURPOSE.  See the GNU General Public License for more details.
;;;;
;;;;    You should have received a copy of the GNU General Public
;;;;    License along with this program; if not, write to the Free
;;;;    Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;;    Boston, MA 02111-1307 USA
;;;;**************************************************************************


(defclass radar-window (glut:window)
  ()
  (:default-initargs :width 640 :height 480 :title "radar map"
                     :mode '(:single :rgb)))


(defmethod glut:display-window :before ((w radar-window))
  (gl:clear-color 0 0 0 0)
  (gl:shade-model :flat))


(defmethod glut:display ((w radar-window))
  (gl:clear :color-buffer)
  (gl:color 0.1 1.0 0.1)
  (let* ((margin   20)
         (width    (glut:width  w))
         (height   (glut:height w))
         (side/2   (/ (- (min width height) margin margin) 2))
         (center-x (/ width  2))
         (center-y (/ height 2))
         (left     (- center-x side/2))
         (bottom   (- center-y side/2))
         (right    (+ center-x side/2))
         (top      (+ center-y side/2)))
    (when (plusp side/2)

      ;; centered square frame:
      (gl:rect  left  bottom right (1+ bottom))
      (gl:rect  left  top    right (1- top))
      (gl:rect  left  bottom (1+ left)  top)
      (gl:rect  right bottom (1- right) top)
      ;; center cross
      (gl:rect (- center-x 10)     (1- center-y)
               (+ center-x 10)     (1+ center-y))
      (gl:rect (1- center-x)       (- center-y 10)
               (1+ center-x)       (+ center-y 10))

      (cl-glut:solid-sphere 100 80 80)

      ))
  (gl:flush))


(defmethod glut:reshape ((w radar-window) width height)
  (gl:viewport 0 0 width height)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (glu:ortho-2d 0 width 0 height))


(defmethod glut:keyboard ((w radar-window) key x y)
  (declare (ignore x y))
  (case key
    ((#\Space #\Return)
     (glut:post-redisplay))
    ((#\Esc #\q #\Q)
     (glut:destroy-current-window))))


(defun radar-map ()
  (glut:display-window (make-instance 'radar-window)))

;;;; THE END ;;;;
ViewGit