Author: ArcRiley Date: 2008-02-06 05:31:15 -0500 (Wed, 06 Feb 2008) New Revision: 816
Added: trunk/pysoy/src/scenes/_getScenes.pxi Modified: trunk/pysoy/src/scenes/Scene.pxi trunk/pysoy/src/scenes/soy.scenes.pxd trunk/pysoy/src/scenes/soy.scenes.pyx Log: more work on #903 Modified: trunk/pysoy/src/scenes/Scene.pxi =================================================================== --- trunk/pysoy/src/scenes/Scene.pxi 2008-02-06 10:20:00 UTC (rev 815) +++ trunk/pysoy/src/scenes/Scene.pxi 2008-02-06 10:31:15 UTC (rev 816) @@ -1,4 +1,4 @@ -# PySoy Scene Class +# PySoy scenes.Scene Class # # Copyright (C) 2006,2007,2008 PySoy Group # Copied: trunk/pysoy/src/scenes/_getScenes.pxi (from rev 815, trunk/pysoy/src/scenes/Scene.pxi) =================================================================== --- trunk/pysoy/src/scenes/_getScenes.pxi (rev 0) +++ trunk/pysoy/src/scenes/_getScenes.pxi 2008-02-06 10:31:15 UTC (rev 816) @@ -0,0 +1,161 @@ +# PySoy scenes.Scene Class +# +# Copyright (C) 2006,2007,2008 PySoy Group +# +# 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 +# +# $Id$ + +cimport soy.bodies.lights + +cdef soy._internals.Children _scenes +_scenes = soy._internals.Children() + +cdef class Scene : + '''PySoy Scene + + Scenes are containers in physics space for bodies, joints, and shapes. + Objects in different worlds cannot interact, for example, bodies in two + different worlds cannot collide. Worlds also apply gravity to bodies. + ''' + + def __cinit__(self, *args, **kw) : + global _scenes + self._bodies = soy._internals.Children() + self._joints = soy._internals.Children() + self._lights = soy._internals.Children() + self._worldID = ode.dWorldCreate() + self._spaceID = ode.dSimpleSpaceCreate(NULL) + self._stepSize = 0.01 + self._prevTime = _time() + self._ambient = soy.colors.Gray() + _scenes.lock() + _scenes.append(<void *>self) + _scenes.unlock() + + + def __dealloc__(self) : + global _scenes + _scenes.lock() + _scenes.remove(<void *>self) + _scenes.unlock() + if self._worldID != NULL : + ode.dWorldDestroy(self._worldID) + if self._spaceID != NULL : + ode.dSpaceDestroy(self._spaceID) + + + def __repr__(self) : + report = [] + if self._bodies.current == 1 : + report.append('1 body') + elif self._bodies.current > 1 : + report.append('%d bodies' % self._bodies.current) + + if self._lights.current == 1 : + report.append('1 light') + elif self._bodies.current > 1 : + report.append('%d lights' % self._lights.current) + + if report == [] : return '<Empty Scene>' + else : return '<Scene with %s>' % ', '.join(report) + + + cdef void _render(self) : + cdef int i + cdef float _ambientLight[4] + + gl.glEnable(gl.GL_LIGHTING) + (<soy.colors.Color> self._ambient)._getRGBA(_ambientLight) + gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, _ambientLight) + self._lights.lock() + for i from 0 <= i < self._lights.current : + # This is a quick hack (gl.GL_LIGHT0+i) + (<soy.bodies.lights.Light> self._lights.list[i])._on(gl.GL_LIGHT0+i) + self._lights.unlock() + self._bodies.lock() + for i from 0 <= i < self._bodies.current : + (<soy.bodies._bodies.Body> self._bodies.list[i])._render() + self._bodies.unlock() + self._lights.lock() + for i from 0 <= i < self._lights.current : + # This is a quick hack (gl.GL_LIGHT0+i) + (<soy.bodies.lights.Light> self._lights.list[i])._off(gl.GL_LIGHT0+i) + self._lights.unlock() + gl.glDisable(gl.GL_LIGHTING) + + + cdef void _updateTime(self) : + self._time = _time() + + + cdef int _steps(self) : + cdef int _step + cdef double _lapsTime + _lapsTime = _time() - self._prevTime + if _lapsTime < ode.dEpsilon : + _lapsTime = ode.dEpsilon + _step = lround(_lapsTime / self._stepSize) + if _step > 12 : + _step = 12 + self._prevTime = self._prevTime + (_step * self._stepSize) + return _step + + + property gravity : + '''Scene gravity + + This is a scene-wide pseudo-force drawing all bodies in a single + direction. This should not be confused with a monopole force or other + forces which are often used for gravity in larger scenes. + + Takes a (x,y,z) tuple of numbers, defaults to (0.0, 0.0, 0.0) + ''' + def __get__(self) : + cdef ode.dVector3 grav + ode.dWorldGetGravity(self._worldID, grav) + return (grav[0], grav[1], grav[2]) + def __set__(self, value) : + ode.dWorldSetGravity(self._worldID, value[0], value[1], value[2]) + + + property stepsize : + '''Step Size + + This is the fraction of time each "step" calculates for. Larger steps + trade accuracy for speed. + + Takes a float, defaults to .01 + ''' + def __get__(self) : + return self._stepSize + def __set__(self, value) : + global _scenes + _scenes.lock() + self._stepSize = value + _scenes.unlock() + + + property ambient : + '''Scene's ambient light + + This is the ambient light for the scene. When no light is used this is + the only light available in the scene - use it well. + + Defaults to soy.colors.Gray(). + ''' + def __get__(self) : + return self._ambient + def __set__(self, soy.colors.Color value) : + self._ambient = value Modified: trunk/pysoy/src/scenes/soy.scenes.pxd =================================================================== --- trunk/pysoy/src/scenes/soy.scenes.pxd 2008-02-06 10:20:00 UTC (rev 815) +++ trunk/pysoy/src/scenes/soy.scenes.pxd 2008-02-06 10:31:15 UTC (rev 816) @@ -1,4 +1,4 @@ -# PySoy Core Declarations (for X11-based systems) +# PySoy Scenes Declarations # # Copyright (C) 2006,2007,2008 PySoy Group # @@ -18,10 +18,8 @@ # $Id$ cimport gl -cimport glx cimport glib cimport ode -cimport ogg cimport py cimport stdio cimport soy._datatypes @@ -50,51 +48,6 @@ cdef void _updateTime(self) -cdef class Screen : - cdef glx.Screen *_screen - cdef int _screenID - cdef glx.Atom _wmDelWin - cdef glx.XF86VidModeModeInfo _deskMode - cdef glx.XVisualInfo *_xVisualInfo - cdef object _fullScreen - # OpenGL Support - cdef int _glVersion - cdef void _glewInit(self) - cdef void _events(self) - -cdef class Window : - cdef soy._internals.Children _controllers - cdef soy._internals.Children _widgets - cdef Screen _screen - cdef glx.Window _windowID - cdef object _title - cdef soy.textures.Texture _icon - cdef glx.Pixmap _iconID - cdef soy.colors.Color _background - cdef int _width - cdef int _height - cdef int _savedWidth - cdef int _savedHeight - cdef int _opened - cdef int _splash - # _coreloop methods - cdef void _create(self, int, int, int, int) - cdef void _destroy(self) - cdef void _render(self) - cdef void _resize(self, int _width, int _height) - cdef void _setProperties( self ) - cdef void _eventKeyDown ( self, glx.Time, - glx.KeyCode, glx.KeySym ) - cdef void _eventKeyUp ( self, glx.Time, - glx.KeyCode, glx.KeySym ) - cdef void _eventButtonDown( self, glx.Time, - unsigned int, int, int ) - cdef void _eventButtonUp ( self, glx.Time, - unsigned int, int, int ) - cdef void _eventMotion ( self, glx.Time, int, int ) - cdef void _eventWinClose ( self ) - - cdef extern from "sys/time.h" : cdef struct timeval : long int tv_sec Modified: trunk/pysoy/src/scenes/soy.scenes.pyx =================================================================== --- trunk/pysoy/src/scenes/soy.scenes.pyx 2008-02-06 10:20:00 UTC (rev 815) +++ trunk/pysoy/src/scenes/soy.scenes.pyx 2008-02-06 10:31:15 UTC (rev 816) @@ -35,14 +35,3 @@ include "../_core-common/Scene.pxi" include "_sleep.pxi" include "_time.pxi" -include "Screen.pxi" -include "Window.pxi" - -# These must be last and in this order -include "../_core-common/_eventLoop.pxi" -include "../_core-common/quit.pxi" -include "../_core-common/_callback.pxi" -include "../_core-common/_coreLoop.pxi" -include "../_core-common/_runField.pxi" -include "../_core-common/_prerunField.pxi" -include "../_core-common/_init.pxi" _______________________________________________ PySoy-SVN mailing list [email protected] http://www.pysoy.org/mailman/listinfo/pysoy-svn
