Example #1
0
    def create(self, division=0):
        # I will improve it later
        # Idea of Cylinder create can be applied here may be
        # Clone probably slow down the process significantly
        step = self.__quadLength / float(2**division)

        self.subdivison = {"number": division}

        self.resetShape()
        self.defineQuad(self, step / 2)

        if (division != 0):
            self.transformShape(Mat3d().defineTranslationMatrix(
                (step / 2.0) - (self.__quadLength / 2.0), 0, 0))

        tmp = self.clone()
        for i in range(2**division - 1):
            tmp.transformShape(Mat3d().defineTranslationMatrix(step, 0, 0))
            self.addVerticesOfShape(tmp)

        if (division != 0):
            self.transformShape(Mat3d().defineTranslationMatrix(
                0, self.__quadLength / 2.0 - (step / 2.0), 0))

        tmp = self.clone()
        for j in range(2**division - 1):
            tmp.transformShape(Mat3d().defineTranslationMatrix(0, -step, 0))
            self.addVerticesOfShape(tmp)

        self.__createBox()
Example #2
0
    def placeRepresentativeShape(self, aMath3d):
        lightBox = self.createRepresentativeShape()

        t = self.__position
        lightBox.addTransformation(Mat3d().defineTranslationMatrix(t.getX(),t.getY(),t.getZ()))
        lightBox.transformShape(Mat3d().defineTranslationMatrix(t.getX(),t.getY(),t.getZ()))

        lightBox.transformShape(aMath3d)
        lightBox.draw()
Example #3
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
Example #4
0
    def rotateMoveShapeTo(self,
                          shapeName,
                          angle,
                          rotAx="Y",
                          transformationSpace=Space.SCENE):
        if (transformationSpace == Space.SCENE):
            shape = self.__shapeListSS.get(shapeName)

            shape.addTransformation(Mat3d().defineRotationMatrix(angle, rotAx))
            shape.transformShape(Mat3d().defineRotationMatrix(angle, rotAx))
        else:
            shape = self.__shapeListLS.get(shapeName)

            shape.addTransformation(Mat3d().defineRotationMatrix(angle, rotAx))
            shape.transformShape(Mat3d().defineRotationMatrix(angle, rotAx))

            self.updateShapeListSS(shapeName)
Example #5
0
    def __createBox(self):
        distance = 1
        angle = self.calculateScanAngle(distance)

        # Quad with 180 degree rotated side by side
        temp = self.transformShape(Mat3d().defineTranslationMatrix(
            0, 0, distance)).clone()
        temp.transformShape(Mat3d().defineRotationMatrix(angle * 2, "Y"))
        self.addVerticesOfShape(temp)

        # Side by side quad rotated around Y
        scanShape = self.clone().transformShape(Mat3d().defineRotationMatrix(
            angle, "Y"))
        self.addVerticesOfShape(scanShape)

        # Side by side quad rotated aroun Z
        scanShape.transformShape(Mat3d().defineRotationMatrix(angle, "Z"))
        self.addVerticesOfShape(scanShape)
Example #6
0
    def linearMoveShapeto(self,
                          shapeName,
                          x,
                          y,
                          z,
                          tranformationSpace=Space.SCENE):
        if (tranformationSpace == Space.SCENE):
            # Scene Space
            shape = self.__shapeListSS.get(shapeName)

            # Shape class logic not work as I expected
            shape.addTransformation(Mat3d().defineTranslationMatrix(x, y, z))
            shape.transformShape(Mat3d().defineTranslationMatrix(x, y, z))
        else:
            # Local Space
            shape = self.__shapeListLS.get(shapeName)

            shape.addTransformation(Mat3d().defineTranslationMatrix(x, y, z))
            shape.transformShape(Mat3d().defineTranslationMatrix(x, y, z))

            self.updateShapeListSS(shapeName)  # Update Scene Space
Example #7
0
    def rotateCamera(self, degree, axis="X"):
        self.__rotated += degree
        radian = self.calculateRadian(self.__rotated)

        self.setFocus(CamFocus.FOCUS_TARGET)
        if (self.__target == None):
            self.setTarget(0, 0, 0)

        if (axis == "X"):
            # derivative
            self.setWorldUp(0, math.cos(radian), math.sin(radian))
        if (axis == "Y"):
            self.setWorldUp(0, 1, 0)
        rotMat = Mat3d().defineRotationMatrix(degree, axis)

        self.__cameraPosition = rotMat.multiplyByVec3d(self.__cameraPosition)

        self.__updateCameraVectors()

        self.setFocus(CamFocus.FREE_MOVE)
Example #8
0
        drawer.setWireWidth(self.__wireWidth)
        
        # Fire the drawer
        drawer.draw()

        #material.applyMaterial()

        

    def clone(self):
        return copy.deepcopy(self)

    def __str__(self):
        output = ""
        for i in self.__verticesList:
            output += i.__str__() + "\n"
        output += "Face List: \n"
        output += self.__faceList.__str__() + "\n"
        return output
        
if __name__ == "__main__":
    a = Shape()
    a.addVertice(1,2,3)
    a.addVertice(1,4,6)

    b = Mat3d()
    b.defineRotationMatrix(30,"Z")

    a.transformShape(b)

    print(a)
Example #9
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))