Esempio n. 1
0
    def __init__(self,
                 materialName,
                 ambient=ambientDefault,
                 diffuse=diffuseDefault,
                 specular=specularDefault,
                 shininess=shininessDefault,
                 emission=emmissionDefault):

        self.__materialName = materialName
        self.__ambient = Vec3d(*ambient)
        self.__diffuse = Vec3d(*diffuse)
        self.__specular = Vec3d(*specular)
        self.__shininess = shininess
        self.__emission = Vec3d(*emission)
Esempio n. 2
0
    def __init__(self,
                 lightName,
                 lightNum,
                 ambient=ambientDefault,
                 diffuse=diffuseDefault,
                 specular=specularDefault):

        self._name = lightName
        self._lightNum = Light.LIGHT_NUM[(lightNum % 8)]
        self._lightStatus = True

        self._ambient = Vec3d(*ambient)
        self._diffuse = Vec3d(*diffuse)
        self._specular = Vec3d(*specular)
Esempio n. 3
0
    def calculateAverageOfVertices(self, vertexList):
        counter = 0
        average = Vec3d(0, 0, 0, 0)
        for vertex in vertexList:
            average.addVec3d(vertex)
            counter += 1

        return average.divideBy(counter)
Esempio n. 4
0
    def __subdivideFace(self, quadFace):
        index = self.getShape().getSize()
        xCenter = Vec3d(0, 0, 0, 0)
        for verticeIndex in quadFace:
            xCenter.addVec3d(self.getShape().getVerticeList()[verticeIndex])
        xCenter.scalarMultiplication(0.25)
        self.getShape().getVerticeList().append(xCenter)
        xCenterIndex = index

        x1 = Vec3d(0, 0, 0, 0)
        x1.addVec3d(self.getShape().getVerticeList()[quadFace[0]]).addVec3d(
            self.getShape().getVerticeList()[
                quadFace[1]]).scalarMultiplication(0.5)
        self.getShape().getVerticeList().append(x1)
        x1Index = index + 1

        x2 = Vec3d(0, 0, 0, 0)
        x2.addVec3d(self.getShape().getVerticeList()[quadFace[1]]).addVec3d(
            self.getShape().getVerticeList()[
                quadFace[2]]).scalarMultiplication(0.5)
        self.getShape().getVerticeList().append(x2)
        x2Index = index + 2

        x3 = Vec3d(0, 0, 0, 0)
        x3.addVec3d(self.getShape().getVerticeList()[quadFace[2]]).addVec3d(
            self.getShape().getVerticeList()[
                quadFace[3]]).scalarMultiplication(0.5)
        self.getShape().getVerticeList().append(x3)
        x3Index = index + 3

        x4 = Vec3d(0, 0, 0, 0)
        x4.addVec3d(self.getShape().getVerticeList()[quadFace[0]]).addVec3d(
            self.getShape().getVerticeList()[
                quadFace[3]]).scalarMultiplication(0.5)
        self.getShape().getVerticeList().append(x4)
        x4Index = index + 4

        self.getShape().setSize(self.getShape().getSize() + 5)

        faceList = [[x1Index, quadFace[1], x2Index, xCenterIndex],
                    [x2Index, quadFace[2], x3Index, xCenterIndex],
                    [x3Index, quadFace[3], x4Index, xCenterIndex],
                    [x4Index, quadFace[0], x1Index, xCenterIndex]]

        return faceList
Esempio n. 5
0
    def __init__(self, lightName, lightNum, 
                    ambient = Light.ambientDefault,
                    diffuse = Light.diffuseDefault, 
                    specular = Light.specularDefault,
                    direction = directionDefault):
        
        Light.__init__(self, lightName, lightNum, ambient, diffuse, specular)

        self.__direction = Vec3d(direction[0], direction[1], direction[2], 0.0)
