Statistics
| Revision:

root / PyOpenGL-Demo / NeHe / lesson44 / glPoint.py @ 1

History | View | Annotate | Download (795 Bytes)

1
import glVector
2

    
3
class glPoint (list):
4
        def __init__ (self, first = 0, second = 0, third = 0):
5
                # Allow creation from a vector
6
                if (isinstance (first, glVector.glVector)):
7
                        self.x = first.i
8
                        self.y = first.j
9
                        self.z = first.k
10
                else:
11
                        self.x = first
12
                        self.y = second
13
                        self.z = third
14

    
15
        def __str__ (self):
16
                return "x=%f y=%f z=%f" % (self.x, self.y, self.z)
17

    
18
        def __iadd__ (self, other):
19
                self.x += other.x
20
                self.y += other.y
21
                self.z += other.z
22
                return self
23

    
24
        def __add__ (self, other):
25
                result = glPoint (self.x, self.y, self.z)
26
                result += other
27
                return result
28

    
29
        def __sub__ (self, other):
30
                """ Create a vector from the difference between this point and another point """
31
                result = glVector.glVector (self.x - other.x, self.y - other.y, self.z - other.z)
32
                return result