本文整理汇总了Python中panda3d.core.Fog.setExpDensity方法的典型用法代码示例。如果您正苦于以下问题:Python Fog.setExpDensity方法的具体用法?Python Fog.setExpDensity怎么用?Python Fog.setExpDensity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.Fog
的用法示例。
在下文中一共展示了Fog.setExpDensity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadPrisonCrater
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def loadPrisonCrater():
## Sky color
base.win.setClearColor(Vec4(.46,.824,.904,1))
## Load Ground
sand = loader.loadModel("data/models/sand.bam")
sand.reparentTo(render)
sand.setTexScale(TextureStage.getDefault(),5000,5000)
craterwalls = loader.loadModel("data/models/craterwalls.bam")
craterwalls.reparentTo(render)
craterwalls.setTexScale(TextureStage.getDefault(),500,50)
## World Effects
fog = Fog("Fog")
fog.setColor(255,215,143)
fog.setExpDensity(.0000001)
render.setFog(fog)
alight = render.attachNewNode(AmbientLight("Abient"))
alight.node().setColor(Vec4(.9,.9,.9,1))
render.setLight(alight)
sun = DirectionalLight('Sun')
sun.setColor(Vec4(1,1,1,1))
sunNP = render.attachNewNode(sun)
sunNP.setPos(0,0,4000)
sunNP.setHpr(0,-90,0)
render.setLight(sunNP)
示例2: begin
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def begin(self):
base.setBackgroundColor( self.environment['colourBackground'] )
alight = AmbientLight('AmbientLight')
alight.setColor(self.environment['colourAmbient'] )
alnp = self.sceneNode.attachNewNode(alight)
self.sceneNode.setLight(alnp)
if self.environment['fog']:
fog = Fog( 'sceneName' )
fog.setColor( self.environment['fog']['color'] )
if self.environment['fog']['mode'] == "linear":
fog.setLinearRange(self.environment['fog']['linearStart']*1000,self.environment['fog']['linearEnd']*1000)
else:
fog.setExpDensity( self.environment['fog']['expDensity'] )
self.sceneNode.setFog(fog)
[self.createNode(props) for props in self.nodes]
[self.createLight(props) for props in self.lights]
[self.createCamera(props) for props in self.cameras]
[self.createEntity(props) for props in self.entities]
# [self.createStaticGeoms(props) for props in self.staticGeoms]
self.sceneNode.clearModelNodes()
self.sceneNode.flattenStrong()
self.sceneNode.setShaderAuto()
示例3: BRHood
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
class BRHood(ToonHood):
notify = directNotify.newCategory("BRHood")
ID = ToontownGlobals.TheBrrrgh
TOWNLOADER_CLASS = BRTownLoader
SAFEZONELOADER_CLASS = BRSafeZoneLoader
STORAGE_DNA = "phase_8/dna/storage_BR.pdna"
SKY_FILE = "phase_3.5/models/props/BR_sky"
SPOOKY_SKY_FILE = "phase_3.5/models/props/BR_sky"
TITLE_COLOR = (0.3, 0.6, 1.0, 1.0)
HOLIDAY_DNA = {
ToontownGlobals.WINTER_DECORATIONS: ["phase_8/dna/winter_storage_BR.pdna"],
ToontownGlobals.WACKY_WINTER_DECORATIONS: ["phase_8/dna/winter_storage_BR.pdna"],
ToontownGlobals.HALLOWEEN_PROPS: ["phase_8/dna/halloween_props_storage_BR.pdna"],
ToontownGlobals.SPOOKY_PROPS: ["phase_8/dna/halloween_props_storage_BR.pdna"],
}
def load(self):
ToonHood.load(self)
self.fog = Fog("BRFog")
def setFog(self):
if base.wantFog:
self.fog.setColor(0.9, 0.9, 0.9)
self.fog.setExpDensity(0.004)
render.clearFog()
render.setFog(self.fog)
self.sky.clearFog()
self.sky.setFog(self.fog)
示例4: setFogOn
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def setFogOn(self, fog):
self.fogOn = fog
if self.fogOn:
myFog = Fog('Fog Rendering Fog of Rendering')
myFog.setColor(1.0, 0.0, 0.0)
myFog.setExpDensity(0.5)
self.setFog(myFog)
else:
self.clearFog()
示例5: toggle_smoke
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def toggle_smoke(self):
from panda3d.core import Fog
if self.render.getFog():
self.render.clearFog()
else:
smoke = Fog("smoke")
smoke.setColor(config.smoke_color)
smoke.setExpDensity(config.smoke_exp_density)
render.setFog(smoke)
示例6: createEnvironment
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def createEnvironment(self):
# Fog
expfog = Fog("scene-wide-fog")
expfog.setColor(0.5, 0.5, 0.5)
expfog.setExpDensity(0.002)
self.render.setFog(expfog)
# Sky
skysphere = self.loader.loadModel("assets/blue-sky-sphere")
skysphere.setEffect(CompassEffect.make(self.render))
skysphere.setScale(0.08)
skysphere.reparentTo(self.camera)
# Lights
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(0.6, 0.6, 0.6, 1))
self.render.setLight(self.render.attachNewNode(ambientLight))
directionalLight = DirectionalLight("directionalLight")
directionalLight.setColor(VBase4(0.8, 0.8, 0.5, 1))
dlnp = self.render.attachNewNode(directionalLight)
dlnp.setPos(0, 0, 260)
dlnp.lookAt(self.player)
self.render.setLight(dlnp)
# Water
self.water = self.loader.loadModel("assets/square.egg")
self.water.setSx(self.worldsize * 2)
self.water.setSy(self.worldsize * 2)
self.water.setPos(self.worldsize / 2, self.worldsize / 2, 25)
self.water.setTransparency(TransparencyAttrib.MAlpha)
newTS = TextureStage("1")
self.water.setTexture(newTS, self.loader.loadTexture("assets/water.png"))
self.water.setTexScale(newTS, 4)
self.water.reparentTo(self.render)
LerpTexOffsetInterval(self.water, 200, (1, 0), (0, 0), textureStage=newTS).loop()
示例7: BossbotHQ
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
class BossbotHQ(CogHood):
notify = directNotify.newCategory("BossbotHQ")
ID = ToontownGlobals.BossbotHQ
LOADER_CLASS = BossbotCogHQLoader
def load(self):
CogHood.load(self)
self.fog = Fog("BossbotHQFog")
self.sky.hide()
def enter(self, requestStatus):
CogHood.enter(self, requestStatus)
base.localAvatar.setCameraFov(ToontownGlobals.CogHQCameraFov)
base.camLens.setNearFar(ToontownGlobals.BossbotHQCameraNear, ToontownGlobals.BossbotHQCameraFar)
self.setFog()
def spawnTitleText(self, zoneId, floorNum=None):
if ZoneUtil.isMintInteriorZone(zoneId):
text = "%s\n%s" % (ToontownGlobals.StreetNames[zoneId][-1], TTLocalizer.MintFloorTitle % (floorNum + 1))
self.doSpawnTitleText(text)
else:
CogHood.spawnTitleText(self, zoneId)
def setFog(self):
if base.wantFog:
self.fog.setColor(0.1, 0.1, 0.1)
self.fog.setExpDensity(0.004)
render.clearFog()
render.setFog(self.fog)
self.sky.clearFog()
self.sky.setFog(self.fog)
示例8: gameLoop
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def gameLoop(self, task):
#Compensate for inconsistent update intervals
dt = globalClock.getDt()
if self.GAME_MODE == MAIN_MENU:
if not self.mode_initialized:
self.buildMainMenu()
self.mode_initialized = True
if self.GAME_MODE == IN_GAME_MENU:
if not self.mode_initialized:
#Fog out background
inGameMenuFogColor = (50, 150, 50)
inGameMenuFog = Fog("inGameMenuFog")
inGameMenuFog.setMode(Fog.MExponential)
inGameMenuFog.setColor(*inGameMenuFogColor)
inGameMenuFog.setExpDensity(.01)
render.setFog(inGameMenuFog)
self.buildInGameMenu()
self.mode_initialized = True
if self.GAME_MODE == PLAY:
if not self.mode_initialized:
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
self.last_mouse_x = self.win.getPointer(0).getX()
self.last_mouse_y = self.win.getPointer(0).getY()
self.mode_initialized = True
if self.play_mode == TERRAIN:
self.maintainTurrets()
self.avatar.move(dt)
elif self.play_mode == SPACE:
self.asteroidManager.maintainAsteroidField(self.avatar.objectNP.getPos(),
self.avatar.speed, dt)
#Handle keyboard input
self.avatar.handleKeys(self.keys, self.play_mode)
########## Mouse-based viewpoint rotation ##########
mouse_pos = self.win.getPointer(0)
current_mouse_x = mouse_pos.getX()
current_mouse_y = mouse_pos.getY()
#Side to side
if self.play_mode == TERRAIN:
mouse_shift_x = current_mouse_x - self.last_mouse_x
self.last_mouse_x = current_mouse_x
if current_mouse_x < 5 or current_mouse_x >= (self.win_center_x * 1.5):
base.win.movePointer(0, self.win_center_x, current_mouse_y)
self.last_mouse_x = self.win_center_x
yaw_shift = -((mouse_shift_x) * Camera.ROT_RATE[0])
self.avatar.yawRot += yaw_shift
self.avatar.objectNP.setH(self.avatar.yawRot)
#Up and down
mouse_shift_y = current_mouse_y - self.last_mouse_y
self.last_mouse_y = current_mouse_y
if current_mouse_y < 5 or current_mouse_y >= (self.win_center_y * 1.5):
base.win.movePointer(0, current_mouse_x, self.win_center_y)
self.last_mouse_y = self.win_center_y
pitch_shift = -((mouse_shift_y) * Camera.ROT_RATE[1])
self.mainCamera.pitchRot += pitch_shift
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def __init__(self):
ShowBase.__init__(self)
#Setup
scene = BulletWorld()
scene.setGravity(Vec3(0, 0, -9.81))
base.setBackgroundColor(0.6,0.9,0.9)
fog = Fog("The Fog")
fog.setColor(0.9,0.9,1.0)
fog.setExpDensity(0.003)
render.setFog(fog)
#Lighting
#Sun light
sun = DirectionalLight("The Sun")
sun_np = render.attachNewNode(sun)
sun_np.setHpr(0,-60,0)
render.setLight(sun_np)
#Ambient light
amb = AmbientLight("The Ambient Light")
amb.setColor(VBase4(0.39,0.39,0.39, 1))
amb_np = render.attachNewNode(amb)
render.setLight(amb_np)
#Variables
self.gear = 0
self.start = 0
self.Pbrake = 0
self.terrain_var = 1
self.time = 0
self.headlight_var = 0
self.RPM = 0
self.clutch = 0
self.carmaxspeed = 100 #KPH
self.carmaxreversespeed = -40 #KPH
self.steering = 0
#Functions
def V1():
camera.setPos(0.25,-1.2,0.5)
camera.setHpr(0,-13,0)
def V2():
camera.setPos(0,-15,3)
camera.setHpr(0,-10,0)
def V3():
camera.setPos(0,0,9)
camera.setHpr(0,-90,0)
def up():
self.gear = self.gear -1
if self.gear < -1:
self.gear = -1
def down():
self.gear = self.gear +1
if self.gear > 1:
self.gear = 1
def start_function():
self.start = 1
self.start_sound.play()
self.engine_idle_sound.play()
self.RPM = 1000
def stop_function():
self.start = 0
self.engine_idle_sound.stop()
def parkingbrake():
self.Pbrake = (self.Pbrake + 1) % 2
def rotate():
Car_np.setHpr(0, 0, 0)
def horn():
self.horn_sound.play()
def set_time():
if self.time == -1:
sun.setColor(VBase4(0.4, 0.3, 0.3, 1))
base.setBackgroundColor(0.8,0.7,0.7)
if self.time == 0:
sun.setColor(VBase4(0.7, 0.7, 0.7, 1))
base.setBackgroundColor(0.6,0.9,0.9)
if self.time == 1:
sun.setColor(VBase4(0.2, 0.2, 0.2, 1))
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
class Arena:
def __init__(self, arenaNr):
arenaPath = "levels/arena%d/" % arenaNr
self.arena = loader.loadModel(arenaPath + "arena")
self.arena.setScale(2)
self.arena.reparentTo(render)
self.arena.hide()
ambientLight = AmbientLight("ambient_light")
ambientLight.setColor((0.2, 0.2, 0.2, 1))
self.alnp = render.attachNewNode(ambientLight)
sunLens = PerspectiveLens()
sunLens.setFilmSize(50)
sun = DirectionalLight("sun")
sun.setColor((1, 1, 1, 1))
sun.setShadowCaster(True, 2048, 2048)
sun.setScene(render)
#sun.showFrustum()
self.ambientSound = None
self.levelParticles = None
if arenaNr == 1:
sunLens.setNearFar(25,45)
sun.setLens(sunLens)
self.sunNp = render.attachNewNode(sun)
self.sunNp.setPos(-10, -10, 30)
self.sunNp.lookAt(0,0,0)
self.ambientSound = loader.loadSfx("assets/audio/ambientLevel1.ogg")
self.ambientSound.setLoop(True)
self.fog = Fog("Outside Fog")
self.fog.setColor(0.3,0.3,0.5)
self.fog.setExpDensity(0.025)
self.levelParticles = ParticleEffect()
self.levelParticles.loadConfig("assets/fx/Leafs.ptf")
self.levelParticles.start(parent = render2d, renderParent = render2d)
elif arenaNr == 2:
sunLens.setFov(120, 40)
sunLens.setNearFar(2,10)
sun.setLens(sunLens)
self.sunNp = render.attachNewNode(sun)
self.sunNp.setPos(0, 0, 5)
self.sunNp.lookAt(0,0,0)
self.fog = Fog("Temple Fog")
self.fog.setColor(0,0,0)
self.fog.setExpDensity(0.065)
def start(self):
self.arena.show()
render.setLight(self.alnp)
render.setLight(self.sunNp)
if self.ambientSound != None:
self.ambientSound.play()
render.setFog(self.fog)
def stop(self):
self.arena.hide()
render.clearLight()
if self.ambientSound != None:
self.ambientSound.stop()
render.clearFog()
if self.levelParticles != None:
self.levelParticles.cleanup()
def getStartPos(self, charNr):
if charNr == 1:
return self.arena.find("**/StartPosA").getPos() * 2
elif charNr == 2:
return self.arena.find("**/StartPosB").getPos() * 2
else:
return (0,0,0)
示例11: SpaceFlight
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
class SpaceFlight(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.text = OnscreenText \
(
parent = base.a2dBottomCenter,
align=TextNode.ARight,
fg=(1, 1, 1, 1),
pos=(0.2, 1.),
scale=0.1,
shadow=(0, 0, 0, 0.5)
)
self.setBackgroundColor(0, 0, 0)
self.disableMouse()
self.fog = Fog('distanceFog')
self.fog.setColor(0, 0, 0)
self.fog.setExpDensity(.002)
#
self.queue = CollisionHandlerQueue()
self.trav = CollisionTraverser('traverser')
base.cTrav = self.trav
self.loadSky()
self.reloadGame()
self.keyMap = {'left' : 0, 'right' : 0, 'up' : 0, 'down' : 0}
self.gamePause = False
#
self.accept('escape', sys.exit)
self.accept('p', self.pause)
self.accept('r', self.reloadGame)
self.accept('arrow_left', self.setKey, ['left', True])
self.accept('arrow_right', self.setKey, ['right', True])
self.accept('arrow_up', self.setKey, ['up', True])
self.accept('arrow_down', self.setKey, ['down', True])
self.accept('arrow_left-up', self.setKey, ['left', False])
self.accept('arrow_right-up', self.setKey, ['right', False])
self.accept('arrow_up-up', self.setKey, ['up', False])
self.accept('arrow_down-up', self.setKey, ['down', False])
#
taskMgr.add(self.moveShip, 'moveShip')
taskMgr.add(self.moveAsteroids, 'moveAsteroids')
taskMgr.add(self.handleCollisions, 'handleCollisions')
#
if DEBUG:
self.trav.showCollisions(render)
render.find('**/ship_collision').show()
for asteroid in render.findAllMatches('**/asteroid_collision*'):
asteroid.show()
def loadSky(self):
self.sky = loader.loadModel('models/solar_sky_sphere.egg.pz')
self.sky_tex = loader.loadTexture('models/stars_1k_tex.jpg')
self.sky.setTexture(self.sky_tex, 1)
self.sky.reparentTo(render)
self.sky.setScale(500)
def loadShip(self):
self.ship = loader.loadModel('models/alice-scifi--fighter/fighter.egg')
self.ship.reparentTo(render)
self.ship.setPos(START_X, START_Y, START_Z)
self.ship.setScale(0.25)
# add some physics
ship_col = self.ship.attachNewNode(CollisionNode('ship_collision'))
col_sphere = CollisionSphere(START_X, START_Y, 0, SHIP_SPHERE_RADIUS)
ship_col.node().addSolid(col_sphere)
self.trav.addCollider(ship_col, self.queue)
def spawnAsteroid(self):
asteroid = loader.loadModel(choice(ASTEROID_SHAPES))
asteroid_tex = loader.loadTexture('models/rock03.jpg')
asteroid.setTexture(asteroid_tex, 1)
asteroid.reparentTo(render)
asteroid.setFog(self.fog)
self.asteroids.append(asteroid)
self.asteroids_rotation.append(randint(ASTEROID_ROTATE_MIN, ASTEROID_ROTATE_MAX))
#
num = len(self.asteroids) - 1
asteroid_col = asteroid.attachNewNode(CollisionNode('asteroid_collision_%d' % num))
col_sphere = CollisionSphere(0, 0, 0, ASTEROID_SPHERE_RADIUS)
asteroid_col.node().addSolid(col_sphere)
#
asteroid.setX(randint(MIN_X, MAX_X))
asteroid.setY(randint(ASTEROID_SPAWN_MIN_Y, ASTEROID_SPAWN_MAX_Y))
asteroid.setZ(randint(MIN_Z, MAX_Z))
def setKey(self, key, value):
self.keyMap[key] = value
if key in ['left', 'right'] and value == False:
self.ship.setH(0)
if key in ['up', 'down'] and value == False:
self.ship.setP(0)
def updateCamera(self):
x, y, z = self.ship.getPos()
self.camera.setPos(x, y - 40, z + 25)
self.camera.lookAt(x, y, z + 10)
def moveAsteroids(self, task):
dt = globalClock.getDt()
if not self.gamePause:
#.........这里部分代码省略.........
示例12: Terrain
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
class Terrain():
def __init__(self, _heightField):
texture = loader.loadTexture("ground_tex.png")
self.zScale = 45
self.terrain = GeoMipTerrain("BasicTerrain")
self.terrain.setHeightfield(_heightField)
# Dynamic settings?
self.terrain.setBlockSize(16)
self.terrain.setNear(20)
self.terrain.setFar(100)
self.terrain.setFocalPoint(base.camera)
# Settings
self.terrain.getRoot().setSz(self.zScale)
self.terrain.getRoot().setTexture(texture)
self.terrain.getRoot().reparentTo(render)
self.terrain.generate()
self.terrainSize = (self.terrain.heightfield().getReadXSize(), self.terrain.heightfield().getReadYSize())
print "Terrain Size:", self.terrainSize
taskMgr.add(self.terrainTask, "TerrainTask")
self.skydome = loader.loadModel("Skydome")
self.skydome.setDepthTest(False)
self.skydome.setAttrib(CullBinAttrib.make("skydomeBin", 1000))
self.skydome.reparentTo(camera)
self.skydome.setScale(2)
self.skydome.setPos(0, 0, -0.5)
self.skydome.setCollideMask(BitMask32.allOff())
taskMgr.add(self.skydomeTask, "paperplanet_skydome")
# Add some fancy fog
self.fog = Fog("Fog Name")
self.fog.setColor(0.4,0.2,0.3)
self.fog.setExpDensity(0.015)
render.setFog(self.fog)
# Some Test light
dlight = DirectionalLight("dlight")
dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
dlnp = render.attachNewNode(dlight)
dlnp.setHpr(0, -60, 0)
render.setLight(dlnp)
# Add basic blacksmith hut
tmp = loader.loadModel("blacksmith_hut")
tmp.reparentTo(render)
tmp.setPos(164.054, 340.92, 11.3384)
def skydomeTask(self, task):
self.skydome.setHpr(render, 0,0,0)
return task.cont
def terrainTask(self, task):
# tmp
self.terrain.update()
return task.cont
示例13: World
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
class World(DirectObject):
# Initialize the world class
def __init__(self):
# A few window settings
base.disableMouse()
camera.setPosHpr(0, 0.5, 10, 0, -100, 0) #Vary this
base.setBackgroundColor(0, 0.5, 1)
# Load the Boeing707
self.scale = 0.04
self.xPos = 0.0
self.yPos = 0.0
self.tilt = 0.0
self.lift = 0.0
self.plane = loader.loadModel('./models/plane/boeing707')
self.plane.reparentTo(render)
self.plane.setScale(self.scale, self.scale, self.scale)
self.plane.setPosHpr(self.xPos, -0.7 + self.yPos, 0, 0, 270 + self.lift, self.tilt)
# Load fog into the view
self.fog = Fog('distanceFog')
self.fog.setColor(0, 0.5, 1)
self.fog.setExpDensity(.08)
render.setFog(self.fog)
# Load the tunnel and keep it running infinitely
self.initTunnel()
self.contTunnel()
# Key mappings
self.accept('escape', sys.exit)
self.accept('+', self.scaleUp)
self.accept('-', self.scaleDown)
try:
self.ser = serial.Serial('/dev/ttyUSB0', 9600)
taskMgr.add(self.serialTask, "serialTask")
except:
print("Could not open Serial port")
# The serial task
def serialTask(self, task):
reading = self.ser.readline()
if(reading != ""):
try:
if(reading[0] == 'y'):
x = float(reading[1:])
devX = (X_STABLE - x)
if(devX < -25):
self.moveLeft()
elif(devX > 25):
self.moveRight()
else:
self.stabilizeTilt()
if(reading[0] == 'x'):
y = float(reading[1:])
devY = (Y_STABLE - y)
if(devY < -25):
self.liftDown()
elif(devY > 25):
self.liftUp()
else:
self.stabilizeLift()
except:
pass
return Task.cont
# Make the Boeing stable on the tilt
def stabilizeTilt(self):
if(self.tilt > 0):
if(self.tilt != 0.0):
self.tilt = self.tilt - 0.25
else:
if(self.tilt != 0.0):
self.tilt = self.tilt + 0.25
self.plane.setPosHpr(self.xPos, -0.7 + self.yPos, 0, 0, 270 + self.lift, self.tilt)
# Make the Boeing stable on the lift
def stabilizeLift(self):
if(self.lift > 0):
if(self.lift != 0.0):
self.lift = self.lift - 0.25
else:
if(self.lift != 0.0):
self.lift = self.lift + 0.25
self.lift.setPosHpr(self.xPos, -0.7 + self.yPos, 0, 0, 270 + self.lift, self.tilt)
# Zoom into the plane
def scaleUp(self):
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def __init__(self):
ShowBase.__init__(self)
wp = WindowProperties()
wp.setSize(1024, 768)
base.win.requestProperties(wp)
#Environment
self.setBackgroundColor(0.3,0.3,1,1) # blue sky
fog = Fog("fog")
fog.setColor(0.75,0.75,0.75)
fog.setExpDensity(0.016)
self.render.setFog(fog)
# Controls
self.add_move_key("w", lambda: self.move(y=1))
self.add_move_key("a", lambda: self.move(x=-1))
self.add_move_key("d", lambda: self.move(x=1))
self.add_move_key("s", lambda: self.move(y=-1))
# Camera
self.disableMouse()
self.camera.setPos(12.6694, 16.5869, 2.23608)
self.camera.setHpr(-5.44159, 7.59898, -0.084791)
self.taskMgr.add(self.handleMouse, 'mouseStuff')
self.taskMgr.add(self.rotateBuildingColors, 'buildingColors')
self.cube = loader.loadModel(path_of_local_file("models/cube/cube.egg"))
self.cube.setScale(0.3,0.3,0.3)
# Floor
floor_plane = self.cube.copyTo(self.render)
floor_plane.setScale(100,100,1)
floor_plane.setColor(0.1,0.75,0.1,1)
# Buildings
self.buildings = []
for start_x in range(0,100,20):
for start_y in range(0,100,25):
height = random.randrange(5,25)
color = (random.uniform(0,1),random.uniform(0,1),random.uniform(0,1))
building = self.render.attachNewNode("building")
for y in range(0,10): # west wall
for z in range(1,height):
self.add_cube(start_x, start_y + y, z,parent=building)
for y in range(0,10): # east wall
for z in range(1,height):
self.add_cube(start_x + 10, start_y + y, z, parent=building)
for x in range(0,11): # north wall
for z in range(1,height):
self.add_cube(start_x + x, start_y + 10, z, parent=building)
for x in range(0,11): # south wall
for z in range(1,height):
self.add_cube(start_x + x, start_y, z, parent=building)
for c in building.getChildren():
gray = random.uniform(0.1,0.4)
c.setColor(color[0] - gray,color[1] - gray,color[2] - gray,1)
self.buildings.append(building)
# Trees
self.tree_model = loader.loadModel(path_of_local_file("models/plants6/plants6.egg"))
self.tree_model.setScale(0.25,0.25,0.25)
for x in range(15,100,20):
for y in range (15,100,20):
tree = self.tree_model.copyTo(self.render)
tree.setPos(x,y,0)
# Roads
for y in range(15, 100, 20):
road = self.cube.copyTo(self.render)
road.setScale(10,100,0.1)
road.setPos(0,y,0.1)
示例15: gameLoop
# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import setExpDensity [as 别名]
def gameLoop(self, task):
#Compensate for inconsistent update intervals
dt = globalClock.getDt()
if self.GAME_MODE == MAIN_MENU:
if not self.mode_initialized:
self.buildMainMenu()
self.mode_initialized = True
if self.GAME_MODE == IN_GAME_MENU:
if not self.mode_initialized:
inGameMenuFogColor = (50, 150, 50)
inGameMenuFog = Fog("inGameMenuFog")
inGameMenuFog.setMode(Fog.MExponential)
inGameMenuFog.setColor(*inGameMenuFogColor)
inGameMenuFog.setExpDensity(.01)
render.setFog(inGameMenuFog)
self.buildInGameMenu()
self.mode_initialized = True
if self.GAME_MODE == NORMAL:
if not self.mode_initialized:
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
self.last_mouse_x = self.win.getPointer(0).getX()
self.last_mouse_y = self.win.getPointer(0).getY()
self.mode_initialized = True
#Handle keyboard input
self.avatar.handleKeys(self.keys)
self.avatar.move(dt)
#Mouse-based viewpoint rotation
mouse_pos = self.win.getPointer(0)
current_mouse_x = mouse_pos.getX()
current_mouse_y = mouse_pos.getY()
mouse_shift_x = current_mouse_x - self.last_mouse_x
mouse_shift_y = current_mouse_y - self.last_mouse_y
self.last_mouse_x = current_mouse_x
self.last_mouse_y = current_mouse_y
if current_mouse_x < 5 or current_mouse_x >= (self.win_center_x * 1.5):
base.win.movePointer(0, self.win_center_x, current_mouse_y)
self.last_mouse_x = self.win_center_x
if current_mouse_y < 5 or current_mouse_y >= (self.win_center_y * 1.5):
base.win.movePointer(0, current_mouse_x, self.win_center_y)
self.last_mouse_y = self.win_center_y
yaw_shift = -((mouse_shift_x) * Camera.ROT_RATE[0])
pitch_shift = -((mouse_shift_y) * Camera.ROT_RATE[1])
self.avatar.yawRot += yaw_shift
self.mainCamera.pitchRot += pitch_shift
if self.mainCamera.pitchRot > Camera.MAX_PITCH_ROT:
self.mainCamera.pitchRot = Camera.MAX_PITCH_ROT
elif self.mainCamera.pitchRot < Camera.MIN_PITCH_ROT:
self.mainCamera.pitchRot = Camera.MIN_PITCH_ROT
self.avatar.objectNP.setH(self.avatar.yawRot)
self.mainCamera.camObject.setH(self.avatar.yawRot)
self.mainCamera.camObject.setP(self.mainCamera.pitchRot)
if self.NAVIGATION_MODE == TERRAIN:
xy_plane_cam_dist = Camera.AVATAR_DIST
cam_z_adjust = Camera.ELEVATION
elif self.NAVIGATION_MODE == SPACE:
#.........这里部分代码省略.........