Esempio n. 6
0
    def __updateCameraVectors(self):
        # Calculate front vector
        frontX = math.cos(self.calculateRadian(self.__pitch)) * math.sin(
            self.calculateRadian(self.__yaw))
        frontY = math.sin(self.calculateRadian(self.__pitch))
        frontZ = math.cos(self.calculateRadian(self.__pitch)) * math.cos(
            self.calculateRadian(self.__yaw))

        self.__cameraFront = Vec3d(-frontX, -frontY, -frontZ, 0).normalize()
        # End

        self.updateCamera()
Esempio n. 7
0
    def __defineCameraMatrix(self, rightVector, upVector, directionVector,
                             camPosition):
        lookAt = Mat3d()
        translation = Mat3d()
        translation.defineTranslationMatrix(-camPosition.getX(),
                                            -camPosition.getY(),
                                            -camPosition.getZ())
        lookAt.defineMatrix(rightVector, upVector, directionVector,
                            Vec3d(0, 0, 0, 1.0))

        lookAt.multiplyByMat3d(translation)

        return lookAt
Esempio n. 8
0
    def __init__(self, lightName, lightNum, 
                    ambient = Light.ambientDefault,
                    diffuse = Light.diffuseDefault, 
                    specular = Light.specularDefault,
                    position = positionDefault,
                    atConstant = constantAttenuationDefault,
                    atLinear = linearAttenuationDefault,
                    atQuadratic = quadraticAttnuationDefault,
                    cutoff = cutoffDefault,
                    direction = directionDefault,
                    exponent = exponentDefault):
        
        Light.__init__(self, lightName, lightNum, ambient, diffuse, specular)

        self.__position = Vec3d(position[0], position[1], position[2], 1)

        self.__atConstant = atConstant
        self.__atLinear = atLinear
        self.__atQuadratic = atQuadratic

        self.__cutoff = cutoff
        self.__direction = Vec3d(direction[0], direction[1], direction[2], 0)
        self.__exponent = exponent
Esempio n. 9
0
    def calculateVertexPoint(self, vertexNum):
        if (vertexNum in self.__vertexPointDict):
            return self.__vertexPointDict[vertexNum]

        mesh = self.getMesh()
        vertexPoint = Vec3d(0, 0, 0, 0)

        valence = self.findValenceOfVertex(vertexNum)
        valueQ = self.calculateQ(vertexNum)
        valueR = self.calculateR(vertexNum)
        valueS = mesh.getVertex(vertexNum)

        # (Q + 2R + S(n - 3)) / n
        vertexPoint.addVec3d(valueQ).addVec3d(
            valueR.scalarMultiplication(2.0)).addVec3d(
                valueS.scalarMultiplication(
                    (valence - 3))).divideBy(float(valence))

        index = self.addVertex(vertexPoint)
        self.__vertexPointDict[vertexNum] = index

        return index
Esempio n. 10
0
 def setWorldUp(self, x, y, z):
     self.__worldUp = Vec3d(x, y, z, 0)
Esempio n. 11
0
 def setCameraFront(self, x, y, z):
     self.__cameraFront = Vec3d(x, y, z, 0)
Esempio n. 12
0
 def setCameraPosition(self, x, y, z):
     self.__cameraPosition = Vec3d(x, y, z, 1)
Esempio n. 13
0
 def setTarget(self, targetX, targetY, targetZ):
     self.__target = Vec3d(targetX, targetY, targetZ, 0)
Esempio n. 14
0
 def addVertice(self, vx, vy, vz):
     self.__verticesList.append(Vec3d(vx, vy, vz, 1))
     self.__size += 1
     return self
Esempio n. 15
0
    def updatePosition(self, x, y, z):
        newX = self.__position.getX() + x
        newY = self.__position.getY() + y
        newZ = self.__position.getZ() + z

        self.__position = Vec3d(newX, newY, newZ, 1.0)
Esempio n. 16
0
 def __identityMatrix(self):
     return Mat3d().defineMatrix(Vec3d(1, 0, 0, 0), Vec3d(0, 1, 0, 0),
                                 Vec3d(0, 0, 1, 0), Vec3d(0, 0, 0, 1))