Пример #1
0
  def create_graphic_objects( self, canvas, mesh, doClip ) :

    #Draw object
    faces = mesh.getFaces()
    if( doClip == 0 ) :
      for i in faces :     
        v1 = mesh.getTransformedVertex( i[0] )
        v2 = mesh.getTransformedVertex( i[1] )
        v3 = mesh.getTransformedVertex( i[2] )   
        canvas.create_line( v1[0], v1[1], v2[0], v2[1], fill= "red" )
        canvas.create_line( v2[0], v2[1], v3[0], v3[1], fill= "red" )
        canvas.create_line( v3[0], v3[1], v1[0], v1[1], fill= "red" )
    else : 
      v = mesh.getViewport()
      width  = int( canvas.cget( "width" ) )
      height = int( canvas.cget( "height" ) )
      xMin = v[0] * width
      xMax = v[2] * width
      yMin = v[1] * height
      yMax = v[3] * height
      portal = (xMin, yMin, xMax, yMax)
      for i in faces : 
        v1 = mesh.getTransformedVertex( i[0] )
        v2 = mesh.getTransformedVertex( i[1] )
        v3 = mesh.getTransformedVertex( i[2] )
        doDraw, p1x, p1y, p2x, p2y = clipLine(v1[0], v1[1], v2[0], v2[1], portal )
        if(doDraw == True) : 
          canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )
        doDraw, p1x, p1y, p2x, p2y = clipLine(v2[0], v2[1], v3[0], v3[1], portal)
        if(doDraw == True) :
          canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )  
        doDraw, p1x, p1y, p2x, p2y = clipLine(v3[0], v3[1], v1[0], v1[1], portal)            
        if(doDraw == True) :
          canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )
