Ejemplo n.º 1
0
    def _trackballTask(self, task):
        if not self.mouseDown:
            return Task.cont

        if (base.mouseWatcherNode.hasMouse()):
            mpos = base.mouseWatcherNode.getMouse()
            if mpos == self.lastMousePos:
                return Task.cont

            mDelta = mpos - self.clickPos

            heading = -mDelta.x * 100 + self.initialHpr.x
            pitch = mDelta.y * 100 + self.initialHpr.y
            if pitch > 90:
                pitch = 90
            elif pitch < -90:
                pitch = -90
            trans1 = Mat4.translateMat(self.focus)
            rotx = Mat4.rotateMat(heading, Vec3(0, 0, 1))
            roty = Mat4.rotateMat(pitch, Vec3(1, 0, 0))
            trans2 = Mat4.translateMat(0, -self.initialTranslation, 0)
            rotation = trans2 * roty * rotx * trans1
            base.camera.setMat(rotation)
            self.eventDispatcher.dispatchEvent(EVT_CAMERA_MOVE, base.camera)

            self.lastMousePos = Vec2(mpos)
        return Task.cont
Ejemplo n.º 2
0
    def _trackballTask(self, task):
        if not self.mouseDown:
            return Task.cont

        if (base.mouseWatcherNode.hasMouse()):
            mpos = base.mouseWatcherNode.getMouse()
            if mpos == self.lastMousePos:
                return Task.cont

            mDelta = mpos - self.clickPos

            heading = -mDelta.x * 100 + self.initialHpr.x
            pitch = mDelta.y * 100 + self.initialHpr.y
            if pitch > 90:
                pitch = 90
            elif pitch < -90:
                pitch = -90
            trans1 = Mat4.translateMat(self.focus)
            rotx = Mat4.rotateMat(heading, Vec3(0, 0, 1))
            roty = Mat4.rotateMat(pitch, Vec3(1, 0, 0))
            trans2 = Mat4.translateMat(0, -self.initialTranslation, 0)
            rotation = trans2 * roty * rotx * trans1
            base.camera.setMat(rotation)
            self.eventDispatcher.dispatchEvent(EVT_CAMERA_MOVE, base.camera)
            
            self.lastMousePos = Vec2(mpos)
        return Task.cont
Ejemplo n.º 3
0
def drawLeaf(nodePath,
             vdata,
             pos=Vec3(0, 0, 0),
             vecList=[Vec3(0, 0, 1),
                      Vec3(1, 0, 0),
                      Vec3(0, -1, 0)],
             scale=0.125):

    #use the vectors that describe the direction the branch grows to make the right
    #rotation matrix
    newCs = Mat4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    newCs.setRow(0, vecList[2])  #right
    newCs.setRow(1, vecList[1])  #up
    newCs.setRow(2, vecList[0])  #forward
    newCs.setRow(3, Vec3(0, 0, 0))
    newCs.setCol(3, Vec4(0, 0, 0, 1))

    axisAdj = Mat4.scaleMat(scale) * newCs * Mat4.translateMat(pos)

    #orginlly made the leaf out of geometry but that didnt look good
    #I also think there should be a better way to handle the leaf texture other than
    #hardcoding the filename
    leafModel = loader.loadModel('models/shrubbery')
    leafTexture = loader.loadTexture('models/material-10-cl.png')

    leafModel.reparentTo(nodePath)
    leafModel.setTexture(leafTexture, 1)
    leafModel.setTransform(TransformState.makeMat(axisAdj))
Ejemplo n.º 4
0
 def drawLeaf(self, pos=Vec3(0, 0, 0), quat=None, scale=0.125):
     """
     this draws leafs when we reach an end
     """
     #use the vectors that describe the direction the branch grows to make
     #the right rotation matrix
     newCs = Mat4()
     quat.extractToMatrix(newCs)
     axisAdj = Mat4.scaleMat(scale) * newCs * Mat4.translateMat(pos)
     leafModel = NodePath("leaf")
     self.leafModel.instanceTo(leafModel)
     leafModel.reparentTo(self.leaves)
     leafModel.setTransform(TransformState.makeMat(axisAdj))
