source: src/models/Sun.pxi @ 1166:46634b842b03

Revision 1166:46634b842b03, 6.2 KB checked in by Jon Neal <reportingsjr@…>, 7 years ago (diff)

Ticket #950: Cleaned up all files to comply with organisation standards, soy._core and NormalizationCubeMap? ommited.

Line 
1# PySoy's models.Axis class
2#
3# Copyright (C) 2006,2007,2008 PySoy Group
4#
5#  This program is free software; you can redistribute it and/or modify
6#  it under the terms of the GNU Affero General Public License as published
7#  by the Free Software Foundation, either version 3 of the License, or
8#  (at your option) any later version.
9#
10#  This program is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#  GNU Affero General Public License for more details.
14#
15#  You should have received a copy of the GNU Affero General Public License
16#  along with this program; if not, see http://www.gnu.org/licenses
17#
18# $Id: Sun.pxi 1212 2008-03-28 21:49:25Z JonNeal $
19
20cdef class Sun (Model) :
21  '''soy.models.Sun
22
23    This models class renders a sun.
24  '''
25
26  ############################################################################
27  #
28  # Python functions
29  #
30 
31  def __cinit__(self, **kwargs ) :
32    if kwargs.has_key('centerMat') :
33      self._centerMat = kwargs['centerMat']
34    else:
35      self._centerMat = soy.materials.StainlessSteel()
36
37    if kwargs.has_key('auraMat') :
38      self._auraMat = kwargs['auraMat']
39    else:
40      self._auraMat = soy.materials.StainlessSteel()
41
42    if kwargs.has_key('spikeMat') :
43      self._spikeMat = kwargs['spikeMat']
44    else:
45      self._spikeMat = soy.materials.StainlessSteel()
46
47    if kwargs.has_key('numSpikes') :
48      self._numSpikes = kwargs['numSpikes']
49    else:
50      self._numSpikes = 4
51
52    if kwargs.has_key('circleVerts') :
53      self._circleVerts = kwargs['circleVerts']
54    else:
55      self._circleVerts = 32
56
57    if kwargs.has_key('centerSize') :
58      self._centerSize[0] = kwargs['centerSize'][0]
59      self._centerSize[1] = kwargs['centerSize'][1]
60    else:
61      self._centerSize[0] = 1
62      self._centerSize[1] = 1
63
64    if kwargs.has_key('auraSize') :
65      self._auraSize[0] = kwargs['auraSize'][0]
66      self._auraSize[1] = kwargs['auraSize'][1]
67    else:
68      self._auraSize[0] = 2
69      self._auraSize[1] = 2
70
71    if kwargs.has_key('spikeSize') :
72      self._spikeSize = kwargs['spikeSize']
73    else:
74      self._spikeSize = 4
75
76
77  ############################################################################
78  #
79  # Properties
80  #
81
82  property centerMat :
83    def __get__(self) :
84      return self._centerMat
85
86    def __set__(self, newmat) :
87      self._centerMat = newmat
88
89
90  property auraMat :
91    def __get__(self) :
92      return self._auraMat
93
94    def __set__(self, newmat) :
95      self._auraMat = newmat
96
97
98  property spikeMat :
99    def __get__(self) :
100      return self._spikeMat
101
102    def __set__(self, newmat) :
103      self._spikeMat = newmat
104
105
106  property numSpikes :
107    def __get__(self) :
108      return self._numSpikes
109
110    def __set__(self, newmat) :
111      self._numSpikes = newmat
112
113
114  property circleVerts :
115    def __get__(self) :
116      return self._circleVerts
117
118    def __set__(self, newmat) :
119      self._circleVerts = newmat
120
121
122  property centerSize :
123    def __get__(self) :
124      return (self._centerSize[0], self._centerSize[1])
125
126    def __set__(self, newsize) :
127      self._centerSize[0] = newsize[0]
128      self._centerSize[1] = newsize[1]
129
130
131  property auraSize :
132    def __get__(self) :
133      return (self._auraSize[0], self._auraSize[1])
134
135    def __set__(self, newsize) :
136      self._auraSize[0] = newsize[0]
137      self._auraSize[1] = newsize[1]
138
139
140  property spikeSize :
141    def __get__(self) :
142      return self._spikeSize
143
144    def __set__(self, newsize) :
145      self._spikeSize = newsize
146
147
148  ############################################################################
149  #
150  # WindowLoop Functions
151  #
152
153  cdef void _render(self, void* body) :
154    cdef int   _i
155    cdef float _mmat[16]
156    cdef float _xSize
157    cdef float _ySize
158    cdef float _angle
159    cdef float _piS
160    #
161    _piS = 3.1415926535897931 / 180.0
162    gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
163    #
164    # UP = (_mmat[0], _mmat[4], _mmat[8])
165    # RIGHT = (_mmat[1], _mmat[5], _mmat[9])
166    gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, _mmat)
167    _mmat[12] = _mmat[13] = _mmat[14] = 0
168    gl.glMultTransposeMatrixf(_mmat)
169    #
170    # Render Spikes
171    if self._spikeMat :
172      gl.glPolygonOffset(0,0)
173      self._spikeMat._coreBind()
174      _angle = 360.0 / self._numSpikes
175      for _i from 0 <= _i < self._numSpikes :
176        gl.glPushMatrix()
177        gl.glRotatef( _i * _angle, 0.0, 0.0, 1.0)
178        _xSize = self._centerSize[0]/5.0
179        _ySize = self._centerSize[1]/5.0
180        gl.glBegin(gl.GL_TRIANGLES)
181        gl.glNormal3f(0,0,-1)
182        gl.glTexCoord1f(0.0)
183        gl.glVertex3f(_xSize, _ySize, 0)
184        gl.glTexCoord1f(1.0)
185        gl.glVertex3f(0, self._spikeSize, 0)
186        gl.glTexCoord1f(0.0)
187        gl.glVertex3f(-_xSize, _ySize, 0)
188        gl.glEnd()
189        gl.glPopMatrix()
190        self._spikeMat._coreUnBind()
191    #
192    # Render Aura
193    if self._auraMat :
194      gl.glPolygonOffset(0, -1)
195      self._auraMat._coreBind()
196      _angle = 360.0 / self._circleVerts
197
198      gl.glBegin(gl.GL_TRIANGLE_FAN)
199      gl.glNormal3f(0,0,-1)
200      gl.glTexCoord1f(0.0)
201      gl.glVertex3f(0,0,0)
202      gl.glTexCoord1f(1.0)
203      for _i from 0 <= _i <= self._circleVerts :
204        _xSize = self._auraSize[0] * ode.dSin(-_pyS*(<float> _i * _angle))
205        _ySize = self._auraSize[1] * ode.dCos( _pyS*(<float> _i * _angle))
206        gl.glVertex3f(_xSize, _ySize, 0.0)
207      gl.glEnd()
208      self._auraMat._coreUnBind()
209    #
210    # Render Center
211    if self._centerMat :
212      gl.glPolygonOffset( 0.0, -4)
213      self._centerMat._coreBind()
214      _angle = 360.0 / self._circleVerts
215      gl.glBegin(gl.GL_TRIANGLE_FAN)
216      gl.glNormal3f(0,0,-1)
217      gl.glTexCoord1f(0.0)
218      gl.glVertex3f(0,0,0)
219      gl.glTexCoord1f(1.0)
220      for _i from 0 <= _i <= self._circleVerts :
221        _xSize = self._centerSize[0] * ode.dSin(-_pyS*(<float> _i * _angle))
222        _ySize = self._centerSize[1] * ode.dCos( _pyS*(<float> _i * _angle))
223        gl.glVertex3f(_xSize, _ySize, 0.0)
224      gl.glEnd()
225      self._centerMat._coreUnBind()
226    gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
Note: See TracBrowser for help on using the repository browser.