脳汁でコードを書く

Archive for 10 月, 2009

CLで幾何モデルライブラリを作ろう(5)

日曜日, 10 月 18th, 2009

githubにてコードを追加しました

https://github.com/garaemon

仕様変更, というかこれからガシガシ変更していきます.

導入方法や動作環境はまた今度.

ドキュメンテーションもそのうち作ります.

あと, ちょっと攻殻機動隊っぽいデモをつくりました. REPLとの連携もみれます.

komainu sample

追記

動作環境について.

SBCLでかつマルチスレッドがつかえる環境でしか動きません.

というわけでlinuxでしかうごきません.

macはsnow leopardではOpenGLのdylibのffiがうまくいきません.

環境構築はclbuildを使うと楽.
以下は動作確認してないので注意

my-projectsに以下を追加

lisp-unit get_git git://repo.or.cz/lisp-unit.git
cl-interpol get_ediware
 
chimi get_git git://github.com/garaemon/chimi.git
nurarihyon get_git git://github.com/garaemon/nurarihyon.git
nurikabe get_git git://github.com/garaemon/nurikabe.git
komainu get_git git://github.com/garaemon/komainu.git
yasha get_git git://github.com/garaemon/yasha.git
tengu get_git git://github.com/garaemon/tengu.git
clyax get_git git://github.com/garaemon/clyax.git

さらにdependencyに以下を追加

cl-interpol cl-unicode
chimi iterate cl-interpol log5 cl-ppcre alexandria cffi
nurarihyon chimi
nurikabe chimi cl-vectors iterate cffi clyax nurarihyon alexandria
komainu chimi nurarihyon nurikabe iterate
yasha chimi usocket
tengu chimi iterate
clyax cffi chimi

CLで幾何モデルライブラリを作ろう(4)

金曜日, 10 月 9th, 2009

透明なobjectをサポート.

transparent object

transparent object

これに必要なコードは以下

(require :komainu)
(use-package :komainu)
(use-package :nurarihyon)
(use-package :nurikabe)
(defvar *viewer* (make-komainu-viewer :loggingp nil))
(defvar *a* (make-cube 100.0 100.0 100.0 :color :red))
(defvar *b* (make-cube 200.0 200.0 200.0 :color :green))
(transparent *b* 0.5)
(objects *viewer* (list *A* *B* *world-coords*))

CLで幾何モデルライブラリを作ろう(3)

金曜日, 10 月 9th, 2009

テクスチャに対応.こんな感じ.


textured cube

textured cube

(require :komainu)
(use-package :komainu)
(use-package :nurarihyon)
(use-package :nurikabe)
 
(defvar *viewer* (make-komainu-viewer :loggingp t))
(defvar *a* (make-cube 100.0 100.0 100.0 :color :red))
(defvar *im* (make-image :width 300 :height 300 :background :green))
(draw-string *im* "Hoge" 150 150
             :font-size 0.03
             :color :black)
(paste-texture (car (faces-of *a*)) *im*
               (list (float-vector 0 1)
                     (float-vector 0 0)
                     (float-vector 1 0)
                     (float-vector 1 1)))
(objects *viewer* (list *a*))

このために, clxのGLX, OpenGLのバインディングを捨てて, すべてcffiでバインディングを1から作り直すことにした.

ちなみに, 2Dの描画はcl-vectorsをつかってベクター描画.

snow leopardでsbclをbuildしてみる

日曜日, 10 月 4th, 2009

snow leopardでsbclのbuildにてこずったのでメモ

まずいまのstable版ではmakeが通らない.
以下のようなエラーが出る.

//entering make-target-1.sh
//building runtime system and symbol table file
rm -f *.[do] sbcl sbcl.nm sbcl.h core *.tmp
echo '#include "genesis/config.h"' >sbcl.h
echo '#include "genesis/constants.h"' >>sbcl.h
gcc -g -Wall -O2 -fdollars-in-identifiers -mmacosx-version-min=10.4 -I. -no-cpp-precomp  -c -o alloc.o alloc.c
In file included from alloc.c:21:
runtime.h: In function 'CONS':
runtime.h:151: warning: cast to pointer from integer of different size
runtime.h: In function 'SYMBOL':
runtime.h:157: warning: cast to pointer from integer of different size
runtime.h: In function 'FDEFN':
runtime.h:163: warning: cast to pointer from integer of different size
/var/folders/3K/3K4LXRIJHoq8UNahYP7P4U+++TI/-Tmp-//cck88adh.s:81:Incorrect register `%rbx' used with `l' suffix
/var/folders/3K/3K4LXRIJHoq8UNahYP7P4U+++TI/-Tmp-//cck88adh.s:578:Incorrect register `%rdx' used with `l' suffix
make: *** [alloc.o] Error 1