Ejemplo n.º 5
0
def draw_leaf(nodePath, vdata, pos=Vec3(0, 0, 0), vecList=[Vec3(0, 0, 1), Vec3(1, 0, 0), Vec3(0, -1, 0)], scale=0.125):

    # use the vectors that describe the direction the branch grows to make the right
    # rotation matrix
    newCs = Mat4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    newCs.setRow(0, vecList[2])  # right
    newCs.setRow(1, vecList[1])  # up
    newCs.setRow(2, vecList[0])  # forward
    newCs.setRow(3, Vec3(0, 0, 0))
    newCs.setCol(3, Vec4(0, 0, 0, 1))

    try:
        axisAdj = Mat4.scaleMat(scale) * newCs * Mat4.translateMat(pos)
    except TypeError, e:
        print e
        print scale, pos
Ejemplo n.º 6
0
def draw_leaf(nodePath,
              vdata,
              pos=Vec3(0, 0, 0),
              vecList=[Vec3(0, 0, 1),
                       Vec3(1, 0, 0),
                       Vec3(0, -1, 0)],
              scale=0.125):

    #use the vectors that describe the direction the branch grows to make the right
    #rotation matrix
    newCs = Mat4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    newCs.setRow(0, vecList[2])  #right
    newCs.setRow(1, vecList[1])  #up
    newCs.setRow(2, vecList[0])  #forward
    newCs.setRow(3, Vec3(0, 0, 0))
    newCs.setCol(3, Vec4(0, 0, 0, 1))

    try:
        axisAdj = Mat4.scaleMat(scale) * newCs * Mat4.translateMat(pos)
    except TypeError, e:
        print e
        print scale, pos
def drawLeaf(nodePath,vdata,pos=Vec3(0,0,0),vecList=[Vec3(0,0,1), Vec3(1,0,0),Vec3(0,-1,0)], scale=0.125):
	
	#use the vectors that describe the direction the branch grows to make the right 
		#rotation matrix
	newCs=Mat4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
	newCs.setRow(0, vecList[2]) #right
	newCs.setRow(1, vecList[1]) #up
	newCs.setRow(2, vecList[0]) #forward
	newCs.setRow(3, Vec3(0,0,0))
	newCs.setCol(3,Vec4(0,0,0,1))

	axisAdj=Mat4.scaleMat(scale)*newCs*Mat4.translateMat(pos)	
	
	#orginlly made the leaf out of geometry but that didnt look good
	#I also think there should be a better way to handle the leaf texture other than
	#hardcoding the filename
	leafModel=loader.loadModel('models/shrubbery')
	leafTexture=loader.loadTexture('models/material-10-cl.png')


	leafModel.reparentTo(nodePath)
	leafModel.setTexture(leafTexture,1)
	leafModel.setTransform(TransformState.makeMat(axisAdj))
Ejemplo n.º 8
0
 def _mouseWheelHandler(self, arg):
     deltY = base.camera.getPos().length() * arg * 0.15
     transl = Mat4.translateMat(0, deltY, 0)
     base.camera.setMat(transl * base.camera.getMat())
     self.eventDispatcher.dispatchEvent(EVT_CAMERA_MOVE, base.camera)
Ejemplo n.º 9
0
 def mouseMoved(self, event):
     transl = self.fromCam.xformVec(self.mouse2Vec(event.pos))
     self.parent.transform(Mat4.translateMat(transl))
Ejemplo n.º 10
0
 def _mouseWheelHandler(self, arg):
     deltY = base.camera.getPos().length() * arg * 0.15
     transl = Mat4.translateMat(0, deltY, 0)
     base.camera.setMat(transl * base.camera.getMat())
     self.eventDispatcher.dispatchEvent(EVT_CAMERA_MOVE, base.camera)
Ejemplo n.º 11
0
 def mouseMoved(self, event):
     transl = self.fromCam.xformVec(self.mouse2Vec(event.pos))
     self.parent.transform(Mat4.translateMat(transl))