1
"""Selection-buffer handling code
3
This code is resonsible for turning gluint *
4
arrays into structured representations for use
7
def uintToLong( value ):
9
# array type without a uint, so represented as an int
10
value = (value & 0x7fffffff) + 0x80000000
14
class GLSelectRecord( object ):
15
"""Minimalist object for storing an OpenGL selection-buffer record
17
Provides near and far as *float* values by dividing by
18
self.DISTANCE_DIVISOR (2**32-1)
20
Depth values (which are in the range [0,1]) are multiplied by
21
2^32 - 1, before being placed in the hit record.
23
Names are unmodified, so normally are slices of the array passed in
24
to GLSelectRecord.fromArray( array )
26
DISTANCE_DIVISOR = float((2L**32)-1)
27
__slots__ = ('near','far','names')
28
def fromArray( cls, array, total ):
29
"""Produce list with all records from the array"""
32
arrayLength = len(array)
33
for item in xrange( total ):
34
if index + 2 >= arrayLength:
39
names = map(uintToLong, array[index+3:index+3+count])
40
result.append( cls( near, far, names ) )
43
fromArray = classmethod( fromArray )
45
def __init__( self, near, far, names ):
46
"""Initialise/store the values"""
47
self.near = self.convertDistance( near )
48
self.far = self.convertDistance( far )
50
def convertDistance( self, value ):
51
"""Convert a distance value from array uint to 0.0-1.0 range float"""
52
return uintToLong( value ) / self.DISTANCE_DIVISOR
53
def __getitem__( self, key ):
54
"""Allow for treating the record as a three-tuple"""
55
if isinstance( key, (int,long)):
56
return (self.near,self.far,self.names)[key]
57
elif key in self.__slots__:
59
return getattr( self, key )
60
except AttributeError, err:
61
raise KeyError( """Don't have an index/key %r for %s instant"""%(
b'\\ No newline at end of file'