Ejemplo n.º 1
0
 def updateWindowPoints(self):
     rayLength = math.sqrt(
         math.pow(self.windowDistance, 2) +
         math.pow((.5 * self.windowSize[0]), 2))
     leftAngle = -math.atan(
         (self.windowSize[0] * .5) / (self.windowDistance))
     rightAngle = -leftAngle
     leftAngle += self.cartesianAngle
     rightAngle += self.cartesianAngle
     leftPointXVal = rayLength * math.sin(leftAngle)
     leftPointYVal = rayLength * math.cos(leftAngle)
     rightPointXVal = rayLength * math.sin(rightAngle)
     rightPointYVal = rayLength * math.cos(rightAngle)
     upperZValue = self.windowSize[1] * .5
     lowerZValue = -self.windowSize[1] * .5
     upperLeft = Point3D()
     lowerLeft = Point3D()
     upperRight = Point3D()
     lowerRight = Point3D()
     upperLeft.setXValue(leftPointXVal)
     lowerLeft.setXValue(leftPointXVal)
     upperRight.setXValue(rightPointXVal)
     lowerRight.setXValue(rightPointXVal)
     upperLeft.setYValue(leftPointYVal)
     lowerLeft.setYValue(leftPointYVal)
     upperRight.setYValue(rightPointYVal)
     lowerRight.setYValue(rightPointYVal)
     upperLeft.setZValue(upperZValue)
     upperRight.setZValue(upperZValue)
     lowerLeft.setZValue(lowerZValue)
     lowerRight.setZValue(lowerZValue)
     windowPoints = [upperLeft, upperRight, lowerLeft, lowerRight]
     self.window.setPoints(windowPoints)
Ejemplo n.º 2
0
 def __init__(self,
              focalPoint=Point3D(),
              vanishPoint=Point3D(),
              windowSize=(500.0, 300.0),
              windowDistance=10.0):
     self.focalPoint = focalPoint
     self.vanishPoint = vanishPoint
     self.windowSize = windowSize
     self.windowDistance = windowDistance
     vanishPoint.setYValue(100.0)
     self.setVanishPoint(vanishPoint)
     self.setViewField()
     self.updateWindowPoints()
Ejemplo n.º 3
0
 def getWindowCenter(self):
     twoPointsOp = TwoPointsOperation(self.focalPoint, self.vanishPoint)
     pitch = twoPointsOp.getPitch(self.focalPoint, self.vanishPoint)
     # yaw = twoPointsOp.getYaw(self.focalPoint, self.vanishPoint)
     yaw = self.getCartesianAngle()
     zValue = self.getZValue(pitch, self.windowDistance)
     xValue = self.getXValue(yaw, self.windowDistance)
     yValue = self.getYValue(yaw, self.windowDistance)
     returnPoint3D = Point3D()
     returnPoint3D.setXValue(xValue)
     returnPoint3D.setYValue(yValue)
     returnPoint3D.setZValue(zValue)
     return returnPoint3D
Ejemplo n.º 4
0
 def rotateRight(self):  # rotate camera right by 1 degree
     degree = math.radians(1.0)
     self.changeCartesianAngle(degree)
     newVanishPoint = Point3D()
     newVanishPoint.setXValue(self.viewField *
                              math.sin(self.getCartesianAngle()))
     newVanishPoint.setYValue(self.viewField *
                              math.cos(self.getCartesianAngle()))
     self.setVanishPoint(newVanishPoint)
     self.updateWindowPoints()
     print(self.cartesianAngle)
     print('windowValues after right rotation')
     self.window.printPointValues()
     print('break')
def getIntersectionWithWindow(camera, pointInSpace):
    points = camera.window.getPoints()
    normalVector = getNormalVector(camera)
    constantD = (points[0].getXVal() * normalVector[0]) + (
        points[0].getYVal() * normalVector[1]) + (points[0].getZVal() *
                                                  normalVector[2])
    topOfT = (constantD - (normalVector[0] * camera.focalPoint.getXVal()) -
              (normalVector[1] * camera.focalPoint.getYVal()) -
              (normalVector[2] * camera.focalPoint.getZVal()))
    bottomOfT = ((normalVector[0] * pointInSpace.getXVal()) -
                 (normalVector[0] * camera.focalPoint.getXVal()) +
                 (normalVector[1] * pointInSpace.getYVal()) -
                 (normalVector[1] * camera.focalPoint.getYVal()) +
                 (normalVector[2] * pointInSpace.getZVal()) -
                 (normalVector[2] * camera.focalPoint.getZVal()))
    t = topOfT / bottomOfT
    intersectingPoint = Point3D()
    intersectingPoint.setXValue(camera.focalPoint.getXVal() + (
        t * (pointInSpace.getXVal() - camera.focalPoint.getXVal())))
    intersectingPoint.setYValue(camera.focalPoint.getYVal() + (
        t * (pointInSpace.getYVal() - camera.focalPoint.getYVal())))
    intersectingPoint.setZValue(camera.focalPoint.getZVal() + (
        t * (pointInSpace.getZVal() - camera.focalPoint.getZVal())))
    return intersectingPoint
