def _initCollisions(self): self.collPlane = CollisionPlane(Plane(Vec3(0, 0, 1.0), Point3(0, 0, 10))) self.collPlane.setTangible(0) self.collNode = CollisionNode('fogPlane') self.collNode.setIntoCollideMask(OTPGlobals.FloorBitmask) self.collNode.addSolid(self.collPlane) self.collNodePath = self.root.attachNewNode(self.collNode) self.collNodePath.hide()
def updateFanVelocity(self, dt): fanHeight = Globals.Gameplay.FanCollisionTubeHeight min = Globals.Gameplay.FanMinPower max = Globals.Gameplay.FanMaxPower powerRange = max - min for fan in self.activeFans: blowVec = fan.getBlowDirection() blowVec *= Globals.Gameplay.ToonAcceleration['fan'] * dt if Globals.Gameplay.UseVariableFanPower: distance = fan.model.getDistance(self.toon) power = math.fabs(distance / fanHeight - 1.0) * powerRange + min power = clamp(power, min, max) blowVec *= power if fan.index in self.fanIndex2ToonVelocity: fanVelocity = self.fanIndex2ToonVelocity[fan.index] fanVelocity += blowVec removeList = [] for fan in self.fansStillHavingEffect: if fan not in self.activeFans: blowVec = fan.getBlowDirection() blowVec *= Globals.Gameplay.ToonDeceleration['fan'] * dt if fan.index in self.fanIndex2ToonVelocity: fanVelocity = Vec3(self.fanIndex2ToonVelocity[fan.index]) lastLen = fanVelocity.length() fanVelocity -= blowVec if fanVelocity.length() > lastLen: removeList.append(fan) else: self.fanIndex2ToonVelocity[fan.index] = fanVelocity for fan in removeList: self.fansStillHavingEffect.remove(fan) if fan.index in self.fanIndex2ToonVelocity: del self.fanIndex2ToonVelocity[fan.index] self.fanVelocity = Vec3(0.0, 0.0, 0.0) for fan in self.fansStillHavingEffect: if fan.index in self.fanIndex2ToonVelocity: self.fanVelocity += self.fanIndex2ToonVelocity[fan.index] minVal = -Globals.Gameplay.ToonVelMax['fan'] maxVal = Globals.Gameplay.ToonVelMax['fan'] self.fanVelocity[0] = clamp(self.fanVelocity[0], minVal, maxVal) self.fanVelocity[1] = clamp(self.fanVelocity[1], minVal, maxVal) self.fanVelocity[2] = clamp(self.fanVelocity[2], minVal, maxVal)
def turnDown(self, doInterval = DoIntervalDefault): self.faceUp = 0 if doInterval: self.clearFlipIval() self.flipIval = Parallel(LerpHprInterval(self, self.FlipTime, Vec3(0, 0, 180)), SoundInterval(self.turnDownSound, node = self, listenerNode = base.localAvatar, cutOff = 240)) self.flipIval.start() else: self.setR(180)
def setupVarsNPs(self): self.root = render.attachNewNode("Root") self.dirNP = self.root.attachNewNode("DirNP") self.refNP = self.root.attachNewNode("RefNP") self.dirVec = Vec3(0,0,0) self.cycleVec = Vec3(0,0,0) self.refVec = Vec3(0,0,0) self.speed = 0 self.throttle = 0 self.maxSpeed = 200 self.accel = 25 self.handling = 20 self.cycle = loader.loadModel("../Models/Cycle.bam") self.cycle.reparentTo(self.root) self.root.setPos(2,15,0) base.camera.reparentTo(self.dirNP) base.camera.setY(base.camera, -5)
def announceGenerate(self): DistributedElevatorExt.DistributedElevatorExt.announceGenerate(self) angle = self.startingHpr[0] angle -= 90 radAngle = deg2Rad(angle) unitVec = Vec3(math.cos(radAngle), math.sin(radAngle), 0) unitVec *= 45.0 self.endPos = self.startingPos + unitVec self.endPos.setZ(0.5) dist = Vec3(self.endPos - self.enteringPos).length() wheelAngle = dist / (4.8 * 1.4 * math.pi) * 360 self.kartEnterAnimateInterval = Parallel(LerpHprInterval(self.wheels[0], 5.0, Vec3(self.wheels[0].getH(), wheelAngle, self.wheels[0].getR())), LerpHprInterval(self.wheels[1], 5.0, Vec3(self.wheels[1].getH(), wheelAngle, self.wheels[1].getR())), LerpHprInterval(self.wheels[2], 5.0, Vec3(self.wheels[2].getH(), wheelAngle, self.wheels[2].getR())), LerpHprInterval(self.wheels[3], 5.0, Vec3(self.wheels[3].getH(), wheelAngle, self.wheels[3].getR())), name='CogKartAnimate') trolleyExitTrack1 = Parallel(LerpPosInterval(self.golfKart, 5.0, self.endPos), self.kartEnterAnimateInterval, name='CogKartExitTrack') self.trolleyExitTrack = Sequence(trolleyExitTrack1) self.trolleyEnterTrack = Sequence(LerpPosInterval(self.golfKart, 5.0, self.startingPos, startPos=self.enteringPos)) self.closeDoors = Sequence(self.trolleyExitTrack, Func(self.onDoorCloseFinish)) self.openDoors = Sequence(self.trolleyEnterTrack)
def __init__(self): base.disableMouse() # This disables the default mouse based camera control used by panda. This default control is awkward, and won't be used. base.camera.setPos(0,20,20) base.camera.lookAt(0,0,0) # Gives the camera an initial position and rotation. self.mx,self.my=0,0 # Sets up variables for storing the mouse coordinates self.orbiting=False # A boolean variable for specifying whether the camera is in orbiting mode. Orbiting mode refers to when the camera is being moved # because the user is holding down the right mouse button. self.target=Vec3() # sets up a vector variable for the camera's target. The target will be the coordinates that the camera is currently focusing on. self.camDist = 40 # A variable that will determine how far the camera is from it's target focus self.panRateDivisor = 20 # This variable is used as a divisor when calculating how far to move the camera when panning. Higher numbers will yield slower panning # and lower numbers will yield faster panning. This must not be set to 0. self.panZoneSize = .15 # This variable controls how close the mouse cursor needs to be to the edge of the screen to start panning the camera. It must be less than 1, # and I recommend keeping it less than .2 self.panLimitsX = Vec2(-20, 20) self.panLimitsY = Vec2(-20, 20) # These two vairables will serve as limits for how far the camera can pan, so you don't scroll away from the map. self.setTarget(0,0,0) # calls the setTarget function to set the current target position to the origin. self.turnCameraAroundPoint(0,0) # calls the turnCameraAroundPoint function with a turn amount of 0 to set the camera position based on the target and camera distance self.accept("mouse3",self.startOrbit) # sets up the camrea handler to accept a right mouse click and start the "drag" mode. self.accept("mouse3-up",self.stopOrbit) # sets up the camrea handler to understand when the right mouse button has been released, and ends the "drag" mode when # the release is detected. # The next pair of lines use lambda, which creates an on-the-spot one-shot function. self.accept("wheel_up",lambda : self.adjustCamDist(0.9)) # sets up the camera handler to detet when the mouse wheel is rolled upwards and uses a lambda function to call the # adjustCamDist function with the argument 0.9 self.accept("wheel_down",lambda : self.adjustCamDist(1.1)) # sets up the camera handler to detet when the mouse wheel is rolled upwards and uses a lambda function to call the # adjustCamDist function with the argument 1.1 taskMgr.add(self.camMoveTask,'camMoveTask')
def __init__(self, cogIndex, suitType, game, cogSpeed): self.cogIndex = cogIndex self.suitType = suitType self.game = game self.cogSpeed = cogSpeed suit = Suit.Suit() d = SuitDNA.SuitDNA() d.newSuit(suitType) suit.setDNA(d) suit.pose('walk', 0) self.suit = suit self.goal = CTGG.NoGoal self.goalId = CTGG.InvalidGoalId self.lastLocalTimeStampFromAI = 0 self.lastPosFromAI = Point3(0, 0, 0) self.lastThinkTime = 0 self.doneAdjust = False self.barrel = CTGG.NoBarrelCarried self.signalledAtReturnPos = False self.defaultPlayRate = 1.0 self.netTimeSentToStartByHit = 0 self.velocity = Vec3(0, 0, 0) self.oldVelocity = Vec3(0, 0, 0) self.acceleration = Vec3(0, 0, 0) self.bodyLength = self.CollisionRadius * 2 self.cruiseDistance = 2 * self.bodyLength self.maxVelocity = self.cogSpeed self.maxAcceleration = 5.0 self.perceptionRange = 6 self.notify.debug('cogSpeed=%s' % self.cogSpeed) self.kaboomSound = loader.loadSfx( 'phase_4/audio/sfx/MG_cannon_fire_alt.ogg') self.kaboom = loader.loadModel( 'phase_4/models/minigames/ice_game_kaboom') self.kaboom.setScale(2.0) self.kaboom.setBillboardPointEye() self.kaboom.hide() self.kaboomTrack = None splatName = 'splat-creampie' self.splat = globalPropPool.getProp(splatName) self.splat.setBillboardPointEye() self.splatType = globalPropPool.getPropType(splatName) self.pieHitSound = globalBattleSoundCache.getSound( 'AA_wholepie_only.ogg') return
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 enterShowScores(self): self.notify.debug('enterShowScores') lerpTrack = Parallel() lerpDur = 0.5 lerpTrack.append( Parallel( LerpPosInterval(self.goalBar, lerpDur, Point3(0, 0, -0.6), blendType='easeInOut'), LerpScaleInterval(self.goalBar, lerpDur, Vec3(self.goalBar.getScale()) * 2.0, blendType='easeInOut'))) tY = 0.6 bY = -0.05 lX = -0.5 cX = 0 rX = 0.5 scorePanelLocs = (((cX, bY), ), ((lX, bY), (rX, bY)), ((cX, tY), (lX, bY), (rX, bY)), ((lX, tY), (rX, tY), (lX, bY), (rX, bY))) scorePanelLocs = scorePanelLocs[self.numPlayers - 1] for i in xrange(self.numPlayers): panel = self.scorePanels[i] pos = scorePanelLocs[i] panel.wrtReparentTo(aspect2d) lerpTrack.append( Parallel( LerpPosInterval(panel, lerpDur, Point3(pos[0], 0, pos[1]), blendType='easeInOut'), LerpScaleInterval(panel, lerpDur, Vec3(panel.getScale()) * 2.0, blendType='easeInOut'))) self.showScoreTrack = Parallel( lerpTrack, Sequence(Wait(MazeGameGlobals.SHOWSCORES_DURATION), Func(self.gameOver))) self.showScoreTrack.start() if base.config.GetBool('want-blueprint4-ARG', False): MinigameGlobals.generateDebugARGPhrase()
def calcTargetScale(target = target, origin = origin, horizScale = horizScale, vertScale = vertScale): if callable(target): target = target() if callable(origin): origin = origin() distance = Vec3(target - origin).length() yScale = distance / SPRAY_LEN targetScale = Point3(yScale * horizScale, yScale, yScale * vertScale) return targetScale
def genTextNode(T): global aspect2d txt = TextNode(T) txt.setText(T) txtNode = aspect2d.attachNewNode(txt) txtNode.setScale(0.1) txtNode.setPos(Vec3(-1.0, 0, 0.92)) txt.setTextColor(1,0,0,1) return txt
def update_crawler(self, timer): angle = self.angle direction = Vec3(-1. * math.sin(angle), -1. * math.cos(angle), 0) speed = self.linear_velocity speeddir = speed * speed.dot(direction) sqlen = speeddir.lengthSquared() if sqlen < self.max_crawl_speed_sq: self.add_force(direction * self.crawl_force * timer.delta)
def createMyParticle(self, size): particle = ParticleEffect() smokeEffect = self.path + "smoke.ptf" particle.loadConfig(Filename(smokeEffect)) p0 = particle.particlesDict['particles'] p0.emitter.setOffsetForce(Vec3(0.0, 0.0, 0.0)) p0.factory.setLifespanBase(0.3 * size) p0.setPoolSize(200) return particle
def movePivotTask(self, task): ''' move the camera pivot by keypresses ''' #print "I: CameraController.movePivotTask:", task.time # the movement the camera pivot should make moveVec = Vec3(0) for key, active in self.pressedKeys.items(): if active: moveVec += self.moveActions[key] # move relative to camera viewport cam = WindowManager.getDefaultCamera() relVec = self.cameraPosPivot.getRelativeVector(cam, moveVec) self.cameraPosPivot.setPos(self.cameraPosPivot, relVec * globalClock.getDt()) # send a event with the new position of the pivot pivotPos = Vec3(self.cameraPosPivot.getPos(render)) messenger.send(EVENT_CAMERAPIVOT_POSITION_CHANGE, [pivotPos]) return task.cont
def OnUpdate(self, task): # Position axes 30 pixels from top left corner self.axes.setPos(Vec3(30, 0, -30)) # Set rotation to inverse of camera rotation cameraQuat = Quat(self.getQuat()) cameraQuat.invertInPlace() self.axes.setQuat(cameraQuat)
def updateGoal(self, timestamp, inResponseClientStamp, goalType, goalId, pos): """Update our goal and position.""" assert self.notify.debugStateCall(self) self.notify.debug('self.netTimeSentToStartByHit =%s' % self.netTimeSentToStartByHit) if not self.game: self.notify.debug('updateGoal self.game is None, just returning') return if not self.suit: self.notify.debug('updateGoal self.suit is None, just returning') return if self.goal == CTGG.NoGoal: self.startWalkAnim() if goalType == CTGG.NoGoal: self.notify.debug('updateGoal setting position to %s' % pos) self.suit.setPos(pos) self.lastThinkTime = 0 self.velocity = Vec3(0, 0, 0) self.oldVelocity = Vec3(0, 0, 0) self.acceleration = Vec3(0, 0, 0) if goalType == CTGG.RunAwayGoal: #import pdb; pdb.set_trace() pass if inResponseClientStamp < self.netTimeSentToStartByHit and \ self.goal == CTGG.NoGoal and \ goalType == CTGG.RunAwayGoal: #import pdb; pdb.set_trace() self.notify.warning( 'ignoring newGoal %s as cog %d was recently hit responsetime=%s hitTime=%s' % (CTGG.GoalStr[goalType], self.cogIndex, inResponseClientStamp, self.netTimeSentToStartByHit)) else: self.lastLocalTimeStampFromAI = globalClockDelta.networkToLocalTime( timestamp, bits=32) self.goal = goalType self.goalId = goalId self.lastPosFromAI = pos self.doneAdjust = False self.signalledAtReturnPos = False
def updateDrawbridges(self): for drawbridge in self.drawbridges: if self.hp <= 0: if base.options.getSpecialEffectsSetting( ) >= base.options.SpecialEffectsHigh: smokeEffect = SmokeExplosion.getEffect() if smokeEffect: smokeEffect.reparentTo(render) smokeEffect.setPos(drawbridge, 0, 0, 0) smokeEffect.spriteScale = 1.0 smokeEffect.play() posHprIval = LerpPosHprInterval( drawbridge, 1.0, Vec3(drawbridge.getX(), drawbridge.getY(), drawbridge.getZ() - 130.0), Vec3(drawbridge.getH(), drawbridge.getP() - 360.0, drawbridge.getR() + 15)) posHprIval.start()
def __init__(self, player, cam, root): self.player = player self.toon = player.toon self.camera = cam self.root = root self.camOffset = VBase3(0, -12, 5) self.cameraManager = FlyingCamera(self.camera) self.cameraManager.vecRate = Vec3(3.0, 2.0, 1.8) self.cameraManager.otherNP = self.root
def __init__(self, fov=60.0, pos=(0, 20, 0), lookAt=(0, 0, 0), target=(0, 0, 0), dist=40): self.fov = fov self.pos = Vec3(pos) self.lookAt = Vec3(lookAt) self.target = Vec3(target) self.camDist = dist self.movingUp = False self.movingDown = False self.movingLeft = False self.movingRight = False self.dragging = False self.mx, self.my = 0, 0
def getWalkDuration(fromNode, toNode, velocity, paths): posPoints = getPointsFromTo(fromNode, toNode, paths) duration = 0 for pointIndex in xrange(len(posPoints) - 1): startPoint = posPoints[pointIndex] endPoint = posPoints[pointIndex + 1] distance = Vec3(endPoint - startPoint).length() duration += distance / velocity return duration
def handleEnterFan(self, fan): if fan in self.activeFans: return if len(self.activeFans) == 0: self._fanSfx.loop() self.activeFans.append(fan) if fan.index not in self.fanIndex2ToonVelocity: self.fanIndex2ToonVelocity[fan.index] = Vec3(0.0, 0.0, 0.0) if fan not in self.fansStillHavingEffect: self.fansStillHavingEffect.append(fan)
def getWalkDistance(fromNode, toNode, velocity, paths): posPoints = getPointsFromTo(fromNode, toNode, paths) retval = 0 for pointIndex in xrange(len(posPoints) - 1): startPoint = posPoints[pointIndex] endPoint = posPoints[pointIndex + 1] distance = Vec3(endPoint - startPoint).length() retval += distance return retval
def doModelSetup(self): if self.typeIndex == GardenGlobals.BOX_THREE: self.defaultModel = 'phase_5.5/models/estate/planterA' elif self.typeIndex == GardenGlobals.BOX_TWO: self.defaultModel = 'phase_5.5/models/estate/planterC' else: self.defaultModel = 'phase_5.5/models/estate/planterD' self.collSphereOffset = 0.0 self.collSphereRadius = self.collSphereRadius * 1.41 self.plotScale = Vec3(1.0, 1.0, 1.0)
def defineConstants(self, forceNumPlayers=None): DistributedPartyCatchActivity.notify.debug('defineConstants') self.ShowObjSpheres = 0 self.ShowToonSpheres = 0 self.useGravity = True self.trickShadows = True if forceNumPlayers is None: numPlayers = self.getNumPlayers() else: numPlayers = forceNumPlayers self.calcDifficultyConstants(numPlayers) DistributedPartyCatchActivity.notify.debug('ToonSpeed: %s' % self.ToonSpeed) DistributedPartyCatchActivity.notify.debug('total drops: %s' % self.totalDrops) DistributedPartyCatchActivity.notify.debug('numFruits: %s' % self.numFruits) DistributedPartyCatchActivity.notify.debug('numAnvils: %s' % self.numAnvils) self.ObjRadius = 1.0 dropRegionTable = PartyRegionDropPlacer.getDropRegionTable(numPlayers) self.DropRows, self.DropColumns = len(dropRegionTable), len( dropRegionTable[0]) for objType in PartyGlobals.DropObjectTypes: DistributedPartyCatchActivity.notify.debug('*** Object Type: %s' % objType.name) objType.onscreenDuration = objType.onscreenDurMult * self.BaselineOnscreenDropDuration DistributedPartyCatchActivity.notify.debug( 'onscreenDuration=%s' % objType.onscreenDuration) v_0 = 0.0 t = objType.onscreenDuration x_0 = self.MinOffscreenHeight x = 0.0 g = 2.0 * (x - x_0 - v_0 * t) / (t * t) DistributedPartyCatchActivity.notify.debug('gravity=%s' % g) objType.trajectory = Trajectory(0, Vec3(0, 0, x_0), Vec3(0, 0, v_0), gravMult=abs(g / Trajectory.gravity)) objType.fallDuration = objType.onscreenDuration + self.OffscreenTime return
def turnCameraAroundPoint(self, deltaX, deltaY): # This function performs two important tasks. First, it is used for the camera orbital movement that occurs when the # right mouse button is held down. It is also called with 0s for the rotation inputs to reposition the camera during the # panning and zooming movements. # The delta inputs represent the change in rotation of the camera, which is also used to determine how far the camera # actually moves along the orbit. newCamHpr = Vec3() newCamPos = Vec3() # Creates temporary containers for the new rotation and position values of the camera. camHpr = base.camera.getHpr() # Creates a container for the current HPR of the camera and stores those values. newCamHpr.setX(camHpr.getX() + deltaX) newCamHpr.setY(self.clamp(camHpr.getY() - deltaY, -85, -10)) newCamHpr.setZ(camHpr.getZ()) # Adjusts the newCamHpr values according to the inputs given to the function. The Y value is clamped to prevent # the camera from orbiting beneath the ground plane and to prevent it from reaching the apex of the orbit, which # can cause a disturbing fast-rotation glitch. base.camera.setHpr(newCamHpr) # Sets the camera's rotation to the new values. angleradiansX = newCamHpr.getX() * (math.pi / 180.0) angleradiansY = newCamHpr.getY() * (math.pi / 180.0) # Generates values to be used in the math that will calculate the new position of the camera. newCamPos.setX(self.camDist * math.sin(angleradiansX) * math.cos(angleradiansY) + self.target.getX()) newCamPos.setY(-self.camDist * math.cos(angleradiansX) * math.cos(angleradiansY) + self.target.getY()) newCamPos.setZ(-self.camDist * math.sin(angleradiansY) + self.target.getZ()) base.camera.setPos(newCamPos.getX(), newCamPos.getY(), newCamPos.getZ()) # print (newCamPos.getX(),newCamPos.getY(),newCamPos.getZ()) # Performs the actual math to calculate the camera's new position and sets the camera to that position. #Unfortunately, this math is over my head, so I can't fully explain it. base.camera.lookAt(self.target.getX(), self.target.getY(), self.target.getZ())
def enterShowScores(self): self.notify.debug('enterShowScores') lerpTrack = Parallel() lerpDur = 0.5 lerpTrack.append( Parallel( LerpPosInterval(self.goalBar, lerpDur, Point3(0, 0, -.6), blendType='easeInOut'), LerpScaleInterval(self.goalBar, lerpDur, Vec3(self.goalBar.getScale()) * 2.0, blendType='easeInOut'))) tY = 0.6 bY = -.05 lX = -.5 cX = 0 rX = 0.5 scorePanelLocs = (((cX, bY), ), ((lX, bY), (rX, bY)), ((cX, tY), (lX, bY), (rX, bY)), ((lX, tY), (rX, tY), (lX, bY), (rX, bY))) scorePanelLocs = scorePanelLocs[self.numPlayers - 1] for i in range(self.numPlayers): panel = self.scorePanels[i] pos = scorePanelLocs[i] lerpTrack.append( Parallel( LerpPosInterval(panel, lerpDur, Point3(pos[0], 0, pos[1]), blendType='easeInOut'), LerpScaleInterval(panel, lerpDur, Vec3(panel.getScale()) * 2.0, blendType='easeInOut'))) self.showScoreTrack = Parallel( lerpTrack, Sequence(Wait(MazeGameGlobals.SHOWSCORES_DURATION), Func(self.gameOver))) self.showScoreTrack.start()
def create(self): lightAttrib = LightAttrib.makeAllOff() #create ambient light ambientLight = AmbientLight("ambientLight") ambientLight.setColor(self.ambientColor) lightAttrib = lightAttrib.addLight(ambientLight) render.attachNewNode(ambientLight.upcastToPandaNode()) self.ambientLight = ambientLight #default light settings """colors = [ Vec4(1,0,0,0), Vec4(0,1,0,0), Vec4(0,0,1,0), Vec4(1,1,0,0) ] directions = [ Vec3(1,0,0), Vec3(0,1,0), Vec3(-1,0,0), Vec3(0,-1,0) ] intensities = [ 3.0, 0.1, 3.0, 0.1 ]""" colors = [ Vec4(1, 1, 1, 0), Vec4(0, 1, 0, 0), Vec4(0, 0, 1, 0), Vec4(1, 1, 0, 0) ] # basic 3+1 point lighting directions = [ Vec3(0, 1, -0.2), Vec3(0, 1, 0), Vec3(-1, 0.3, 0), Vec3(0, -1, 0) ] intensities = [1.0, 0.0, 0.5, 0.0] #add directional lights self.directionalLights = [] for i in range(4): self.directionalLights.append( ShaderDirectionalLight(colors[i], directions[i], intensities[i], i)) lightAttrib = self.directionalLights[i].create(lightAttrib) #set light attributes render.node().setAttrib(lightAttrib)
def setTime(self, time): self.time = time if time < 500.0 or time > 1900.0: self.sun.hide() self.dlight.setColor(Vec4(0, 0, 0, 0)) return self.sun.show() noonOffset = (1200.0 - time) / 600.0 sunsetStrength = noonOffset * noonOffset directColor = Vec4(2.7, 2.5, 2.1, 1) #bright for hdr sunsetColor = Vec4(1.8, 1.1, 0.6, 1) if sunsetStrength < 1.0: directColor *= 1-sunsetStrength sunsetColor *= sunsetStrength #logging.info( str(directColor)+ str(sunsetColor)) lightColor = directColor + sunsetColor else: maxSunsetStrength = (1.0 + 1.0 / 6.0) * (1.0 + 1.0 / 6.0) duskTime = maxSunsetStrength - 1.0 duskMultiplier = ((1.0 + duskTime) - sunsetStrength) / duskTime #logging.info( duskMultiplier) if duskMultiplier < 0: lightColor = Vec4(0, 0, 0, 1) else: lightColor = sunsetColor * duskMultiplier lightColor.w = 1 self.dlight.setColor(lightColor) directColor = Vec4(1.0, 1.0, 1.0, 1) sunsetColor = Vec4(1.0, 0.9, 0.7, 1) directColor *= 1-sunsetStrength sunsetColor *= sunsetStrength #logging.info( str(directColor)+ str(sunsetColor)) lightColor = directColor + sunsetColor self.sun.setColorScale(lightColor, 1000) if self.finalQuad != None: directColor = Vec4(1, 0.99, 0.80, 0.03) sunsetColor = Vec4(1, 0.65, 0.25, 0.025) sunsetColor *= sunsetStrength directColor *= 1-sunsetStrength vlColor = directColor + sunsetColor self.finalQuad.setShaderInput('vlcolor', vlColor) angle = noonOffset * math.pi / 2 y = math.sin(angle) z = math.cos(angle) #logging.info( "sun angle, x, z: ", angle, x, z) self.setPos(Vec3(0, y, z))
def hourChange(self, currentHour): currentHour = currentHour % 12 if currentHour == 0: currentHour = 12 self.hourSoundInterval = Parallel() seq1 = Sequence() for i in xrange(currentHour): seq1.append(SoundInterval(self.clockSounds[i])) seq1.append(Wait(0.2)) timeForEachDeformation = seq1.getDuration() / currentHour seq2 = Sequence() for i in xrange(currentHour): seq2.append(self.clockFlat.scaleInterval(timeForEachDeformation / 2.0, Vec3(0.9, 1.0, 1.2), blendType='easeInOut')) seq2.append(self.clockFlat.scaleInterval(timeForEachDeformation / 2.0, Vec3(1.2, 1.0, 0.9), blendType='easeInOut')) seq2.append(self.clockFlat.scaleInterval(timeForEachDeformation / 2.0, Vec3(1.0, 1.0, 1.0), blendType='easeInOut')) self.hourSoundInterval.append(seq1) self.hourSoundInterval.append(seq2) self.hourSoundInterval.start()
def __init__(self, pos): self.lane = 0 # Creates a variable to store the number ID of the lane this marker is in. self.index = 0 # Creates a variable to store the number ID of the marker within it's lane. self.np = render.attachNewNode("MarkerNP") self.np.setPos(pos.getX(), pos.getY(), pos.getZ()) # Creates and positions a proxy NodePath to represent the marker's position in # space. self.nextMarker = None self.prevMarker = None # Creates variables to store the next and previous markers in the lane. self.adjMarkers = [] # Creates a list to reference the markers that are adjacent to this one. self.facingVec = Vec3(0, 1, 0) self.cycleVec = Vec3(0, 0, 0)