Пример #2
0
    def draw_Patch_Triangle(self, canvas, portal, DataSet, Triangle_name,
                            doEuler, doPerspective):
        (p1x, p1y) = DataSet.transformXYZ(Triangle_name[0][0],
                                          Triangle_name[0][1],
                                          Triangle_name[0][2], doEuler,
                                          doPerspective)
        (p2x, p2y) = DataSet.transformXYZ(Triangle_name[1][0],
                                          Triangle_name[1][1],
                                          Triangle_name[1][2], doEuler,
                                          doPerspective)
        (p3x, p3y) = DataSet.transformXYZ(Triangle_name[2][0],
                                          Triangle_name[2][1],
                                          Triangle_name[2][2], doEuler,
                                          doPerspective)

        doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(
            p1x, p1y, p2x, p2y, portal)
        if doDraw:
            self.objects.append(
                canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))

        doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(
            p2x, p2y, p3x, p3y, portal)

        if doDraw:
            self.objects.append(
                canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))

        doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(
            p3x, p3y, p1x, p1y, portal)

        if doDraw:
            self.objects.append(
                canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
Пример #3
0
    def create_graphic_objects(self, canvas, modelData, doClip):

        (xMin, yMin, xMax, yMax) = modelData.getViewport()
        limits = (xMin, yMin, xMax, yMax)

        if (doClip):
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x1, y1, _ = modelData.getTransformedVertex(v1Num)
                x2, y2, _ = modelData.getTransformedVertex(v2Num)
                x3, y3, _ = modelData.getTransformedVertex(v3Num)

                (doDraw, _x1, _y1, _x2, _y2) = clipLine(x1, y1, x2, y2, limits)
                (doDraw, _x2, _y2, _x3, _y3) = clipLine(x2, y2, x3, y3, limits)
                (doDraw, _x3, _y3, _x1, _y1) = clipLine(x3, y3, x1, y1, limits)

                if (doDraw):
                    canvas.create_line(_x1, _y1, _x2, _y2, _x3, _y3, _x1, _y1)
                else:
                    canvas.create_line(x1, y1, x2, y2, x3, y3, x1, y1)

        else:
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x1, y1, _ = modelData.getTransformedVertex(v1Num)
                x2, y2, _ = modelData.getTransformedVertex(v2Num)
                x3, y3, _ = modelData.getTransformedVertex(v3Num)

                canvas.create_line(x1, y1, x2, y2, x3, y3, x1, y1)
Пример #4
0
    def create_graphic_objects(self, canvas, modelData, doClip, doPerspective,
                               doEuler):
        ax, ay, sx, sy = modelData.getViewport()
        width = int(canvas.cget("width"))
        height = int(canvas.cget("height"))
        portal = (width * ax, height * ay, width * sx, height * sy)

        if doClip == False:
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x2, y2, _ = modelData.getTransformedVertex(
                    v2Num, doPerspective, doEuler)
                x1, y1, _ = modelData.getTransformedVertex(
                    v1Num, doPerspective, doEuler)
                x3, y3, _ = modelData.getTransformedVertex(
                    v3Num, doPerspective, doEuler)

                canvas.create_line(x1, y1, x2, y2, x3, y3, x1, y1)
        else:
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x1, y1, _ = modelData.getTransformedVertex(
                    v1Num, doPerspective, doEuler)
                x2, y2, _ = modelData.getTransformedVertex(
                    v2Num, doPerspective, doEuler)
                x3, y3, _ = modelData.getTransformedVertex(
                    v3Num, doPerspective, doEuler)

                draw, p1x, p1y, p2x, p2y = clipLine(x1, y1, x2, y2, portal)
                if draw == True:
                    canvas.create_line(p1x, p1y, p2x, p2y)
                draw, p1x, p1y, p2x, p2y = clipLine(x2, y2, x3, y3, portal)
                if draw == True:
                    canvas.create_line(p1x, p1y, p2x, p2y)
                draw, p1x, p1y, p2x, p2y = clipLine(x3, y3, x1, y1, portal)
                if draw == True:
                    canvas.create_line(p1x, p1y, p2x, p2y)
Пример #5
0
    def create_graphic_objects(self, canvas, modelData, doClip):
        ax, ay, sx, sy = modelData.getViewport()
        width = int(canvas.cget("width"))
        height = int(canvas.cget("height"))
        portal = (width * ax, height * ay, width * sx, height * sy)

        if doClip == False:
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x1, y1, _ = modelData.getTransformedVertex(v1Num)
                x2, y2, _ = modelData.getTransformedVertex(v2Num)
                x3, y3, _ = modelData.getTransformedVertex(v3Num)

                canvas.create_line(x1, y1, x2, y2, x3, y3, x1, y1)
        else:
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x1, y1, _ = modelData.getTransformedVertex(v1Num)
                x2, y2, _ = modelData.getTransformedVertex(v2Num)
                x3, y3, _ = modelData.getTransformedVertex(v3Num)

                draw, p1x, p1y, p2x, p2y = clipLine(x1, y1, x2, y2, portal)
                print(f'draw the line between p1 and p2? {draw}')
                if draw == True:
                    print(f'drawing line from p1: {x1},{y1} to p2: {x2},{y2}')
                    canvas.create_line(p1x, p1y, p2x, p2y)
                draw, p1x, p1y, p2x, p2y = clipLine(x2, y2, x3, y3, portal)
                if draw == True:
                    canvas.create_line(p1x, p1y, p2x, p2y)
                draw, p1x, p1y, p2x, p2y = clipLine(x3, y3, x1, y1, portal)
                if draw == True:
                    canvas.create_line(p1x, p1y, p2x, p2y)
Пример #6
0
  def create_graphic_objects( self, canvas, DataSet) :

    viewport = DataSet.getViewport(); face = DataSet.getFaces()
    portal = []

    #Draw the Viewport rectangle.
    self.objects.append(canvas.create_rectangle
                        (float(viewport[0]) * float(canvas.cget("width")),
                         float(viewport[1]) * float(canvas.cget("height")),
                         float(viewport[2]) * float(canvas.cget("width")),
                         float(viewport[3]) * float(canvas.cget("height"))))

    # create an array to store the xmin, ymin, xmax and ymax values in the pixel
    # the values are the pixel or screen representation of the viewport window

    portal.append(float(viewport[0]) * float(canvas.cget("width")))  # xmin
    portal.append(float(viewport[1]) * float(canvas.cget("height"))) # ymin
    portal.append(float(viewport[2]) * float(canvas.cget("width")))  # xmax
    portal.append(float(viewport[3]) * float(canvas.cget("height"))) # ymax

    #print(f' Portal: ({portal[0]: .2f},{ portal[1]: .2f},{portal[2]: .2f},{portal[3]: .2f} )')

    for i in range(len(face)):
      #temporary values to store each face value and the transformed value respectively
       temp1 = face[i][0]; temp2 = face[i][1]; temp3 = face[i][2]

       #For each face from the ModelData instance, get the three vertex numbers for that face then Get from the
       # ModelData instance the transformed vertex coordinates.

       #vertice 1 (x, y) for the first face value
       x1 = DataSet.getTransformedVertex(temp1)[0]; y1 = DataSet.getTransformedVertex(temp1)[1]
       #vertice 2 (x, y) for the second face value
       x2 = DataSet.getTransformedVertex(temp2)[0]; y2 = DataSet.getTransformedVertex(temp2)[1]
       #vertice 3 (x, y) for the third face value
       x3 = DataSet.getTransformedVertex(temp3)[0]; y3 = DataSet.getTransformedVertex(temp3)[1]

       #draw three lines, v1->v2, v2->v3, and v3->v1
       #self.objects.append(canvas.create_line( (x1,y1),(x2,y2),(x3,y3),(x1,y1) ) )

       #create a copy of v1, v2 and v3 so that we don't modify their orignal values
       x1_temp = x1; y1_temp = y1; x2_temp = x2; y2_temp = y2; x3_temp = x3; y3_temp = y3

      # calls the clipLine definition in the Cohensutherland.py
      # checks if the do Draw value is true or false and returns the clipped co-ordinate for given two points
      # if the doDraw value is true then draw the line based on the new points(X1_new, Y1_new, X2_new, Y2_new) returned
      # by the clipping function and draw three lines, v1->v2, v2->v3, and v3->v1

       doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(x1_temp, y1_temp, x2_temp, y2_temp, portal)
       if (doDraw):
        self.objects.append(canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))

        doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(x2_temp, y2_temp, x3_temp, y3_temp, portal)
        if (doDraw):
            self.objects.append(canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))

        doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(x3_temp, y3_temp, x1_temp, y1_temp, portal)
        if (doDraw):
            self.objects.append(canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
Пример #7
0
  def create_graphic_objects( self, canvas, mesh, doClip, doPerspective, doEuler, res ) :

    #Draw object
    faces = mesh.getFaces()
    v = mesh.getViewport()
    width  = int( canvas.cget( "width" ) )
    height = int( canvas.cget( "height" ) )
    xMin = v[0] * width
    xMax = v[2] * width
    yMin = v[1] * height
    yMax = v[3] * height
    portal = (xMin, yMin, xMax, yMax)
    if( doClip == 0 ) :
      for i in faces :     
        v1 = mesh.getTransformedVertex( i[0], doPerspective, doEuler )
        v2 = mesh.getTransformedVertex( i[1], doPerspective, doEuler )
        v3 = mesh.getTransformedVertex( i[2], doPerspective, doEuler )   
        canvas.create_line( v1[0], v1[1], v2[0], v2[1], fill= "red" )
        canvas.create_line( v2[0], v2[1], v3[0], v3[1], fill= "red" )
        canvas.create_line( v3[0], v3[1], v1[0], v1[1], fill= "red" )
    else : 
      for i in faces : 
        v1 = mesh.getTransformedVertex( i[0], doPerspective, doEuler )
        v2 = mesh.getTransformedVertex( i[1], doPerspective, doEuler )
        v3 = mesh.getTransformedVertex( i[2], doPerspective, doEuler )
        doDraw, p1x, p1y, p2x, p2y = clipLine(v1[0], v1[1], v2[0], v2[1], portal )
        if(doDraw == True) : 
          canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )
        doDraw, p1x, p1y, p2x, p2y = clipLine(v2[0], v2[1], v3[0], v3[1], portal)
        if(doDraw == True) :
          canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )  
        doDraw, p1x, p1y, p2x, p2y = clipLine(v3[0], v3[1], v1[0], v1[1], portal)            
        if(doDraw == True) :
          canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )
      
    #Patches 
    patches = mesh.getPatches()
    for i in patches :
      patch = []
      for j in i : 
        patch.append( mesh.getTransformedVertex( j, doPerspective, doEuler ) )
      patch = resolveBezierPatch( res, patch )

      for row in range( res-1 ) : 
        rowStart = row*res
        for col in range( res-1 ) :
          here = rowStart + col 
          there = here + res 
          v1, v2, v3 = patch[here], patch[there], patch[there+1]
          drawTriangle( canvas, v1, v2, v3, portal, doClip )        
          v1, v2, v3 = patch[there+1], patch[here+1], patch[here]
          drawTriangle( canvas, v1, v2, v3, portal, doClip )
