;; -*- Mode: LISP; Syntax: Common-Lisp; Package: (USER); -*-
;***************************************************************
;*
;*  SOLAR SYSTEM GRAPHICS BASE
;*
;*  Kris Thorisson 
;*  HISTORY: Begin 6/28 '95
;*
;***************************************************************
;*

;-------- CLASSES  --------

(defclass planetoid (object)
  (
   (name  :accessor name  :initarg :name)
   (pos   :accessor pos   :initarg :pos)
   (color :accessor color :initarg :color)
   (size  :accessor size  :initarg :size)
   (tilt  :accessor tilt  :initarg :tilt)
   (id    :accessor id    :initarg :id)                ;nucleus id
   (vis-id :accessor vis-id :initarg :vis-id)          ;visual object id
   (vis-spd   :accessor vis-spd   :initarg :vis-spd)   ;self-rotation
   (ring  :accessor ring  :initarg :ring :initform nil)
   (y-n-tilt :accessor y-n-tilt :initarg :y-n-tilt :initform nil)
   (far-out  :accessor far-out  :initarg :far-out :initform nil)
   (clos-up :accessor clos-up :initarg :clos-up :initform nil)
   ))

(defclass planet (planetoid)
  (
   (moons :accessor moons :initarg :moons :initform nil)
   ))

(defclass moon   (planetoid) 
  (
   (slant :accessor slant :initarg :slant)    ;slant of orb-object
   (orb-id :accessor orb-id :initarg :orb-id) ;id of rotating object
;  (orb-anim :accessor orb-anim :initarg :orb-anim)  ;animation of rotating object
   (orb-spd :accessor orb-spd :initarg :orb-spd)
   ))

(defvar *planets* nil)

;-------- SOCKET --------

