Exemple #1
0
def lookAt(eye, center, up):
    ''' Matrix 4x4 lookAt function.'''
    f = (center - eye).normalize()
    u = up.normalize()
    s = vector.cross(f, u).normalize()
    u = vector.cross(s, f)

    output = [[s.vector[0], u.vector[0], -f.vector[0], 0.0],
              [s.vector[1], u.vector[1], -f.vector[1], 0.0],
              [s.vector[2], u.vector[2], -f.vector[2], 0.0],
              [-s.dot(eye), -u.dot(eye), f.dot(eye), 1.0]]
    return Matrix(4, data=output)
Exemple #2
0
def lookAt(eye, center, up):
    ''' Matrix 4x4 lookAt function.'''
    f = (center - eye).normalize()
    u = up.normalize()
    s = vector.cross(f, u).normalize()
    u = vector.cross(s, f)

    output = [[s.vector[0], u.vector[0], -f.vector[0], 0.0],
              [s.vector[1], u.vector[1], -f.vector[1], 0.0],
              [s.vector[2], u.vector[2], -f.vector[2], 0.0],
              [-s.dot(eye), -u.dot(eye),
               f.dot(eye), 1.0]]
    return Matrix(4, data=output)
Exemple #3
0
 def fromPoints(self, a, b, c):
     '''Calculate the plane from A,B,C.'''
     self.a = a
     self.b = b
     self.c = c
     self.normal = vector.cross(b - a, c - a).normalize()
     self.d = self.normal.dot(self.a)
Exemple #4
0
 def fromCoeffs(self, a, b, c, d):
     ''' Create the plane from A,B,C,D. '''
     self.a = a
     self.b = b
     self.c = c
     self.d = d
     self.normal = vector.cross(b - a, c - a).normalize()
Exemple #5
0
 def fromPoints(self, a, b, c):
     """Calculate the plane from A,B,C."""
     self.a = a
     self.b = b
     self.c = c
     self.normal = vector.cross(b - a, c - a).normalize()
     self.d = self.normal.dot(self.a)
Exemple #6
0
 def fromCoeffs(self, a, b, c, d):
     """ Create the plane from A,B,C,D. """
     self.a = a
     self.b = b
     self.c = c
     self.d = d
     self.normal = vector.cross(b - a, c - a).normalize()
Exemple #7
0
    def processLine(self, simplex):
        '''Determines which Veronoi region of a tetrehedron the origin is in, utilizing the preserved winding of the simplex to eliminate certain regions'''
        a = simplex[1]
        b = simplex[0]

        ab = b - a
        aO = -a

        if(ab.isInSameDirection(aO)):
            #dot = ab.dot(aO)
            #angle = math.acos(dot / ab.magnitude() * aO.magnitude())
            self.direction = vector.cross(vector.cross(ab, aO), ab)
        else:
            simplex.remove(b)
            self.direction = aO
        return False
Exemple #8
0
    def processTetrehedron(self, simplex):
        '''Determines which Veronoi region of a tetrehedron the origin is in, utilizing the preserved winding of the simplex to eliminate certain regions'''
        a = simplex[3]
        b = simplex[2]
        c = simplex[1]
        d = simplex[0]

        ac = c - a
        ad = d - a
        ab = b - a
        #bc = c - b
        #bd = d - b

        acd = vector.cross(ad, ac)
        abd = vector.cross(ab, ad)
        abc = vector.cross(ac, ab)

        aO = -a

        if (abc.isInSameDirection(aO)):
            if (vector.cross(abc, ac).isInSameDirection(aO)):
                simplex.remove(b)
                simplex.remove(d)
                self.direction = vector.cross(vector.cross(ac, aO), ac)
            elif(vector.cross(ab, abc).isInSameDirection(aO)):
                simplex.remove(c)
                simplex.remove(d)
                self.direction = vector.cross(vector.cross(ab, aO), ab)
            else:
                simplex.remove(d)
                self.direction = abc
        elif (acd.isInSameDirection(aO)):
            if (vector.cross(acd, ad).isInSameDirection(aO)):
                simplex.remove(b)
                simplex.remove(c)
                self.direction = vector.cross(vector.cross(ad, aO), ad)
            elif(vector.cross(ac, acd).isInSameDirection(aO)):
                simplex.remove(b)
                simplex.remove(d)
                self.direction = vector.cross(vector.cross(ac, aO), ac)
            else:
                simplex.remove(b)
                self.direction = acd
        elif(abd.isInSameDirection(aO)):
            if(vector.cross(abd, ab).isInSameDirection(aO)):
                simplex.remove(b)
                simplex.remove(d)
                self.direction = vector.cross(vector.cross(ab, aO), ab)
            elif(vector.cross(ab, abd).isInSameDirection(aO)):
                simplex.remove(b)
                simplex.remove(c)
                self.direction = vector.cross(vector.cross(ad, aO), ad)
            else:
                simplex.remove(c)
                self.direction = abd
        else:
            return True
        return False
Exemple #9
0
    def processTriangle(self, simplex):
        '''Determines which Veronoi region of a tetrehedron the origin is in, utilizing the preserved winding of the simplex to eliminate certain regions'''
        a = simplex[2]
        b = simplex[1]
        c = simplex[0]

        ab = b - a
        ac = c - a
        abc = vector.cross(ab, ac)
        aO = -a

        acNormal = vector.cross(abc, ac)
        abNormal = vector.cross(ab, abc)

        if(acNormal.isInSameDirection(aO)):
            if(ac.isInSameDirection(aO)):
                simplex.remove(b)
                self.direction = vector.cross(vector.cross(ac, aO), ac)
            else:
                if(ab.isInSameDirection(aO)):
                    simplex.remove(c)
                    self.direction = vector.cross(vector.cross(ab, aO), ab)
                else:
                    simplex.remove(b)
                    simplex.remove(c)
                    self.direction = aO
        else:
            if (abNormal.isInSameDirection(aO)):
                if(ab.isInSameDirection(aO)):
                    simplex.remove(c)
                    self.direction = vector.cross(vector.cross(ab, aO), ab)
                else:
                    simplex.remove(b)
                    simplex.remove(c)
                    self.direction = aO
            else:
                if(abc.isInSameDirection(aO)):
                    self.direction = vector.cross(vector.cross(abc, aO), abc)
                else:
                    self.direction = vector.cross(vector.cross(-abc, aO), -abc)
        return False