Пример #8
0
def drawTriangle( canvas, v1, v2, v3, portal, doClip ) :
  if( doClip == 0 ) :
    canvas.create_line( v1[0], v1[1], v2[0], v2[1], v3[0], v3[1], v1[0], v1[1], fill= "red" )
  else :
    doDraw, p1x, p1y, p2x, p2y = clipLine(v1[0], v1[1], v2[0], v2[1], portal )
    if(doDraw == True) : 
      canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )
    doDraw, p1x, p1y, p2x, p2y = clipLine(v2[0], v2[1], v3[0], v3[1], portal)
    if(doDraw == True) :
      canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )  
    doDraw, p1x, p1y, p2x, p2y = clipLine(v3[0], v3[1], v1[0], v1[1], portal)            
    if(doDraw == True) :
      canvas.create_line( p1x, p1y, p2x, p2y, fill= "red" )    
Пример #9
0
    def create_graphic_objects(self, canvas, modelData, doClip, perspective,
                               euler, resolution):
        p = perspective
        e = euler

        patches = modelData.getPatches()
        print(len(patches))

        height = int(canvas.cget("height"))
        width = int(canvas.cget("width"))
        w = modelData.getWindow()
        v = modelData.getViewport()
        vxMin = v[0] * width
        vxMax = v[2] * width
        vyMin = v[1] * height
        vyMax = v[3] * height
        portal = (vxMin, vyMin, vxMax, vyMax)
        print(
            f'Portal       :({vxMin:,.2f},{vyMin:.2f},{vxMax:.2f},{vyMax:.2f})'
        )

        for v1Num, v2Num, v3Num in modelData.getFaces():
            v1 = modelData.getTransformedVertex(v1Num, p, e)
            v2 = modelData.getTransformedVertex(v2Num, p, e)
            v3 = modelData.getTransformedVertex(v3Num, p, e)
            if doClip:
                for (vax, vay, _), (vbx, vby, _) in [(v1, v2), (v2, v3),
                                                     (v3, v1)]:
                    doDraw, vax, vay, vbx, vby = clipLine(
                        vax, vay, vbx, vby, portal)
                    if doDraw:
                        canvas.create_line(vax, vay, vbx, vby)
            else:
                canvas.create_line(*v1[:-1], *v2[:-1], *v3[:-1], *v1[:-1])

    ###############################################################
        if (len(patches) != 0):
            for patch in patches:
                listPatch = []
                pointList = []
                for vNum in patch:
                    Tuple = modelData.getTransformedVertex(vNum, p, e)
                    listPatch.append(Tuple)
                pointList = modelData.resolveBézierPatch(listPatch)
                for row in range(0, resolution - 1):
                    rowStart = row * resolution

                    for col in range(0, resolution - 1):
                        here = rowStart + col
                        there = here + resolution

                        triangleA = (pointList[here], pointList[there],
                                     pointList[there + 1])
                        (v1, v2, v3) = triangleA
                        self.drawTriangle(canvas, v1, v2, v3, portal, doClip)

                        triangleB = (pointList[there + 1], pointList[here + 1],
                                     pointList[here])
                        (v1, v2, v3) = triangleB
                        self.drawTriangle(canvas, v1, v2, v3, portal, doClip)
