summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-15 23:01:04 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-25 19:33:07 -0400
commit73e2fd47272195d2fb458a7f139bde91b70551a7 (patch)
tree5e634b9f3ff5ce03f93aaf531a4f061286c90a83
parentb5f1f175ac08ef1e4a90bd66ce20d159ba146193 (diff)
Add shape module.
* Makefile.am (SOURCES): Add it. * sly/shape.scm: New file.
-rw-r--r--Makefile.am1
-rw-r--r--sly/shape.scm113
2 files changed, 114 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 72cb302..8b9c75c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,6 +42,7 @@ SOURCES = \
sly/repl.scm \
sly/scene.scm \
sly/shader.scm \
+ sly/shape.scm \
sly/signal.scm \
sly/sprite.scm \
sly/texture.scm \
diff --git a/sly/shape.scm b/sly/shape.scm
new file mode 100644
index 0000000..3d96ca7
--- /dev/null
+++ b/sly/shape.scm
@@ -0,0 +1,113 @@
+;;; Sly
+;;; Copyright (C) 2014 David Thompson <davet@gnu.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; Primitive 2D/3D shapes.
+;;
+;;; Code:
+
+(define-module (sly shape)
+ #:use-module (sly math)
+ #:use-module (sly mesh)
+ #:use-module (sly texture)
+ #:export (make-cube))
+
+(define (make-cube texture shader size)
+ (let* ((s1 (texture-s1 texture))
+ (t1 (texture-t1 texture))
+ (s2 (texture-s2 texture))
+ (t2 (texture-t2 texture))
+ (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)
+ #:data `(("position" ,(vector
+ ;; Front
+ (vector (- half-size) (- half-size) (- half-size))
+ (vector half-size (- half-size) (- half-size))
+ (vector half-size half-size (- half-size))
+ (vector (- half-size) half-size (- half-size))
+ ;; Back
+ (vector (- half-size) (- half-size) half-size)
+ (vector half-size (- half-size) half-size)
+ (vector half-size half-size half-size)
+ (vector (- half-size) half-size half-size)
+ ;; Top
+ (vector (- half-size) half-size (- half-size))
+ (vector half-size half-size (- half-size))
+ (vector half-size half-size half-size)
+ (vector (- half-size) half-size half-size)
+ ;; Bottom
+ (vector (- half-size) (- half-size) (- half-size))
+ (vector half-size (- half-size) (- half-size))
+ (vector half-size (- half-size) half-size)
+ (vector (- half-size) (- half-size) half-size)
+ ;; Left
+ (vector (- half-size) (- half-size) (- half-size))
+ (vector (- half-size) half-size (- half-size))
+ (vector (- half-size) half-size half-size)
+ (vector (- half-size) (- half-size) half-size)
+ ;; Right
+ (vector half-size (- half-size) (- half-size))
+ (vector half-size half-size (- half-size))
+ (vector half-size half-size half-size)
+ (vector half-size (- half-size) half-size)))
+ ("tex" ,(vector
+ ;; Front
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Back
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Top
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Bottom
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Left
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Right
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)))))))