def mousePressed(self, event): self.parent.beginTransformation() lens = base.cam.node().getLens() scale = Mat4.scaleMat(self.path.getScale(base.camera)) descale = Mat4() descale.invertAffineFrom(scale) mvMat = descale * self.path.getMat(base.camera) origin = Point3(mvMat.xformPoint(Point3())) dir = Vec3(mvMat.xformVec(Vec3(0, 0, 1))) xprod = dir.cross(origin) planeNorm = xprod.cross(dir) planeNorm.normalize() d = planeNorm.dot(origin) self.dir = dir self.origin = origin self.planeNorm = planeNorm self.d = d self.lens = lens self.fromCam = base.camera.getMat(self.parent.path) * scale transl = self.mouse2Vec(event.pos) self.origin = transl + self.origin
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))
def __init__(self): self.instructionText = addInstructions(0.95, '[ESC]: Leave Mouselook mode.') self.eventDispatcher = EventDispatcher() self.cameraMode = None self.clickPos = Vec2() self.lastMousePos = Vec2() self.focus = Vec3() self.mouseDown = False self.initialPos = Vec3() self.initialHpr = Vec3() self.initialMat = None # Disable the built-in mouse camera control (it sucks). base.disableMouse() self.setCameraMode(TRACKBALL) # Set the camera's initial position. base.camera.setPosHpr(0, 12, 30, 180, -70, 0) # Turn off events generated with modifier buttons, e.g. 'shift-a' # This is to keep keyboard control working after you alt-tab out # of the app. base.mouseWatcherNode.setModifierButtons(ModifierButtons()) base.buttonThrowers[0].node().setModifierButtons(ModifierButtons()) # This is a diagonal matrix that keeps track of movement key # state. The first three diagonal entries can be 1, 0, or -1. self.mouseLookTransMat = Mat4.scaleMat(Vec3(0.0, 0.0, 0.0)) # Keep track of how many movement keys are currently pressed. This # lets us short-circuit past a lot of math when no keys are held. self.keysHeld = 0 # Handle events for the movement keys. for key, value in key2MatArgs.items(): self.accept(key, self._moveKeyHandler, value) self.accept('escape', self._escKeyHandler) self.accept('m', self._mKeyHandler) self.accept('mouse1', self._mouseDownHandler, [1]) self.accept('mouse1-up', self._mouseUpHandler, [1]) self.accept('mouse2', self._mouseDownHandler, [2]) self.accept('mouse2-up', self._mouseUpHandler, [2]) self.accept('wheel_up', self._mouseWheelHandler, [1]) self.accept('wheel_down', self._mouseWheelHandler, [-1]) self.modButtons = ModifierButtons() self.modButtons.addButton(KeyboardButton.control()) self.accept('control', self.modButtons.buttonDown, [KeyboardButton.control()]) self.accept('control-up', self.modButtons.buttonUp, [KeyboardButton.control()]) self.accept(base.win.getWindowEvent(), self._windowHandler)
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))
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 mousePressed(self, event): self.parent.beginTransformation() self.lens = base.cam.node().getLens() scale = Mat4.scaleMat(self.path.getScale(base.camera)) descale = Mat4() descale.invertAffineFrom(scale) mvMat = descale * self.path.getMat(base.camera) self.origin = Point3(mvMat.xformPoint(Point3())) self.planeNorm = Vec3(mvMat.xformVec(Vec3(0, 0, 1))) self.planeNorm.normalize() self.d = self.planeNorm.dot(self.origin) self.fromCam = base.camera.getMat(self.parent.path) * scale self.dir = Vec3(self.mouse2Vec(event.pos)) self.dir.normalize()
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))