Пример #10
0
    def create_graphic_objects(self, canvas, modelData, doClip, doPerspective):

        width = int(canvas.cget("width"))
        height = int(canvas.cget("height"))
        v = modelData.getViewport()
        vxMin = v[0] * width
        vxMax = v[2] * width
        vyMin = v[1] * height
        vyMax = v[3] * height
        portal = (vxMin, vyMin, vxMax, vyMax)

        if (doClip):
            for v1Num, v2Num, v3Num in modelData.getFaces():
                v1 = modelData.getTransformedVertex(v1Num, doPerspective)
                v2 = modelData.getTransformedVertex(v2Num, doPerspective)
                v3 = modelData.getTransformedVertex(v3Num, doPerspective)

                for (vax, vay, _), (vbx, vby, _) in [(v1, v2), (v2, v3),
                                                     (v3, v1)]:
                    (doDraw, vax, vay, vbx,
                     vby) = clipLine(vax, vay, vbx, vby, portal)

                    if (doDraw):
                        canvas.create_line(vax, vay, vbx, vby)

        else:
            for v1Num, v2Num, v3Num in modelData.getFaces():
                x1, y1, _ = modelData.getTransformedVertex(
                    v1Num, doPerspective)
                x2, y2, _ = modelData.getTransformedVertex(
                    v2Num, doPerspective)
                x3, y3, _ = modelData.getTransformedVertex(
                    v3Num, doPerspective)

                canvas.create_line(x1, y1, x2, y2, x3, y3, x1, y1)
