剪切并粘贴 cl-glut-examples 代码,我将一个球体渲染到显示器上。现在我如何使用键盘在 ax,y 和 z 轴上移动它。还有一个在线资源可以学习 CL-OpenGL 中的游戏编程或如何制作墙壁、泥土、房屋和角色等东西,这样我就可以创建一个 3D 世界并在其中移动角色并为其提出游戏逻辑。
到目前为止,这是我的代码:
(defclass glut-teapot-window (glut:window)
()
(:default-initargs :width 948 :height 990 :title "glut-teapot.lisp"
:mode '(:single :rgb :depth)))
(defmethod glut:display-window :before ((window glut-teapot-window))
(gl:clear-color 0 0 0 0)
(gl:cull-face :back)
(gl:depth-func :less)
(gl:disable :dither)
(gl:shade-model :smooth)
(gl:light-model :light-model-local-viewer 1)
(gl:color-material :front :ambient-and-diffuse)
(gl:enable :light0 :lighting :cull-face :depth-test))
(defmethod glut:display ((window glut-teapot-window))
(gl:load-identity)
(gl:translate 0 0 -5)
(gl:rotate 100 1 1 0)
(gl:light :light0 :position '(6000 1000 15 0))
(gl:light :light0 :position '(2000 300 3000 0))
(gl:clear :color-buffer :depth-buffer)
(gl:color 1 1 1)
(gl:front-face :cw)
(glut:Solid-Sphere 1 10 10)
(gl:front-face :ccw)
(gl:flush))
(defmethod glut:reshape ((window glut-teapot-window) width height)
(gl:viewport 0 0 width height)
(gl:matrix-mode :projection)
(gl:load-identity)
(glu:perspective 50 (/ width height) 0.5 20)
(gl:matrix-mode :modelview)
(gl:load-identity))
(defmethod glut:keyboard ((window glut-teapot-window) key x y)
(declare (ignore x y))
(when (eql key #\Esc)
(glut:destroy-current-window)))
(defun glut-teapot ()
(glut:display-window (make-instance 'glut-teapot-window)))
(glut-teapot)