def load(self): self.root = NodePath('PartyCog-%d' % self.id) self.root.reparentTo(self.parentNode) path = 'phase_13/models/parties/cogPinata_' self.actor = Actor( path + 'actor', { 'idle': path + 'idle_anim', 'down': path + 'down_anim', 'up': path + 'up_anim', 'bodyHitBack': path + 'bodyHitBack_anim', 'bodyHitFront': path + 'bodyHitFront_anim', 'headHitBack': path + 'headHitBack_anim', 'headHitFront': path + 'headHitFront_anim' }) self.actor.reparentTo(self.root) self.temp_transform = Mat4() self.head_locator = self.actor.attachNewNode('temphead') self.bodyColl = CollisionTube(0, 0, 1, 0, 0, 5.75, 0.75) self.bodyColl.setTangible(1) self.bodyCollNode = CollisionNode('PartyCog-%d-Body-Collision' % self.id) self.bodyCollNode.setCollideMask(ToontownGlobals.PieBitmask) self.bodyCollNode.addSolid(self.bodyColl) self.bodyCollNodePath = self.root.attachNewNode(self.bodyCollNode) self.headColl = CollisionTube(0, 0, 3, 0, 0, 3.0, 1.5) self.headColl.setTangible(1) self.headCollNode = CollisionNode('PartyCog-%d-Head-Collision' % self.id) self.headCollNode.setCollideMask(ToontownGlobals.PieBitmask) self.headCollNode.addSolid(self.headColl) self.headCollNodePath = self.root.attachNewNode(self.headCollNode) self.arm1Coll = CollisionSphere(1.6499999999999999, 0, 3.9500000000000002, 1.0) self.arm1Coll.setTangible(1) self.arm1CollNode = CollisionNode('PartyCog-%d-Arm1-Collision' % self.id) self.arm1CollNode.setCollideMask(ToontownGlobals.PieBitmask) self.arm1CollNode.addSolid(self.arm1Coll) self.arm1CollNodePath = self.root.attachNewNode(self.arm1CollNode) self.arm2Coll = CollisionSphere(-1.6499999999999999, 0, 3.4500000000000002, 1.0) self.arm2Coll.setTangible(1) self.arm2CollNode = CollisionNode('PartyCog-%d-Arm2-Collision' % self.id) self.arm2CollNode.setCollideMask(ToontownGlobals.PieBitmask) self.arm2CollNode.addSolid(self.arm2Coll) self.arm2CollNodePath = self.root.attachNewNode(self.arm2CollNode) splatName = 'splat-creampie' self.splat = globalPropPool.getProp(splatName) self.splat.setBillboardPointEye() self.splatType = globalPropPool.getPropType(splatName) self.pieHitSound = globalBattleSoundCache.getSound( 'AA_wholepie_only.mp3') self.upSound = globalBattleSoundCache.getSound('AV_jump_to_side.mp3') self.hole = loader.loadModel('phase_13/models/parties/cogPinataHole') self.hole.setTransparency(True) self.hole.setP(-90.0) self.hole.setScale(3) self.hole.setBin('ground', 3) self.hole.reparentTo(self.parentNode)
def buildWorldToFaceMatrices(self): """ Builds the 4x4 matrices that transform a point from the world coordinates system to the faces' image space. The image space has: a. Its origin at the top left corner of the face. b. The positive x axis running from left to right along the face. c. The positive y axis running from top to bottom along the face. d. Extends between [0.0, 1.0] inside the boundary of the face. """ facesCoords = { PanoConstants.CBM_FRONT_FACE: (-self.faceHalfDim, self.faceHalfDim, self.faceHalfDim, 1, 0, -1), PanoConstants.CBM_BACK_FACE: (self.faceHalfDim, -self.faceHalfDim, self.faceHalfDim, -1, 0, -1), PanoConstants.CBM_RIGHT_FACE: (self.faceHalfDim, self.faceHalfDim, self.faceHalfDim, 0, -1, -1), PanoConstants.CBM_LEFT_FACE: (-self.faceHalfDim, -self.faceHalfDim, self.faceHalfDim, 0, 1, -1), PanoConstants.CBM_TOP_FACE: (-self.faceHalfDim, -self.faceHalfDim, self.faceHalfDim, 1, 1, 0), PanoConstants.CBM_BOTTOM_FACE: (-self.faceHalfDim, self.faceHalfDim, -self.faceHalfDim, 1, -1, 0) } for face, coords in facesCoords.items(): matOffset = Mat4() matOffset.setTranslateMat( VBase3(-coords[0], -coords[1], -coords[2])) matScale = Mat4() matScale.setScaleMat( VBase3(coords[3] / self.faceDim, coords[4] / self.faceDim, coords[5] / self.faceDim)) self.worldToFaceMatrices[face] = matOffset * matScale # when calculating the inverse we will need to divide by the scale, so take care to replace zeros with ones scale = [coords[3], coords[4], coords[5]] for i in range(0, 3): if scale[i] == 0.0: scale[i] = 1 matInvOffset = Mat4() matInvOffset.setTranslateMat( VBase3(coords[0], coords[1], coords[2])) matInvScale = Mat4() matInvScale.setScaleMat( VBase3(self.faceDim / scale[0], self.faceDim / scale[1], self.faceDim / scale[2])) self.faceToWorldMatrices[face] = matInvScale * matInvOffset
def draw_leaf(self, position, vector_list, scale = 0.125): # use the vectors that describe the direction the branch grows # to make the right rotation matrix new_cs = Mat4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) new_cs.setRow(0, vector_list[2]) # right new_cs.setRow(1, vector_list[1]) # up new_cs.setRow(2, vector_list[0]) # forward new_cs.setRow(3, Vec3(0, 0, 0)) new_cs.setCol(3, Vec4(0, 0, 0, 1)) axis_adjustment = Mat4.scaleMat(scale) * new_cs * Mat4.translateMat(position) leaf_model = base.loader.loadModelCopy(APP_PATH + 'media/models/shrubbery') leaf_texture = base.loader.loadTexture(APP_PATH + 'media/models/material-10-cl.png') leaf_model.reparentTo(self.get_model()) leaf_model.setTexture(leaf_texture, 1) leaf_model.setTransform(TransformState.makeMat(axis_adjustment))
def __init__(self): self.base = ShowBase() self.model = self.base.loader.loadModel('device.egg') self.model.reparentTo(self.base.render) self.base.disableMouse() self.base.camera.setPos(0, -10, 0) self.model.setHpr(0,90,0) mat = Mat4(self.base.camera.getMat()) mat.invertInPlace() self.base.mouseInterfaceNode.setMat(mat) self.base.enableMouse() self.screen = self.model.find("**/pantalla") self.list_app = ListApp(self) self.music_app = MusicApp(self) self.dial_app = DialApp(self) self.apps = {} self.events = EventDispatcher(self, "Sony Ericsson W200") self.apps["init"] = InitApp(self) self.apps["Dial"] = self.display_dial_screen self.apps["menu"] = MainMenu(self) self.apps["Reproductor"] = self.play self.apps["Reproductor de Audio"] = self.display_list self.apps["Camara"] = CameraApp(self) self.apps["Album Fotografico"] = PhotoApp(self) self.apps["Llamadas"] = self.display_list self.apps["Contactos"] = self.display_list self.apps["Mensajes"] = self.display_list self.apps["Juegos"] = self.display_list self.apps["Utileria"] = self.display_list self.apps["Reproducir Todas"] = self.play self.apps["Lista de Albums"] = self.list_albums self.apps["Lista de Artistas"] = self.list_artists self.apps["Lista de Contactos"] = self.list_contacts self.apps["Dial Contact"] = self.dial_contact self.apps["Llamadas Perdidas"] = self.list_lost_calls self.apps["Llamadas Contestadas"] = self.list_answered_calls self.apps["Llamadas Marcadas"] = self.list_done_calls self.launch("init")
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.loadModelCopy('models/shrubbery') leafTexture=loader.loadTexture('models/material-10-cl.png') leafModel.reparentTo(nodePath) leafModel.setTexture(leafTexture,1) leafModel.setTransform(TransformState.makeMat(axisAdj))
def Transform(self): # Get the distance the mouse has moved during the drag operation - # compensate for how big the gizmo is on the screen axis = self.GetSelectedAxis() axisPoint = self.GetAxisPoint(axis) distance = (axisPoint - self.startAxisPoint).length() / self.getScale()[0] # Using length() will give us a positive number, which doesn't work if # we're trying to scale down the object. Get the sign for the distance # from the dot of the axis and the mouse direction mousePoint = self.getRelativePoint( self.rootNp, axisPoint) - self.getRelativePoint( self.rootNp, self.startAxisPoint) direction = axis.vector.dot(mousePoint) sign = math.copysign(1, direction) distance = distance * sign # Transform the gizmo if axis.vector == Vec3(1, 1, 1): for otherAxis in self.axes: otherAxis.SetSize(distance + self.size) else: axis.SetSize(distance + self.size) # Use the "complementary" vector if in complementary mode vector = axis.vector if self.complementary: vector = Vec3(1, 1, 1) - axis.vector # Create a scale matrix from the resulting vector scaleVec = vector * (distance + 1) + Vec3(1, 1, 1) - vector newScaleMat = Mat4().scaleMat(scaleVec) # Transform attached node paths for i, np in enumerate(self.attachedNps): # Perform transforms in local or world space if self.local: np.setMat(newScaleMat * self.initNpXforms[i].getMat()) else: transMat, rotMat, scaleMat = commonUtils.GetTrsMatrices( self.initNpXforms[i]) np.setMat(scaleMat * rotMat * newScaleMat * transMat)
def _applyShaderInputs(self): ''' Applies the specified texture, vector and matrix shader inputs. Note: Matrix inputs are applied to a shader through a NodePath whose local transformation matches the matrix. ''' for param, texName in self.texParams.items(): tex = self.game.getResources().loadTexture(texName) if tex is not None: tex.setWrapU(Texture.WMRepeat) tex.setWrapV(Texture.WMRepeat) self.screenQuad.setShaderInput(param, tex) else: self.log.error( 'Failed to set shader input %s because the texture was not found' % texName) for param, val in self.floatParams.items(): self.screenQuad.setShaderInput( param, Vec4(val[0], val[1], val[2], val[3])) if self.nodesRoot is None: self.nodesRoot = render.attachNewNode('k_matrices') for param, val in self.matParams.items(): np = NodePath() np.setName(param + '_transform') mat = Mat4() for i in range(4): mat.setRow( i, Vec4(val[i * 4 + 1], val[i * 4 + 2], val[i * 4 + 3], val[i * 4 + 4])) np.setMat(mat) np.reparentTo(self.nodesRoot) self.screenQuad.setShaderInput(param, np) self._applyPredefinedInputs()
def load(self): self.root = NodePath("PartyCog-%d" % self.id) self.root.reparentTo(self.parentNode) path = "phase_13/models/parties/cogPinata_" self.actor = Actor( path + "actor", { "idle": path + "idle_anim", "down": path + "down_anim", "up": path + "up_anim", "bodyHitBack": path + "bodyHitBack_anim", "bodyHitFront": path + "bodyHitFront_anim", "headHitBack": path + "headHitBack_anim", "headHitFront": path + "headHitFront_anim", }) self.actor.reparentTo(self.root) self.temp_transform = Mat4() self.head_locator = self.actor.attachNewNode("temphead") self.bodyColl = CollisionTube(0, 0, 1, 0, 0, 5.75, 0.75) self.bodyColl.setTangible(1) self.bodyCollNode = CollisionNode("PartyCog-%d-Body-Collision" % self.id) self.bodyCollNode.setCollideMask(ToontownGlobals.PieBitmask) self.bodyCollNode.addSolid(self.bodyColl) self.bodyCollNodePath = self.root.attachNewNode(self.bodyCollNode) self.headColl = CollisionTube(0, 0, 3, 0, 0, 3.0, 1.5) self.headColl.setTangible(1) self.headCollNode = CollisionNode("PartyCog-%d-Head-Collision" % self.id) self.headCollNode.setCollideMask(ToontownGlobals.PieBitmask) self.headCollNode.addSolid(self.headColl) self.headCollNodePath = self.root.attachNewNode(self.headCollNode) # Cog's Left Arm self.arm1Coll = CollisionSphere(1.65, 0, 3.95, 1.0) self.arm1Coll.setTangible(1) self.arm1CollNode = CollisionNode("PartyCog-%d-Arm1-Collision" % self.id) self.arm1CollNode.setCollideMask(ToontownGlobals.PieBitmask) self.arm1CollNode.addSolid(self.arm1Coll) self.arm1CollNodePath = self.root.attachNewNode(self.arm1CollNode) # Cog's Right Arm self.arm2Coll = CollisionSphere(-1.65, 0, 3.45, 1.0) self.arm2Coll.setTangible(1) self.arm2CollNode = CollisionNode("PartyCog-%d-Arm2-Collision" % self.id) self.arm2CollNode.setCollideMask(ToontownGlobals.PieBitmask) self.arm2CollNode.addSolid(self.arm2Coll) self.arm2CollNodePath = self.root.attachNewNode(self.arm2CollNode) splatName = 'splat-creampie' self.splat = globalPropPool.getProp(splatName) self.splat.setBillboardPointEye() self.splatType = globalPropPool.getPropType(splatName) self.pieHitSound = globalBattleSoundCache.getSound( 'AA_wholepie_only.mp3') self.upSound = globalBattleSoundCache.getSound('AV_jump_to_side.mp3') self.hole = loader.loadModel("phase_13/models/parties/cogPinataHole") self.hole.setTransparency(True) self.hole.setP(-90.0) self.hole.setScale(3) self.hole.setBin("ground", 3) self.hole.reparentTo(self.parentNode)
def enableMouseCamControl(self): """Enable Mouse Camera Control""" mat=Mat4(camera.getMat()) mat.invertInPlace() base.mouseInterfaceNode.setMat(mat) base.enableMouse()
def __init__(self): self.devconf = ConfigLoader('./res/models/sony_ericsson_w200.json') #with open('./res/models/sony_ericsson_w200.json') as f: # self.devconf = json.load(f) self.base = ShowBase() self.loader = self.base.loader self.model = self.loader.loadModel(self.devconf.model_path) self.model.reparentTo(self.base.render) self.base.disableMouse() self.base.camera.setPos( self.devconf.initial_position['x'], self.devconf.initial_position['y'], self.devconf.initial_position['z']) self.model.setHpr( self.devconf.model_transformation['x'], self.devconf.model_transformation['y'], self.devconf.model_transformation['z']) mat = Mat4(self.base.camera.getMat()) mat.invertInPlace() self.base.mouseInterfaceNode.setMat(mat) self.base.enableMouse() self.screen = self.model.find(self.devconf.model_texture_path) self.list_app = ListApp(self, self.devconf) #self.music_app = MusicApp(self) self.dial_app = DialApp(self, self.devconf) self.apps = {} self.events = EventDispatcher(self, self.devconf.device_name) self.apps["init"] = InitApp(self, self.devconf) self.apps["Dial"] = self.display_dial_screen self.apps["menu"] = MainMenu(self, self.devconf) #self.apps["Reproductor"] = self.play #self.apps["Reproductor de Audio"] = self.display_list #self.apps["Camara"] = CameraApp(self) #self.apps["Album Fotografico"] = PhotoApp(self) self.apps["Llamadas"] = self.display_list self.apps["Contactos"] = self.display_list self.apps["Mensajes"] = self.display_list self.apps["Juegos"] = self.display_list self.apps["Utileria"] = self.display_list #self.apps["Reproducir Todas"] = self.play #self.apps["Lista de Albums"] = self.list_albums #self.apps["Lista de Artistas"] = self.list_artists #self.apps["Lista de Contactos"] = self.list_contacts #self.apps["Dial Contact"] = self.dial_contact #self.apps["Llamadas Perdidas"] = self.list_lost_calls #self.apps["Llamadas Contestadas"] = self.list_answered_calls #self.apps["Llamadas Marcadas"] = self.list_done_calls self.launch("init")
def Transform( self ): startVec = self.startVec axis = self.GetSelectedAxis() if axis is not None and axis.vector == CAMERA_VECTOR: endVec = self.getRelativeVector( self.rootNp, self.GetAxisPoint( axis ) - self.getPos() ) cross = startVec.cross( endVec ) direction = self.getRelativeVector( self.camera, Vec3(0, -1, 0) ).dot( cross ) sign = math.copysign( 1, direction ) # Get the rotation axis rotAxis = self.getRelativeVector( self.camera, Vec3(0, -1, 0) ) * sign else: if self.collEntry.getIntoNode() == self.initCollEntry.getIntoNode(): endVec = self.collEntry.getSurfaceNormal( self ) else: endVec = self.getRelativeVector( self.rootNp, self.GetAxisPoint( self.foobar ) - self.getPos() ) # If an axis is selected then constrain the vectors by projecting # them onto a plane whose normal is the axis vector if axis is not None: plane = Plane( axis.vector, Point3( 0 ) ) startVec = Vec3( plane.project( Point3( startVec ) ) ) endVec = Vec3( plane.project( Point3( endVec ) ) ) # Get the rotation axis rotAxis = endVec.cross( startVec ) * -1 # Return if the rotation vector is not valid, ie it does not have any # length if not rotAxis.length(): return # Normalize all vectors startVec.normalize() endVec.normalize() rotAxis.normalize() # Get the amount of degrees to rotate degs = startVec.angleDeg( endVec ) # Transform the gizmo if in local rotation mode newRotMat = Mat4().rotateMat( degs, rotAxis ) if self.local: self.setMat( newRotMat * self.getMat() ) # Transform all attached node paths for i, np in enumerate( self.attachedNps ): # Split the transform into scale, rotation and translation # matrices transMat, rotMat, scaleMat = commonUtils.GetTrsMatrices( np.getTransform() ) # Perform transforms in local or world space if self.local: np.setMat( scaleMat * newRotMat * rotMat * transMat ) else: self.initNpXforms[i].getQuat().extractToMatrix( rotMat ) np.setMat( scaleMat * rotMat * newRotMat * transMat )