Пример #11
0
    def create_graphic_objects(self, canvas, modelData, doClip, perspective,
                               euler):
        p = perspective
        e = euler
        print(p)

        height = int(canvas.cget("height"))
        width = int(canvas.cget("width"))
        w = modelData.getWindow()
        v = modelData.getViewport()
        vxMin = v[0] * width
        vxMax = v[2] * width
        vyMin = v[1] * height
        vyMax = v[3] * height
        portal = (vxMin, vyMin, vxMax, vyMax)
        print(
            f'Portal       :({vxMin:,.2f},{vyMin:.2f},{vxMax:.2f},{vyMax:.2f})'
        )

        for v1Num, v2Num, v3Num in modelData.getFaces():
            v1 = modelData.getTransformedVertex(v1Num, p, e)
            v2 = modelData.getTransformedVertex(v2Num, p, e)
            v3 = modelData.getTransformedVertex(v3Num, p, e)
            if doClip:
                for (vax, vay, _), (vbx, vby, _) in [(v1, v2), (v2, v3),
                                                     (v3, v1)]:
                    doDraw, vax, vay, vbx, vby = clipLine(
                        vax, vay, vbx, vby, portal)
                    if doDraw:
                        canvas.create_line(vax, vay, vbx, vby)
            else:
                canvas.create_line(*v1[:-1], *v2[:-1], *v3[:-1], *v1[:-1])
Пример #12
0
 def drawTriangle(self, canvas, v1, v2, v3, portal, doClip):
     if doClip:
         for (vax, vay, _), (vbx, vby, _) in [(v1, v2), (v2, v3), (v3, v1)]:
             doDraw, vax, vay, vbx, vby = clipLine(vax, vay, vbx, vby,
                                                   portal)
             if doDraw:
                 canvas.create_line(vax, vay, vbx, vby)
     else:
         canvas.create_line(*v1[:-1], *v2[:-1], *v3[:-1], *v1[:-1])
Пример #13
0
 def drawTriangle(self, canvas, v1, v2, v3, portal, doClip ) :
     if not doClip:
       self.objects.append( canvas.create_line(
         v1[0],v1[1],
         v2[0],v2[1],
         v3[0],v3[1],
         v1[0],v1[1]
       ))
     else:
       clip_result = clipLine(v1[0],v1[1],v2[0],v2[1], portal)
       if clip_result[0]:
         self.objects.append( canvas.create_line(clip_result[1],clip_result[2], clip_result[3],clip_result[4]))
       clip_result1 = clipLine(v2[0],v2[1],v3[0],v3[1], portal)
       if clip_result1[0]:
         self.objects.append( canvas.create_line(clip_result1[1],clip_result1[2], clip_result1[3],clip_result1[4]))
       clip_result2 = clipLine(v3[0],v3[1],v1[0],v1[1], portal)
       if clip_result2[0]:
         self.objects.append( canvas.create_line(clip_result2[1],clip_result2[2], clip_result2[3],clip_result2[4]))
