;;;; Ru*** roLeplay Playground virtual tabletop ;;;; Copyright (C) 2022 Zull ;;;; ;;;; 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 3 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, see . (in-package :rulp.graphics) (defparameter +grid-span+ 50) (defparameter +is-grid-letters+ t) (defparameter +is-grid+ t) ; these two functions can be edited when different grids will be added (defun position-actor-to-view (a) (* a +grid-span+)) (defun position-view-to-actor (a) (floor (/ a +grid-span+))) (defparameter +letters-list+ '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")) ;; this function cycle throughout the letters (defun letter-cycle (n) (nth (mod n (length +letters-list+)) +letters-list+)) (defun toggle-grid () (if +is-grid+ (setf +is-grid+ nil) (setf +is-grid+ t))) ;; NOTE: horrible (defun toggle-grid-letters () (if +is-grid-letters+ (setf +is-grid-letters+ nil) (setf +is-grid-letters+ t))) ;; FIXME: the function doesn't consider *viewpoint-zoom* (defmacro grid-render (renderer &optional (x 0) (y 0) (w 100) (h 100)) "renderize a grid in where required" `(let ((neg-x (* ,x -1)) (neg-y (* ,y -1)) (plane-x (x *plane*)) (plane-y (y *plane*)) (x-iterations (/ (- ,w ,x) *plane-grid*)) (y-iterations (/ (- ,h ,y) *plane-grid*))) (progn ;; (sdl2:set-render-draw-color ,renderer ,red ,green ,blue 255) (loop :for i :from (ceiling (/ neg-x *plane-grid*)) :to x-iterations :do (sdl2:render-draw-line ,renderer (+ (* i *plane-grid*) plane-x) (+ plane-y neg-y) (+ (* i *plane-grid*) plane-x) (+ ,h plane-y neg-y)) ) (loop :for j :from (ceiling (/ neg-y *plane-grid*)) :to y-iterations :do (sdl2:render-draw-line ,renderer (+ plane-x neg-x) (+ (* j *plane-grid*) plane-y) (+ plane-x ,w neg-x) (+ (* j *plane-grid*) plane-y)) )) (sdl2:set-render-draw-color ,renderer 0 0 0 255) )) (defmacro indexes-render (renderer &optional (x 0) (y 0) (w 0) (h 0)) `(let ((neg-x (* ,x -1)) (neg-y (* ,y -1)) (x-offset (x *plane*)) (y-offset (y *plane*)) (x-iterations (/ (- ,w ,x) *plane-grid*)) (y-iterations (/ (- ,h ,y) *plane-grid*))) (loop :for k :from (floor (/ neg-x *plane-grid*)) :to x-iterations :do (loop :for l :from (floor (/ neg-y *plane-grid*)) :to y-iterations :do (tr-write (coordinate-to-grid-index (cons l (+ k 1))) (+ x-offset (* k *plane-grid*)) (+ y-offset (* l *plane-grid*)) (floor (/ *plane-grid* 3)) (floor (/ *plane-grid* 3)) ,renderer))) ;; (sdl2:set-render-draw-color ,renderer 0 255 0 100) ; remember to uncomment both ;; (sdl2:render-fill-rect ,renderer (sdl2:make-rect ,x ,y ,w ,h)) ; test for x y w and h )) ;;; BUG: the coordinates given to the macros are incorrect. The render-fill-rect test ;;; proven that the coordinates are not faithful of the view point visual. These ;;; coordinate must be adjusted so the (now commented) render-fill-rect line will ;;; always fill all the screen