x86, x86_64にするとか1.0.30のバイナリをつかうとかいろいろ試してみたけど, 最終的にcvsの先端だとバグがfixされている模様

$ cvs -d :pserver:anonymous@sbcl.cvs.sourceforge.net:/cvsroot/sbcl co sbcl

そしたら, multi threadつかいたいのでsbcl/customize-target-features.lispというファイルを作る

(lambda (features)
      (flet ((enable (x)
               (pushnew x features))
             (disable (x)
               (setf features (remove x features))))
        ;; Threading support, available only on x86/x86-64 Linux, x86 Solaris
        ;; and x86 Mac OS X (experimental).
        (enable :sb-thread)))

次にsbcl/sbclcomprというのを作る

SBCL_HOME=/usr/local/lib/sbcl /usr/local/bin/sbcl $*

そんでもって

$ sh make.sh "sbclcompr"
$ sudo sh install.sh

なんかrun-tests.shが大量のエラーをはいてるけど, みなかったことにしよう…

追記:

sh run-tests.shの結果

Finished running tests.
Status:
 Expected failure:    float.pure.lisp / (SCALE-FLOAT-OVERFLOW BUG-372)
 Expected failure:    float.pure.lisp / (ADDITION-OVERFLOW BUG-372)
 Expected failure:    threads.pure.lisp / WITHOUT-INTERRUPTS+CONDITION-WAIT
 Expected failure:    callback.impure.lisp / UNDERFLOW-DETECTION
 Invalid exit status: clos-add-remove-method.impure.lisp
 Invalid exit status: clos-cache.impure.lisp
 Invalid exit status: clos-interrupts.impure.lisp
 Invalid exit status: compare-and-swap.impure.lisp
 Invalid exit status: debug.impure.lisp
 Expected failure:    external-format.impure.lisp / (CHARACTER-DECODE-LARGE
                                                     FORCE-END-OF-FILE)
 Invalid exit status: gc.impure.lisp
 Invalid exit status: hash.impure.lisp
 Expected failure:    packages.impure.lisp / USE-PACKAGE-CONFLICT-SET
 Expected failure:    packages.impure.lisp / IMPORT-SINGLE-CONFLICT
 Invalid exit status: profile.impure.lisp
 Invalid exit status: threads.impure.lisp
 Invalid exit status: timer.impure.lisp
 Invalid exit status: core.test.sh
test failed, expected 104 return code, got 1

CLで幾何ライブラリを作ろう(2)

金曜日, 10 月 2nd, 2009

色とcylinderを追加してみた

こんなかんじ

komainu-viewer2

komainu-viewer2

 (require :komainu)
(use-package :komainu)
(use-package :nurarihyon)
(defvar *viewer* (make-komainu-viewer))
(defvar *a* (make-cube 100.0 100.0 100.0 :color :red))
(defvar *b* (make-cube 100.0 100.0 100.0 :color :green))
(translate (coords-of *a*) (float-vector 0 100 0))
(translate (coords-of *b*) (float-vector 0 -100 0))
(objects *viewer* (list *a* *b* *world-coords*
                        (make-cylinder 100 100)))

CLで幾何ライブラリを作ろう

木曜日, 10 月 1st, 2009

最近というかこの一瞬間くらいで猛烈に実装しているのですが, 幾何ライブラリとそのビューワーをせっせと作ってます.

これくらいのコードで

(require :komainu)
 
(defvar *viewer* (komainu:make-komainu-viewer))
 
(komainu:objects *viewer* (komainu:make-cube 100 100 100))

こんなかんじの表示が出ます.

komainu viewer

komainu viewer

ちなみにkomainuっていうパッケージが幾何ライブラリ.

依存するライブラリとしてはchimi(ユーティリティライブラリ), nurarihyon(数学ライブラリ), nurikabe(GUIライブラリ)があります.

もうちょっとできて, いろいろと落ち着いたら公開します.

描画系はclxを叩いてglxでGLの関数を呼んでいます. clxのバグがいくつか発見されたので, どうしようかなーと悩み中

描画系のモットーはインタプリタからの対話性を重視