Пример #14
0
    def drawTriangle(self, canvas, v1, v2, v3, portal, doClip):
        # x and y values of each vertex
        x1 = v1[0]
        y1 = v1[1]
        x2 = v2[0]
        y2 = v2[1]
        x3 = v3[0]
        y3 = v3[1]
        # create a copy of v1, v2 and v3 so that we don't modify their orignal values
        x1_temp = x1
        y1_temp = y1
        x2_temp = x2
        y2_temp = y2
        x3_temp = x3
        y3_temp = y3

        # calls the clipLine definition in the Cohensutherland.py
        # checks if the do Draw value is true or false and returns the clipped co-ordinate for given two points
        # if the doDraw value is true then draw the line based on the new points(X1_new, Y1_new, X2_new, Y2_new) returned
        # by the clipping function and draw three lines, v1->v2, v2->v3, and v3->v1

        if doClip:
            doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(
                x1_temp, y1_temp, x2_temp, y2_temp, portal)

            if doDraw:
                self.objects.append(
                    canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
                doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(
                    x2_temp, y2_temp, x3_temp, y3_temp, portal)

            if doDraw:
                self.objects.append(
                    canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
                doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(
                    x3_temp, y3_temp, x1_temp, y1_temp, portal)

            if doDraw:
                self.objects.append(
                    canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
        else:
            # draw three lines, v1->v2, v2->v3, and v3->v1
            self.objects.append(
                canvas.create_line((x1, y1), (x2, y2), (x3, y3), (x1, y1)))
Пример #15
0
 def drawTriangle( canvas, v1, v2, v3, portal, doClip ) :
   for v1Num, v2Num, v3Num in modelData.getFaces() :
       v1 = modelData.getTransformedVertex( v1Num, doPerspective, doEuler )
       v2 = modelData.getTransformedVertex( v2Num, doPerspective, doEuler )
       v3 = modelData.getTransformedVertex( v3Num, doPerspective, doEuler )
       
       for (vax, vay, _),(vbx, vby, _) in [(v1,v2),(v2,v3),(v3,v1)] :
           ( doDraw, vax, vay, vbx, vby ) = clipLine( vax, vay, vbx, vby, portal )
          
           if ( doDraw ) :
             canvas.create_line( vax, vay, vbx, vby )
Пример #16
0
    def create_graphic_objects(self, canvas, ModelData, persp, doClip):

        width = int(canvas.cget('width'))
        height = int(canvas.cget('height'))
        v = ModelData.getViewport()

        xmin = width * v[0]
        ymin = height * v[1]
        xmax = width * v[2]
        ymax = height * v[3]

        portal = (xmin, ymin, xmax, ymax)

        for face in ModelData.getFaces():
            v1 = ModelData.getTransformedVertex(face[0], persp)
            v2 = ModelData.getTransformedVertex(face[1], persp)
            v3 = ModelData.getTransformedVertex(face[2], persp)
            if doClip is True:
                line_1 = clipLine(v1[0], v1[1], v2[0], v2[1], portal)
                line_2 = clipLine(v2[0], v2[1], v3[0], v3[1], portal)
                line_3 = clipLine(v3[0], v3[1], v1[0], v1[1], portal)
                if line_1[0] is True:
                    self.objects.append(
                        canvas.create_line(line_1[1], line_1[2], line_1[3],
                                           line_1[4]))
                if line_2[0] is True:
                    self.objects.append(
                        canvas.create_line(line_2[1], line_2[2], line_2[3],
                                           line_2[4]))
                if line_3[0] is True:
                    self.objects.append(
                        canvas.create_line(line_3[1], line_3[2], line_3[3],
                                           line_3[4]))

            else:
                self.objects.append(
                    canvas.create_line(v1[0], v1[1], v2[0], v2[1]))
                self.objects.append(
                    canvas.create_line(v2[0], v2[1], v3[0], v3[1]))
                self.objects.append(
                    canvas.create_line(v3[0], v3[1], v1[0], v1[1]))
Пример #17
0
  def create_graphic_objects( self, canvas, modelData, doClip, doPerspective, doEuler, resolution ) :
    
    width  = int( canvas.cget( "width" ) )
    height = int( canvas.cget( "height" ) )
    v = modelData.getViewport()
    vxMin = v[0] * width
    vxMax = v[2] * width
    vyMin = v[1] * height
    vyMax = v[3] * height
    portal = ( vxMin, vyMin, vxMax, vyMax )

    for v1Num, v2Num, v3Num in modelData.getFaces() :
        x1, y1, _ = modelData.getTransformedVertex( v1Num, doPerspective, doEuler )
        x2, y2, _ = modelData.getTransformedVertex( v2Num, doPerspective, doEuler )
        x3, y3, _ = modelData.getTransformedVertex( v3Num, doPerspective, doEuler )

        canvas.create_line( x1, y1, x2, y2, x3, y3, x1, y1 )

    controlPts = []
    for p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16 in modelData.getPatches() :
      cp1 = modelData.getTransformedVertex( p1, doPerspective, doEuler )
      cp2 = modelData.getTransformedVertex( p2, doPerspective, doEuler )
      cp3 = modelData.getTransformedVertex( p3, doPerspective, doEuler )
      cp4 = modelData.getTransformedVertex( p4, doPerspective, doEuler )
      cp5 = modelData.getTransformedVertex( p5, doPerspective, doEuler )
      cp6 = modelData.getTransformedVertex( p6, doPerspective, doEuler )
      cp7 = modelData.getTransformedVertex( p7, doPerspective, doEuler )
      cp8 = modelData.getTransformedVertex( p8, doPerspective, doEuler )
      cp9 = modelData.getTransformedVertex( p9, doPerspective, doEuler )
      cp10 = modelData.getTransformedVertex( p10, doPerspective, doEuler )
      cp11 = modelData.getTransformedVertex( p11, doPerspective, doEuler )
      cp12 = modelData.getTransformedVertex( p12, doPerspective, doEuler )
      cp13 = modelData.getTransformedVertex( p13, doPerspective, doEuler )
      cp14 = modelData.getTransformedVertex( p14, doPerspective, doEuler )
      cp15 = modelData.getTransformedVertex( p15, doPerspective, doEuler )
      cp16 = modelData.getTransformedVertex( p16, doPerspective, doEuler )
        
      controlPts = ( cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, cp11, cp12, cp13, cp14, cp15, cp16 )
      pointList = resolveBezierPatch( resolution, controlPts )

      for row in range( 0, resolution-2 ) :
        rowStart = row * resolution

        for col in range( 0, resolution-2 ) :
          here = rowStart + col
          there = here + resolution

          triangleA = ( pointList[here], pointList[there], pointList[there+1] )
          triangleB = ( pointList[there+1], pointList[here+1], pointList[here] )

          drawTriangle( canvas, v1, v2, v3, portal, doClip )
        

    if ( doClip ) :
      for v1Num, v2Num, v3Num in modelData.getFaces() :
        v1 = modelData.getTransformedVertex( v1Num, doPerspective, doEuler )
        v2 = modelData.getTransformedVertex( v2Num, doPerspective, doEuler )
        v3 = modelData.getTransformedVertex( v3Num, doPerspective, doEuler )

        for (vax, vay, _),(vbx, vby, _) in [(v1,v2),(v2,v3),(v3,v1)] :
            ( doDraw, vax, vay, vbx, vby ) = clipLine( vax, vay, vbx, vby, portal )
           
            if ( doDraw ) :
              canvas.create_line( vax, vay, vbx, vby )

    else :
      for v1Num, v2Num, v3Num in modelData.getFaces() :
        x1, y1, _ = modelData.getTransformedVertex( v1Num, doPerspective, doEuler )
        x2, y2, _ = modelData.getTransformedVertex( v2Num, doPerspective, doEuler )
        x3, y3, _ = modelData.getTransformedVertex( v3Num, doPerspective, doEuler )

        canvas.create_line( x1, y1, x2, y2, x3, y3, x1, y1 )
Пример #18
0
  def create_graphic_objects( self, canvas, modelData, doClip, doPerspective, doEuler, resolution ) :
    ax, ay, sx, sy = modelData.getViewport()
    width  = int( canvas.cget( "width" ) )
    height = int( canvas.cget( "height" ) )
    portal = (width*ax, height*ay, width*sx, height*sy)
    pointList = []
    
    if doClip == False:
      for v1Num, v2Num, v3Num in modelData.getFaces() :
        x2, y2, _ = modelData.getTransformedVertex( v2Num, doPerspective, doEuler )
        x1, y1, _ = modelData.getTransformedVertex( v1Num, doPerspective, doEuler )
        x3, y3, _ = modelData.getTransformedVertex( v3Num, doPerspective, doEuler )

        canvas.create_line( x1, y1, x2, y2, x3, y3, x1, y1 )
    else:
      for v1Num, v2Num, v3Num in modelData.getFaces() :
        x1, y1, _ = modelData.getTransformedVertex( v1Num, doPerspective, doEuler )
        x2, y2, _ = modelData.getTransformedVertex( v2Num, doPerspective, doEuler )
        x3, y3, _ = modelData.getTransformedVertex( v3Num, doPerspective, doEuler )

        draw, p1x, p1y, p2x, p2y = clipLine(x1, y1, x2, y2, portal)
        if draw == True:
          canvas.create_line(p1x, p1y, p2x, p2y)
        draw, p1x, p1y, p2x, p2y = clipLine(x2, y2, x3, y3, portal)
        if draw == True:
          canvas.create_line(p1x, p1y, p2x, p2y)
        draw, p1x, p1y, p2x, p2y = clipLine(x3, y3, x1, y1, portal)
        if draw == True:
          canvas.create_line(p1x, p1y, p2x, p2y)

    for p in modelData.getPatches() :
        tCpts = [ modelData.getTransformedVertex(vNum, doPerspective, doEuler) for vNum in p]
        bpts  = resolveBezierPatch(self, resolution, tCpts )
        pointList.append(bpts)

    # tCpts = []
    # for p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16 in modelData.getPatches() :
    #     x1, y1, _ = modelData.getTransformedVertex( p1, doPerspective, doEuler )
    #     x2, y2, _ = modelData.getTransformedVertex( p2, doPerspective, doEuler )
    #     x3, y3, _ = modelData.getTransformedVertex( p3, doPerspective, doEuler )
    #     x4, y4, _ = modelData.getTransformedVertex( p4, doPerspective, doEuler )
    #     x5, y5, _ = modelData.getTransformedVertex( p5, doPerspective, doEuler )
    #     x6, y6, _ = modelData.getTransformedVertex( p6, doPerspective, doEuler )
    #     x7, y7, _ = modelData.getTransformedVertex( p7, doPerspective, doEuler )
    #     x8, y8, _ = modelData.getTransformedVertex( p8, doPerspective, doEuler )
    #     x9, y9, _ = modelData.getTransformedVertex( p9, doPerspective, doEuler )
    #     x10, y10, _  = modelData.getTransformedVertex( p10, doPerspective, doEuler )
    #     x11, y11, _  = modelData.getTransformedVertex( p11, doPerspective, doEuler )
    #     xp12, y12, _ = modelData.getTransformedVertex( p12, doPerspective, doEuler )
    #     x13, y13, _ = modelData.getTransformedVertex( p13, doPerspective, doEuler )
    #     x14, y14, _ = modelData.getTransformedVertex( p14, doPerspective, doEuler )
    #     x15, y15, _ = modelData.getTransformedVertex( p15, doPerspective, doEuler )
    #     x16, y16, _ = modelData.getTransformedVertex( p16, doPerspective, doEuler )


    for row in range(resolution-1):
      rowStart = row * resolution
      
      for col in range(resolution-1):
        here = rowStart + col
        there = here + resolution
        triangleA = ( pointList[here], pointList[there], pointList[there+1] )
        triangleB = ( pointList[there+1], pointList[here+1], pointList[here] )
        
        drawTriangle( self, canvas, triangleA[0], triangleA[1], triangleA[2], portal, doClip )
        drawTriangle( self, canvas, triangleB[0], triangleB[1], triangleB[2], portal, doClip )
Пример #19
0
  def create_graphic_objects(self, canvas, DataSet, doClip = False, doPerspective = False, doEuler = False) :

     viewport = DataSet.getViewport(); faces = DataSet.getFaces()
     portal = []

    #Draw the Viewport rectangle.
     self.objects.append(canvas.create_rectangle
                        (float(viewport[0]) * float(canvas.cget("width")),
                         float(viewport[1]) * float(canvas.cget("height")),
                         float(viewport[2]) * float(canvas.cget("width")),
                         float(viewport[3]) * float(canvas.cget("height"))))

     # create an array to store the xmin, ymin, xmax and ymax values in the pixel
     # the values are the pixel or screen representation of the viewport window

     portal.append(float(viewport[0]) * float(canvas.cget("width")))  # xmin
     portal.append(float(viewport[1]) * float(canvas.cget("height"))) # ymin
     portal.append(float(viewport[2]) * float(canvas.cget("width")))  # xmax
     portal.append(float(viewport[3]) * float(canvas.cget("height"))) # ymax

     print("portal", portal)
     print("do Clip: ", doClip)
     print("do Perspective: ", doPerspective)
     print("do Euler: ", doEuler)

     # For each face from the ModelData instance, get the three vertex numbers for that face then Get from the
     # ModelData instance the transformed vertex coordinates.

     for v1Num, v2Num, v3Num in faces :
        # vertice 1 contains (x1, y1) for the first face value
        v1 = DataSet.getTransformedVertex (v1Num,doPerspective,doEuler)

        # vertice 2 contains (x2, y2) for the second face value
        v2 = DataSet.getTransformedVertex (v2Num,doPerspective,doEuler)

        # vertice 3 contains (x3, y3) for the third face value
        v3 = DataSet.getTransformedVertex (v3Num,doPerspective,doEuler)

        # x and y values of each vertex
        x1 = v1[0];  y1 = v1[1]; x2 = v2[0];  y2 = v2[1]; x3 = v3[0];  y3 = v3[1];

        #create a copy of v1, v2 and v3 so that we don't modify their orignal values
        x1_temp = x1; y1_temp = y1; x2_temp = x2; y2_temp = y2; x3_temp = x3; y3_temp = y3

        # calls the clipLine definition in the Cohensutherland.py
        # checks if the do Draw value is true or false and returns the clipped co-ordinate for given two points
        # if the doDraw value is true then draw the line based on the new points(X1_new, Y1_new, X2_new, Y2_new) returned
        # by the clipping function and draw three lines, v1->v2, v2->v3, and v3->v1

        if doClip:
            # create a copy of v1, v2 and v3 so that we don't modify their orignal values
            #x1_temp = x1; y1_temp = y1; x2_temp = x2; y2_temp = y2; x3_temp = x3; y3_temp = y3
            doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(x1_temp, y1_temp, x2_temp, y2_temp, portal)

            if doDraw:
                self.objects.append(canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
                doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(x2_temp, y2_temp, x3_temp, y3_temp, portal)


            if doDraw:
                self.objects.append(canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))
                doDraw, X1_new, Y1_new, X2_new, Y2_new = clipLine(x3_temp, y3_temp, x1_temp, y1_temp, portal)


            if doDraw:
                self.objects.append(canvas.create_line((X1_new, Y1_new), (X2_new, Y2_new)))

        else:
            #draw three lines, v1->v2, v2->v3, and v3->v1
            self.objects.append(canvas.create_line( (x1,y1),(x2,y2),(x3,y3),(x1,y1) ) )