Ejemplo n.º 6
0
class Camera():
    focalPoint = Point3D()
    vanishPoint = Point3D()
    viewField = 0.0
    windowSize = [500.0, 300.0]
    windowDistance = 10.0
    cartesianAngle = 0.0
    verticalAngle = 0.0
    window = Plane()

    def __init__(self,
                 focalPoint=Point3D(),
                 vanishPoint=Point3D(),
                 windowSize=(500.0, 300.0),
                 windowDistance=10.0):
        self.focalPoint = focalPoint
        self.vanishPoint = vanishPoint
        self.windowSize = windowSize
        self.windowDistance = windowDistance
        vanishPoint.setYValue(100.0)
        self.setVanishPoint(vanishPoint)
        self.setViewField()
        self.updateWindowPoints()

    def setWindowSize(self, values):
        self.windowSize = values

    def setViewField(self):
        formulaInstance = TwoPointsOperation(self.getFocalPoint(),
                                             self.getVanishPoint())
        newViewField = formulaInstance.getDirectDistance(
            self.getFocalPoint(), self.getVanishPoint())
        self.viewField = newViewField

    def setFocalPoint(self, point):
        self.focalPoint = point

    def setVanishPoint(self, point):
        self.vanishPoint = point

    def setWindowDistance(self, value):
        self.windowDistance = value

    def getFocalPoint(self):
        return self.focalPoint

    def getVanishPoint(self):
        return self.vanishPoint

    def updateWindowPoints(self):
        rayLength = math.sqrt(
            math.pow(self.windowDistance, 2) +
            math.pow((.5 * self.windowSize[0]), 2))
        leftAngle = -math.atan(
            (self.windowSize[0] * .5) / (self.windowDistance))
        rightAngle = -leftAngle
        leftAngle += self.cartesianAngle
        rightAngle += self.cartesianAngle
        leftPointXVal = rayLength * math.sin(leftAngle)
        leftPointYVal = rayLength * math.cos(leftAngle)
        rightPointXVal = rayLength * math.sin(rightAngle)
        rightPointYVal = rayLength * math.cos(rightAngle)
        upperZValue = self.windowSize[1] * .5
        lowerZValue = -self.windowSize[1] * .5
        upperLeft = Point3D()
        lowerLeft = Point3D()
        upperRight = Point3D()
        lowerRight = Point3D()
        upperLeft.setXValue(leftPointXVal)
        lowerLeft.setXValue(leftPointXVal)
        upperRight.setXValue(rightPointXVal)
        lowerRight.setXValue(rightPointXVal)
        upperLeft.setYValue(leftPointYVal)
        lowerLeft.setYValue(leftPointYVal)
        upperRight.setYValue(rightPointYVal)
        lowerRight.setYValue(rightPointYVal)
        upperLeft.setZValue(upperZValue)
        upperRight.setZValue(upperZValue)
        lowerLeft.setZValue(lowerZValue)
        lowerRight.setZValue(lowerZValue)
        windowPoints = [upperLeft, upperRight, lowerLeft, lowerRight]
        self.window.setPoints(windowPoints)

    def getCartesianAngle(self):
        return self.cartesianAngle

    def getWindowCenter(self):
        twoPointsOp = TwoPointsOperation(self.focalPoint, self.vanishPoint)
        pitch = twoPointsOp.getPitch(self.focalPoint, self.vanishPoint)
        # yaw = twoPointsOp.getYaw(self.focalPoint, self.vanishPoint)
        yaw = self.getCartesianAngle()
        zValue = self.getZValue(pitch, self.windowDistance)
        xValue = self.getXValue(yaw, self.windowDistance)
        yValue = self.getYValue(yaw, self.windowDistance)
        returnPoint3D = Point3D()
        returnPoint3D.setXValue(xValue)
        returnPoint3D.setYValue(yValue)
        returnPoint3D.setZValue(zValue)
        return returnPoint3D

    def getZValue(self, angle, distance):
        sine = math.sin(angle)
        value = (distance * sine) + self.focalPoint.getZVal()
        return value

    def getXValue(self, angle, distance):
        sine = math.sin(angle)
        value = (distance * sine) + self.focalPoint.getXVal()
        return value

    def getViewField(self):
        return self.viewField

    def getYValue(self, angle, distance):
        cosine = math.cos(angle)
        value = (distance * cosine) + self.focalPoint.getYVal()
        return value

    def changeCartesianAngle(self, angleChange):
        self.cartesianAngle += angleChange

    def rotateLeft(self):  # rotate camera left by 1 degree
        degree = math.radians(-1.0)
        self.changeCartesianAngle(degree)
        newVanishPoint = Point3D()
        newVanishPoint.setXValue(self.viewField *
                                 math.sin(self.getCartesianAngle()))
        newVanishPoint.setYValue(self.viewField *
                                 math.cos(self.getCartesianAngle()))
        self.setVanishPoint(newVanishPoint)
        self.updateWindowPoints()
        print(self.cartesianAngle)
        print('windowValues after left rotation')
        self.window.printPointValues()
        print('break')

    def rotateRight(self):  # rotate camera right by 1 degree
        degree = math.radians(1.0)
        self.changeCartesianAngle(degree)
        newVanishPoint = Point3D()
        newVanishPoint.setXValue(self.viewField *
                                 math.sin(self.getCartesianAngle()))
        newVanishPoint.setYValue(self.viewField *
                                 math.cos(self.getCartesianAngle()))
        self.setVanishPoint(newVanishPoint)
        self.updateWindowPoints()
        print(self.cartesianAngle)
        print('windowValues after right rotation')
        self.window.printPointValues()
        print('break')