(defvar *graphics-host* "spleen")
(defvar old-graphics-port# 15001)
(defvar graphics-port# 16001)
(setf   graphics-port# 16001)
(defvar graphics-stream nil)

;(setf graphics-port# 15006)
;(setf graphics-port# 15007)

(defun open-Graphics ()
  (let ((port graphics-port#)
        (host *graphics-host*))
    (terpri)(princ "Trying ")(princ host)(princ " at ")(princ port)
    (if
        (setf graphics-stream
              (comm:open-tcp-stream host port :direction :io))
        (progn 
          (setf (graph-status *socket-obj2*) T)
          (terpri)(princ "Connected to ")(princ host)
          (terpri) (princ "Loading object library...")
          (sleep 2)
          (load-graphics init)
          (princ "done.")
          )
      (print " Error (open-Graphics): Connection did not open!"))
    (setf (graph-stream *socket-obj2*) graphics-stream)
    graphics-stream
    ))

(setf *print-msgs* 0)

(defun Graph-cmnd (command)
  (let ((return nil))
    (if (streamp graphics-stream)
        (progn
          (write-line command graphics-stream)
          (if (listen graphics-stream)
	      (loop while (listen graphics-stream)
		    do (push (read graphics-stream) return)))
          )
      (if (< *print-msgs* 20)
          (progn
            (setf *print-msgs* (1+ *print-msgs*))
            (print "No reply received for cmnd: ")
            (princ command))
        ))
    (if (eq (length return) 1)
        (first return)
      (reverse return))
    ))

(defun g-cmnd (cmnd)
  (graph-cmnd cmnd))

(defun close-graphics ()
  (g-cmnd "QUIT")
  (close graphics-stream)
  (setf (graph-stream *socket-obj2*) graphics-stream)
  (setf (graph-status *socket-obj2*) nil)
  )

;-------- SOLAR SYSTEM --------


(defvar curr-ref-obj 1) ;the object the camera is pointing at at any time  

(defun create-solar-system ()
  (make-solar-system))

(defun make-solar-system ()
  (unless (streamp graphics-stream)
    (open-graphics))
;  (unless (symbolp saturn)
;    (g-cmnd "DELETE_ALL")
;    (sleep 3))
  (setf *planets* nil)
  (dolist (planet solar-system)
    (make-planets planet))
  (dolist (planet *planets*)
    (animate-obj planet))
  (setf curr-ref-obj 1)
  (make-rings saturn)
  (start-clock)
  (go-home)
  (set-up)
  (setf *CURRENT-PLANET* earth)
  )

(defun make-planets (planet-lst)
  (dolist (planet planet-lst)
    (setf P (pop planet))
    (let* ((pos    (pop planet))
           (slant  (pop planet))
           (color  (pop planet))
           (size   (pop planet))
           (speed  (pop planet))
           (y-n-tilt (pop planet))
           (shape    (pop planet))
           (far-out  (pop planet))
           (close-up (pop planet))
           (moons planet))       ;a list of the planet's moons
      (setf planetx (eval
                     `(setf ,P (make-instance 
                                'planet
			        :name    ',P
                                :ISA     'object
			        :color   ',color
			        :size    ',size
			        :tilt    ',slant
                                :y-n-tilt ',y-n-tilt
                                :far-out ',far-out
                                :clos-up ',close-up
			        :vis-spd ',speed
                                :words    (list ',P)
			        :pos     ',pos))))
      (setf (id planetx)(g-cmnd "SET_CLASS nil.geom")) ;virtual planet
      (setf (vis-id planetx)  ;visual planet
            (attach (set-class shape) (id planetx)))
      (set-color (id planetx) '(-1 -1 -1))               ;make nucleus transparent
      (set-color (vis-id planetx)(color planetx))
      (set-scale (vis-id planetx)(size planetx))
      (if (first moons)
          (setf (moons planetx) (make-moons moons (id planetx))))
      (if y-n-tilt
          (rotate (vis-id planetx) '(0 1 0) y-n-tilt))
    ;wait until last to set location of each planet
      (set-location planetx (pos planetx))
      (push planetx *planets*)
      )))

(defun make-moons (moons planet-id)
  "Returns a list of moon objects."
  (let ((moonlist nil))
    (dolist (moon moons)
      (let* ((name  (pop moon))
             (pos   (pop moon))
             (slant (pop moon))
             (color (pop moon))
             (size  (pop moon))
             (speed (pop moon))
             (orb-spd (pop moon)))
        (setf moonx (eval 
                     `(setf ,name (make-instance 
                                   'moon 
				   :name    ',name
				   :color   ',color
				   :size    ',size
				   :slant   ',slant
				   :vis-spd ',speed
                                   :orb-spd ',orb-spd
				   :pos     ',pos))))
        (setf (orb-id moonx) 
              (attach (set-class "nil.geom") planet-id))
        (set-color (orb-id moonx) '(-1 -1 -1))     ;make orbit obj transparent
        (setf (id moonx) 
              (attach (set-class "nil.geom") (orb-id moonx)))
        (setf (vis-id moonx)
              (attach (set-class "sphere2")(id moonx)))
        (set-location (id moonx) (pos moonx)) 
        (set-color (vis-id moonx) (color moonx))
        (set-scale (vis-id moonx) (size moonx))
	(push moonx moonlist)
	))
    moonlist)
  )

(defun make-rings (planet)
  (let ((ring (g-cmnd "SET_CLASS torus.geom")))
    (rotate ring '(1 0 0) 90)
    (if (y-n-tilt planet)
        (rotate ring '(0 1 0) (y-n-tilt planet)))
    (set-scale ring '(4.8 0.6 4.8))
    (set-location ring (pos planet))
    (setf (ring planet) (attach ring (vis-id planet)))
    (set-color (ring planet) (color planet))
    ))

(defvar star-list nil)

(defun make-stars (stars)
  (let ((num nil))
;    (dolist (star star-list)
;      (del star))
    (setf star-list nil)
    (dolist (star stars)
      (print (pop star))
      (push (setf num (g-cmnd "SET_CLASS cube")) star-list)
      (set-location num (pop star))
      (set-scale num (pop star))
      (set-color num '(1 1 1))
      )
    ))

;------------- GRAPHIC COMMANDS ----------------
;--- mverse ---

(defun rm-wl ()
  (g-cmnd "RM_WL 0"))

(defun get-wl ()
  (print (g-cmnd "GET_WL")))

(defun delete-all ()
  (rm-wl)
  (sleep 0.5) ;just in case.
  (g-cmnd "DELETE_ALL"))

(defmethod del ((obj planetoid))
  (g-cmnd (format nil "DELETE ~A" (id obj))))

(defmethod del ((obj number))
  (g-cmnd (format nil "DELETE ~A" obj)))

(defun start-clock ()
  (g-cmnd (format nil "START_CLOCK")))

(defun stop-clock ()
  (g-cmnd (format nil "STOP_CLOCK")))

(defun read-clock ()
  (g-cmnd (format nil "GET_TIME")))

(defun get-clock ()  (read-clock))

(defun set-clock (time) (set-time time))

(defmethod set-time (time)
  (g-cmnd (format nil "SET_TIME ~A" time)))

(defun set-class (name)
  (g-cmnd (format nil "SET_CLASS ~A" name)))

(defmethod set-location ((plan planet) loc)
  (g-cmnd (format nil "SET_LOCATION~{ ~S~} ~A" loc (id plan)))
    (setf (pos plan) loc))

(defmethod set-location ((moon moon) loc)
  (g-cmnd (format nil "SET_LOCATION~{ ~S~} ~A" loc (id moon)))
  (setf (pos moon) loc))

(defmethod set-location (id loc)
  (g-cmnd (format nil "SET_LOCATION ~{ ~S~} ~A" loc id)))

(defmethod rotate (id quatern amount)
  (g-cmnd (format nil "ROTATE~{ ~S~} ~A ~A" quatern amount id)))

(defmethod set-scale (id (scale number))
  (setf scale (list scale scale scale))
  (g-cmnd (format nil "SET_SCALE~{ ~S~} ~A" scale id)))

(defmethod set-scale (id (scale list))
  (g-cmnd (format nil "SET_SCALE~{ ~S~} ~A" scale id)))

(defmethod set-scale ((planet planet) (scale list))
  (g-cmnd (format nil "SET_SCALE~{ ~S~} ~A" scale (id planet))))

(defmethod set-orientation (id orient)
  (g-cmnd (format nil "SET_ORIENTATION~{ ~S~} ~A" orient id)))

(defmethod get-location (id)
  (g-cmnd (format nil "GET_LOCATION ~A" id)))

(defmethod get-location ((planet planet))
  (get-location (id planet)))

(defmethod set-eye (x &optional y z)
  (g-cmnd (format nil "SET_EYE ~A ~A ~A" x y z)))

(defmethod set-eye ((xyz list) &optional foo1 foo2)
  (g-cmnd (format nil "SET_EYE ~A ~A ~A" (first xyz) (second xyz) (third xyz))))

(defmethod get-graphics-time ()
  (let ((tm (g-cmnd "GET_TIME")))
    (if (eq 1 tm) (get-graphics-time)
      tm)
    ))

(defmethod set-color (planet-id color)
  (g-cmnd (format nil "SET_COLOR~{ ~S~} ~A" color planet-id)))

(defun set-class (obj-name)
  (g-cmnd (format nil "SET_CLASS ~A" obj-name)))

(defmethod orbit ((object planet))
  (g-cmnd (format nil "ORBIT~{ ~S~}" (pos object))))

(defmethod orbit ((xyz list))
  (g-cmnd (format nil "ORBIT~{ ~S~}" xyz)))

(defun detach (child)
  (g-cmnd (format nil "ATTACH ~A" child)))

(defun attach (child-id parent-id)
  (g-cmnd (format nil "ATTACH ~A ~A" parent-id child-id)))

(defmethod animate (id ref-obj anim speed)
  (g-cmnd 
   (format nil "ANIMATE ~A 1 ~A 1 !0 0 0 ~{ ~S~} ~A 0" 
	   id ref-obj anim speed)))

(defvar anim-num 0)

(defmethod animate-cam (start ref-obj-id pos ref-pos anim-speed)
;  (setf anim-num (1+ anim-num))
  "To get to mars, set ref-obj-id 0,
   pos as (pos-mod (pos mars)(far-out mars)) as ref-obj-id,
   ref-pos as (pos mars)."
  (g-cmnd 
   (format nil "ANIMATE cam ~A ~A 1 !~{ ~S~} ~{ ~S~} 0 ~A" 
	   start ref-obj-id pos ref-pos anim-speed)))

(defun set-up () (g-cmnd "SET_UP 0 0 1"))

(defun lookat (id)
  (g-cmnd (format nil "LOOKAT ~A" id)))

(defun find-objs (coord)  ;coords: left->right, top->bottom ?
  (g-cmnd (format nil "SET_LOOK~{ ~S~}" coord)))

(defun get-eye ()
  (g-cmnd "GET_EYE"))

(defun reset-cam ()
  (g-cmnd "HOME"))

(defun get-next-obj ()
  (g-cmnd "GET_LOOK"))


;--- my own commands ---

(defun zoom (amount)
  (let* ((xyz (g-cmnd "GET_EYE"))
         (y (+ (second (g-cmnd "GET_EYE")) amount))
         (new-xyz (list (first xyz) y (third xyz))))
    (g-cmnd 
     (format nil "ANIMATE cam 1 ~A 1 !~{ ~S~} 0 0 0 0 100" curr-ref-obj new-xyz)))
  )

(defun load-graphics (package)
  (dolist (obj package)
    (dolist (cmnd obj)
      (g-cmnd cmnd)))
  T)

(defun exec-anim (anim)
  (dolist (obj anim)
    (dolist (cmnd obj)
      (g-cmnd cmnd))))

(defun reset-cam2 ()
  (g-cmnd "ANIMATE cam 0 0 1 !0 -50 0 0 0 0 0 30")
  (g-cmnd "ANIMATE cam 30 0 2 !0 -70 0 0 0 0 0 20")
  (go-home))

(defun one-cmnd-many-args (lst)
  (let ((cmnd (pop lst)))
    (dolist (arg lst)
      (g-cmnd (format "~A ~A" cmnd arg)))))

;(defun go-home ()
;  (g-cmnd "ANIMATE cam 0 0 2 !0 -70 0 0 0 0 0 30"))

(defun go-home ()
  (let* ((t1 150))
    (g-cmnd (format nil "ANIMATE cam 0 ~A 1 !100 400 50 0 0 0 0 ~A" (id mars) t1))
    (set-up)
    ))

#|
(defun anim-cam (pos ref dist start) ;dist=where to stop
  (let* ((loc pos)
         (x (+ 5 (first loc)))
         (y (second loc))
         (z (third loc))
         (new-y (+ y dist))
         (new-xyz (list x new-y z)))
;    (print new-y)
;    (if (> 0 new-y) (setf new-y (- (second loc) new-y)))
;    (print new-Y)
    (g-cmnd (format nil "ANIMATE cam ~A ~A 1 !~{ ~S~} 0 0 0 0 100" start ref new-xyz))
    ))
|#

(defun top-view ()
  (setf *zoom-in-flag* T)
  (let* ((planet *current-planet*)
         (id (id planet))
         (x  (first  (clos-up planet)))
         (y  (second (clos-up planet)))
	 (z  20))
    (anim-cam-2 (list x y z) '(0 0 0) id 0)
    ))

(defun side-view ()
  (setf *zoom-in-flag* T)
  (let* ((planet *current-planet*)
         (id (id planet))
         (x  (first  (clos-up planet)))
         (y  (second (clos-up planet)))
         (z  (third  (clos-up planet)))
         (new-xyz (list x y z)))
    (anim-cam-2 new-xyz '(0 0 0) id 0)
    ))

#|
(defmethod go-to ((planet planet))
  (let ((x (* 5 (size planet)))
        (y (* 4 (size planet)))
        (z 0))
    (if (> 0 (first (pos planet)))
        (setf x (* -1 x)))
    (if (> 0 (second (pos planet)))
        (setf y (* -1 y)))
    (print (list x y z))
    (anim-cam-2 (list x y z) (pos planet) (id planet) 0)))
|#

(defmethod go-to-2 ((planet planet))
  (let* ((t1 100)
         (t2 (+ t1 (get-graphics-time) 10))
         (loc (pos planet))
         (id  (id  planet)))
    (g-cmnd (format nil "ANIMATE cam 0 ~A 1 !100 100 50 0 0 0 0 ~A" (id mars) t1))
;    (go-to planet t2)
;    (anim-cam-2 '(0 4 0) loc id t2)
;    (g-cmnd 
;     (format nil "ANIMATE cam ~A ~A 1 !~{ ~S~} ~{ ~S~} 0 100" 
;                              t2 id '(0 0 0) loc t1))
    ))

(defmethod pos-mod (abs-pos mod)
  (let ((x (+ (first abs-pos)  (first mod)))
        (y (+ (second abs-pos) (second mod)))
        (z (+ (third abs-pos)  (third mod))))
    (list x y z)
    ))

(defmethod go-to ((planet planet))
  (setf *CURRENT-PLANET* planet)
  (if   *zoom-in-flag* (progn
                          (zoom-out)
                          (setf *zoom-in-flag* nil)))
  (let ((now 0)
        (start (get-clock))
        (dur1 30)
        (dur2 70)
        (ref-id 0))
    (g-cmnd (format nil "ANIMATE cam ~A ~A 1 !100 100 50 0 0 0 0 ~A" 
                    start (id mars) dur1))
    (loop while (< now (+ start dur1)) do
 ;         (main-loop)
          (setf now (get-clock)))
    (g-cmnd (format nil "ANIMATE cam ~A ~A 1 !~{ ~S~} ~{ ~S~} 0 ~A" 
                    (+ start dur1) ref-id
                    (pos-mod (pos planet)(far-out planet)) (pos planet) dur2))
    ))

;    (print 'now-)(print (setf now (get-graphics-time)))
;    (print start)
;    (print now)
;    (print (+ now start))
;    (loop while (< now (+ start duration)) do
;          (print now)
;          (main-loop)
;          (setf now (get-graphics-time))       
;          )
;    (if (or (Eq (Name Planet) 'Jupiter)
;            (Eq (Name Planet) 'Saturn))
;        (go-to1 planet)
;      (go-to-3 planet (+ start duration 20))
      )
;    (start-clock)
;    ))

(defmethod go-to-3 ((planet planet)(start integer))
  (let ((xyz (far-out planet)))              ; 5 = 5 000 000 Km
    (anim-cam-2 xyz '(0 0 0) (id planet) start)
    ))

(defun anim-cam-2 (xyz ref-pos ref-id start)
  (let ((loc xyz))
    (g-cmnd 
     (format nil "ANIMATE cam ~A ~A 99 !~{ ~S~} ~{ ~S~} 0 70" start ref-id loc ref-pos))
    ))                      ;start,ref-id,loc,  ref-pos ? duration

(defmethod go-to1 ((planet planet)) ;was rel-go-to
  (let ((xyz (far-out planet)))
    (if (moons planet)
        (setf y (* 2 (first (pos (furthest-out-moon planet)))))
      (setf y (* 3 (size planet))))
;    (reset-cam2)
    (anim-cam-2 xyz '(0 0 0) (id planet) (+ (get-graphics-time) 0))
    (set-up)
    ))

(defvar *zoom-in-flag* nil)

(defmethod zoom-in ()
  (set-up)
  (let* ((planet *CURRENT-PLANET*)
         (xyz (if (clos-up planet)
		  (clos-up planet)
		(list 0 (* 3 (size planet)) 5)))
	 )
    (print xyz)
    (anim-cam-2 xyz '(0 0 0) (id planet) 0)
    (setf *zoom-in-flag* T)
    ))

(defmethod zoom-out ()
  (set-up)
  (let* ((planet *CURRENT-PLANET*)
         (xyz (if (far-out planet)
                  (far-out planet)
                (if (moons planet)
                    (list 0 (* 2 (first (pos (furthest-out-moon planet)))) 2)
                  (list 0 (* 15 (size planet)) 0))))
	 )
    (anim-cam-2 xyz '(0 0 0) (id planet) 0)
    ))

;invalidated 3/7/96
;(defmethod close-up ((planet planet))
;  (anim-cam-2 '(0 0 0) (pos planet) (id planet) (+ 100 (get-graphics-time))))

(defmethod old-go-to ((planet planet))
  (let ((loc (pos planet))
       (id  (id planet))
        (dist nil))
    (if (moons planet)
        (setf dist (* 2 (first (pos (furthest-out-moon planet)))))
      (setf dist (* 2 (size planet))))
    (anim-cam loc id dist 0)
    ))

(defmethod go-to ((loc list))
  (anim-cam loc 0 0 0))

(defmethod go-to ((id number))
  (go-to (g-cmnd (format nil "GET_LOCATION ~A" id))))

(defmethod go-to-2 ((planet planet)) 
  "Go a fixed distance from a planet."
  (let ((loc (pos planet))
        (id  (id planet))
        (dist 1.4) ;equal to the size of Jupiter, 142 000 Km
        (dist2 0.8))
    (anim-cam loc id dist2 0)
    ))

(defmethod go-to ((moon moon))
;  (rm-wl)
;  (reset-moons-pos planet)
;  (set-location moon (pos moon))
  (anim-cam (pos moon) (id (find-parent moon)) (* 5 (size moon)) 0)
  )

(defmethod find-parent ((moon moon))
  (let ((parent nil))
    (dolist (obj *planets*)
      (dolist (comp-moon (moons obj))
        (if (eq (name moon) (name comp-moon))
          (setf parent obj))
        ))
    parent))

(defmethod animate-obj ((pla planet))
;  (rm-wl)
  (dolist (moon (moons pla))
    (g-cmnd (format nil "ANIMATE ~A 1 ~A 1 !0 0 0~{ ~S~} ~A 0" 
                    (orb-id moon) (orb-id moon) (slant moon) (orb-spd moon)))
    (g-cmnd (format nil "ANIMATE ~A 1 ~A 1 !0 0 0 0 0 0 ~A 0"
                    (vis-id moon) (vis-id moon) (vis-spd moon)))
    (g-cmnd (format nil "ANIMATE ~A 1 ~A 1 !0 0 0~{ ~S~} ~A 0"
                    (vis-id pla) (vis-id pla) (tilt pla) (vis-spd pla)))
    )
  )

(defun reset-moons-pos (planet)
  (dolist (moon (moons planet))
    (set-location moon (pos moon))))

(defun furthest-out-moon (planet)
  (let* ((moon-list (moons planet))
         (return (pop moon-list))
         moon2)
    (dolist (moon2 moon-list)
      (if (> (abs (first (pos moon2))) (abs (first (pos return))))
          (setf return moon2)))
    return))

(defmethod diff ((coord1 list)(coord2 list))
  (let* ((dx (- (first coord1)(first coord2)))
         (dy (- (second coord1)(second coord2)))
         (dz (- (third coord1)(third coord2))))
    (list dx dy dz)))

;-------- PLANETS --------

(setf init
      '(("LOAD_CLASSES primitives"
         "LOAD_CLASSES /ahi/src/okb2.0/objects/mverse/partbase_pieces"
         )))
#|
(setf planet-list
;TEMPLATE [planet [pos] [tilt] [color] size speed y-n-tilt?  far-out close-up
;                 [moon1 [pos] [tilt] [color] size speed orb-speed];
;		  etc...]
      '((sun (0 0 0) (0 0 0) (1 1 0) 2 1 nil  nil nil nil)
        (mercury (0 0 0) (0 0 0) (0.4 0.4 0.4) 0.4 1 nil nil nil nil) 
        (venus (0 0 0) (0 0 0) (0.6 0.6 0) 1.2 1 nil nil nil nil) 
        (earth (0 0 0) (0 0 1) (0 0.7 0.6) 1.2 1 nil  4 2
               (moon (1 1 1) (0 0 1) (0.8 0.8 0.8) 1 1 1))
        (mars (0 0 0) (0 0 0) (1 0 0) 0.6 1 nil  3 1
              (phobos (1 1 1) (0 0 0) (1 0.67 0.54) 1 1 1)
              (deimos (1 1 1) (0 0 0) (1 0.67 0.54) 1 1 1))
        (jupiter (0 0 0) (0 0 0) (1 0.8 0.5) 14 1  12 7
                 (Ganymede (1 0 0) (0 0 0) (0.73 0 0) 1 1 1)
                 (Callisto (2 0 0) (0 0 0) (0.8 0.54 0.14) 1 1 1)
                 (Io       (3 0 0) (0 0 0) (0.73 0 0) 1 1 1)
                 (Europa   (4 0 0) 0.8 0.54 0.14) 1 1 1)
        (saturn (0 0 0) (0 0 0) (1 1 1) 12 1  12 7
                (Titan   (1 0 0) (0 0 0) (1 0.8 0.46) 1 1 1)
                (Iapetus (2 0 0) (0 0 0) (0.86 0.7 0) 1 1 1)
                (Rhea    (3 0 0) (0 0 0) (0.57 0.49 0.62) 1 1 1)
                (Dione   (4 0 0) (0 0 0) (0.81 0.59 0.6)  1 1 1)
                (Phoebe  (5 0 0) (0 0 0) (0.57 0.49 0.62) 1 1 1))
        (uranus (0 0 0) (0 0 0) (0.3 0.3 1) 5 1  nil nil nil) 
        (neptune (0 0 0) (0 0 0) (0.4 0.4 1) 4.8 1  nil nil nil) 
        (pluto (0 0 0) (0 0 0) (1 1 1) 0.2 1  nil nil nil) 
        ))
|#

;All planets: size = real size x 10^5
;All moons  : size = real size x 10^4  (except where indicated)
;Sun        : size = real size x 10^5

;TEMPLATE [planet [pos] [tilt] [color] size speed y-n-tilt? shapename far-out-pos close-up-pos
;                 [moon1 [pos] [tilt] [color] size speed orb-speed];
;		  etc...]

(setf sun-data  
      '((sun (-100 -100 -100) (0 0 0) (1 1 0.75) 7 0.08 nil "sphere3" (0 50 0) (0 50 0)
             nil)
	))

(setf mercury-data 
      '((mercury (-50 -50 -50) (0 0 0) (0.57 0.49 0.62) 0.004 0.0069 nil "sphere2" (0 1.5 0) nil
                 nil)
	))

(setf venus-data  
      '((venus (0 0 0) (0 0 0) (1 1 0.6) 0.12 -0.00016 nil "sphere2" (0 3 0.2) (0 1.5 0.5)
               nil)
	))

(setf earth-data  ;normal moon size - 10x closer
      '((earth (30 20 0) (1 0 5) (0 0.82 0.77) 0.12 0.1 23 "sphere2" (0 5 1.2) (0 1.5 0.5)
               (moon (0.384 0 0) (0 0 0) (0.9 1 0.9) 0.03 0 0.88))
        ))

(setf mars-data  ;20x moon size - 10x closer
      '((mars (60 40 15) (0 0 0) (0.93 0.3 0.2) 0.06 0.1 nil "sphere2" (0 3 1) (0 1.4 0.5)
              (phobos (-0.09 0 0) (0 0 0) (1 0.67 0.54) 0.00446 0 7.5) ;really: 0.00223
              (deimos (0.23 0 0) (0 0 0) (1 0.67 0.54) 0.00252 0 1.9)) ;0.00126
        ))

(setf jupiter-data ;10x moon size - normal distance 
      '((jupiter (80 80 30) (0 0 0) (1 0.8 0.5) 1.42 0.27 nil "sphere3" (0 65 15) (0 23 6)
                 (Ganymede (10.0 0 0) (0 0 0) (0.80 0 0) 0.5262 0 0.33)       ;0.5262
                 (Callisto (18.8 0 0) (0 0 0) (0.82 0.56 0.18) 0.48 0 0.15)   ;0.48
                 (Io       (0 -4.2 0) (0 0 0) (0.8 0 0) 0.363 0 1.35)         ;0.363
                 (Europa   (-6.7 0 0) (0 0 0) (0.82 0.56 0.18) 0.3138 0 0.67))
        ))

(setf saturn-data  ;normal moon size - 10x closer  
      '((saturn (100 100 50) (1 0 3) (1 1 0.6) 1.2 0.24 18 "sphere3" (0 23 5) (0 13 3)
                (Titan   (1.221 0 0) (0 0 0) (1 0.8 0.46) 0.05 0 0.15)
                (Iapetus (-3.561 0 0) (0 0 0) (0.86 0.7 0) 0.014 0 0.03)
                (Rhea    (-0.0527 0 0) (0 0 0) (0.60 0.52 0.65) 0.015 0 0.53)
                (Dione   (0.0377 0 0) (0 0 0) (0.86 0.63 0.65)  0.011 0 0.88)
                (Phoebe  (12.952 0 0) (0 0 0) (0.57 0.49 0.62) 0.00022 0 -0.04))
        ))

(setf uranus-data  
      '((uranus (120 120 70) (1 0 3) (0 0 1) 0.5 -0.14 18 "sphere2" (0 5 0) (0 17 0)
                nil)
	))

(setf neptune-data  
      '((neptune (140 140 90) (0 0 0) (0 0 1) 0.48 0.14 29 "sphere2" (0 5 0) (0 17 0)
                 nil)
	))

(setf pluto-data  ;10x bigger
      '((pluto (160 160 100) (0 0 0) (0.6 0 0.6) 0.2 -0.07 117 "sphere2" (0 5 0) (0 17 0)
               nil)
	))

(setf solar-system (list sun-data mercury-data venus-data earth-data
                         mars-data jupiter-data saturn-data uranus-data
                         neptune-data pluto-data))

(setf star-data
      '((star1 (160 200 100) 0.1)
        (star2 (100 200 30)  0.1)
        (star3 (40 200 -20) 0.1)
        (star4 (0 200 -40)  0.2)
        (star5 (-40 200 40)  0.2)
        (star6 (-50 200 50)  0.2)
        (star7 (-120 200 0)  0.2)))
