From 8d48b4eb6149c881ab8f08d41472e0d602941de3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 8 Nov 2014 07:34:46 -0500 Subject: render: Move shape module to sly/render directory. * sly/shape.scm: Delete. * sly/render/shape.scm: New file. * Makefile.am (SOURCES): Add new file. Delete old one. --- Makefile.am | 2 +- sly/render/shape.scm | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ sly/shape.scm | 116 --------------------------------------------------- 3 files changed, 117 insertions(+), 117 deletions(-) create mode 100644 sly/render/shape.scm delete mode 100644 sly/shape.scm diff --git a/Makefile.am b/Makefile.am index fc56f9d..bc1335a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,7 +41,6 @@ SOURCES = \ sly/rect.scm \ sly/repl.scm \ sly/scene.scm \ - sly/shape.scm \ sly/signal.scm \ sly/tileset.scm \ sly/transform.scm \ @@ -54,6 +53,7 @@ SOURCES = \ sly/render/mesh.scm \ sly/render/texture.scm \ sly/render/shader.scm \ + sly/render/shape.scm \ sly/render/sprite.scm \ sly/render/vertex-array.scm \ sly/render/context.scm \ diff --git a/sly/render/shape.scm b/sly/render/shape.scm new file mode 100644 index 0000000..d6d9bf3 --- /dev/null +++ b/sly/render/shape.scm @@ -0,0 +1,116 @@ +;;; Sly +;;; Copyright (C) 2014 David Thompson +;;; +;;; 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 +;;; . + +;;; Commentary: +;; +;; Primitive 2D/3D shapes. +;; +;;; Code: + +(define-module (sly render shape) + #:use-module (sly math) + #:use-module (sly render mesh) + #:use-module (sly render shader) + #:use-module (sly render texture) + #:use-module (sly math vector) + #:export (make-cube)) + +(define* (make-cube size #:optional #:key (texture #f) + (shader (load-default-shader))) + (let ((half-size (half size))) + (make-mesh + #:shader shader + #:texture texture + #:indices #( + ;; Front + 0 3 2 0 2 1 + ;; Back + 4 6 7 4 5 6 + ;; Top + 8 11 10 8 10 9 + ;; Bottom + 12 14 15 12 13 14 + ;; Left + 16 19 18 16 18 17 + ;; Right + 20 22 23 20 21 22) + #:positions (vector + ;; Front + (vector3 (- half-size) (- half-size) (- half-size)) + (vector3 half-size (- half-size) (- half-size)) + (vector3 half-size half-size (- half-size)) + (vector3 (- half-size) half-size (- half-size)) + ;; Back + (vector3 (- half-size) (- half-size) half-size) + (vector3 half-size (- half-size) half-size) + (vector3 half-size half-size half-size) + (vector3 (- half-size) half-size half-size) + ;; Top + (vector3 (- half-size) half-size (- half-size)) + (vector3 half-size half-size (- half-size)) + (vector3 half-size half-size half-size) + (vector3 (- half-size) half-size half-size) + ;; Bottom + (vector3 (- half-size) (- half-size) (- half-size)) + (vector3 half-size (- half-size) (- half-size)) + (vector3 half-size (- half-size) half-size) + (vector3 (- half-size) (- half-size) half-size) + ;; Left + (vector3 (- half-size) (- half-size) (- half-size)) + (vector3 (- half-size) half-size (- half-size)) + (vector3 (- half-size) half-size half-size) + (vector3 (- half-size) (- half-size) half-size) + ;; Right + (vector3 half-size (- half-size) (- half-size)) + (vector3 half-size half-size (- half-size)) + (vector3 half-size half-size half-size) + (vector3 half-size (- half-size) half-size)) + #:textures (let ((s1 (texture-s1 texture)) + (t1 (texture-t1 texture)) + (s2 (texture-s2 texture)) + (t2 (texture-t2 texture))) + (vector + ;; Front + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) + ;; Back + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) + ;; Top + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) + ;; Bottom + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) + ;; Left + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) + ;; Right + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2)))))) diff --git a/sly/shape.scm b/sly/shape.scm deleted file mode 100644 index ecacace..0000000 --- a/sly/shape.scm +++ /dev/null @@ -1,116 +0,0 @@ -;;; Sly -;;; Copyright (C) 2014 David Thompson -;;; -;;; 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 -;;; . - -;;; Commentary: -;; -;; Primitive 2D/3D shapes. -;; -;;; Code: - -(define-module (sly shape) - #:use-module (sly math) - #:use-module (sly render mesh) - #:use-module (sly render shader) - #:use-module (sly render texture) - #:use-module (sly math vector) - #:export (make-cube)) - -(define* (make-cube size #:optional #:key (texture #f) - (shader (load-default-shader))) - (let ((half-size (half size))) - (make-mesh - #:shader shader - #:texture texture - #:indices #( - ;; Front - 0 3 2 0 2 1 - ;; Back - 4 6 7 4 5 6 - ;; Top - 8 11 10 8 10 9 - ;; Bottom - 12 14 15 12 13 14 - ;; Left - 16 19 18 16 18 17 - ;; Right - 20 22 23 20 21 22) - #:positions (vector - ;; Front - (vector3 (- half-size) (- half-size) (- half-size)) - (vector3 half-size (- half-size) (- half-size)) - (vector3 half-size half-size (- half-size)) - (vector3 (- half-size) half-size (- half-size)) - ;; Back - (vector3 (- half-size) (- half-size) half-size) - (vector3 half-size (- half-size) half-size) - (vector3 half-size half-size half-size) - (vector3 (- half-size) half-size half-size) - ;; Top - (vector3 (- half-size) half-size (- half-size)) - (vector3 half-size half-size (- half-size)) - (vector3 half-size half-size half-size) - (vector3 (- half-size) half-size half-size) - ;; Bottom - (vector3 (- half-size) (- half-size) (- half-size)) - (vector3 half-size (- half-size) (- half-size)) - (vector3 half-size (- half-size) half-size) - (vector3 (- half-size) (- half-size) half-size) - ;; Left - (vector3 (- half-size) (- half-size) (- half-size)) - (vector3 (- half-size) half-size (- half-size)) - (vector3 (- half-size) half-size half-size) - (vector3 (- half-size) (- half-size) half-size) - ;; Right - (vector3 half-size (- half-size) (- half-size)) - (vector3 half-size half-size (- half-size)) - (vector3 half-size half-size half-size) - (vector3 half-size (- half-size) half-size)) - #:textures (let ((s1 (texture-s1 texture)) - (t1 (texture-t1 texture)) - (s2 (texture-s2 texture)) - (t2 (texture-t2 texture))) - (vector - ;; Front - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Back - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Top - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Bottom - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Left - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Right - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2)))))) -- cgit v1.2.3