class TwoPointsOperation():
    pointOne = Point3D()
    pointTwo = Point3D()

    def __init__(self, pointOne, pointTwo):
        self.pointOne = pointOne
        self.pointTwo = pointTwo

    def getPitch(self, pointOne, pointTwo):
        oppositeSideLength = self.getVerticalDistance(pointOne, pointTwo)
        sideOneLength = self.getYDistance(pointOne, pointTwo)
        sideTwoLength = self.getDirectDistance(pointOne, pointTwo)
        cosine = self.getCosFromSides(oppositeSideLength, sideOneLength,
                                      sideTwoLength)
        pitch = math.acos(cosine)
        return pitch

    def getYaw(self, pointOne, pointTwo
               ):  # This will need to be fixed to accomodate negative angles
        oppositeSideLength = self.getHorizontalXDistance(pointOne, pointTwo)
        sideOneLength = self.getHorizontalYDistance(pointOne, pointTwo)
        sideTwoLength = self.getDirectDistance(pointOne, pointTwo)
        cosine = self.getCosFromSides(oppositeSideLength, sideOneLength,
                                      sideTwoLength)
        pitch = math.acos(cosine)
        return pitch

    def getYDistance(self, pointOne, pointTwo):
        x1 = pointOne.getXVal()
        x2 = pointTwo.getXVal()
        y1 = pointOne.getYVal()
        y2 = pointTwo.getYVal()
        distance = math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
        return distance

    def getHorizontalXDistance(self, pointOne, pointTwo):
        x1 = pointOne.getXVal()
        x2 = pointTwo.getXVal()
        return x2 - x1

    def getHorizontalYDistance(self, pointOne, pointTwo):
        y1 = pointOne.getYVal()
        y2 = pointTwo.getYVal()
        return y2 - y1

    def getVerticalDistance(self, pointOne, pointTwo):
        z1 = pointOne.getZVal()
        z2 = pointTwo.getZVal()
        return z2 - z1

    def getDirectDistance(self, pointOne, pointTwo):
        x1 = pointOne.getXVal()
        x2 = pointTwo.getXVal()
        y1 = pointOne.getYVal()
        y2 = pointTwo.getYVal()
        z1 = pointOne.getZVal()
        z2 = pointTwo.getZVal()
        distance = math.sqrt(((x2 - x1) * (x2 - x1)) +
                             ((y2 - y1) * (y2 - y1)) + ((z2 - z1) * (z2 - z1)))
        return distance

    def getCosFromSides(self, oppositeSide, sideOne, sideTwo):
        if (sideOne == 0):
            return 1.0
        elif (sideTwo == 0):
            return 0.0
        cosine = (math.pow(sideOne, 2) + math.pow(sideTwo, 2) -
                  math.pow(oppositeSide, 2)) / (2 * sideOne * sideTwo)
        return cosine