This is my code:
#!/usr/bin/python
#coding:utf8
from pandac.PandaModules import loadPrcFileData
loadPrcFileData('', 'bullet-additional-damping 1')
loadPrcFileData('', 'egg-load-old-curves 1')
loadPrcFileData('', 'audio-library-name p3openal_audio')
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.directutil import Mopath
from direct.interval.LerpInterval import LerpPosInterval
from direct.interval.IntervalGlobal import Sequence
from direct.showbase import Audio3DManager
from panda3d.core import Vec3
from panda3d.core import TransformState
from panda3d.core import Point3
from panda3d.core import AmbientLight, DirectionalLight, Vec4
from panda3d.core import CollisionTraverser
import sys
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.accept('escape', sys.exit)
g = loader.loadModel('rail')
g.reparentTo(render)
#移动摄像机
self.disableMouse()
taskMgr.add(self.task, 'mainTask')
self.train1 = loader.loadModel('train')
self.train1.reparentTo(render)
self.train2 = loader.loadModel('train')
self.train2.reparentTo(render)
self.train2.setHpr(180,0,0)
self.train2.setPos(-5,800,0)
railInterval1 = LerpPosInterval(self.train1, name='train', duration=20,startPos=(0,-800,0), pos=(0,800,0))
railInterval2 = LerpPosInterval(self.train2, name='train', duration=20,startPos=(-5,800,0), pos=(-5,-800,0))
Sequence(railInterval1, railInterval2).loop()
camera.setPos(15,0,2)
camera.setHpr(90,0,0)
pLight = DirectionalLight('pLinght')
pLight.setColor(Vec4(0.8,0.8,0.8,1))
plnp = render.attachNewNode(pLight)
plnp.setHpr(30,-60,0)
render.setLight(plnp)
ambientLight = AmbientLight('abmientLight')
alnp = render.attachNewNode(ambientLight)
render.setLight(alnp)
##########################################################################
audio3d = Audio3DManager.Audio3DManager(base.sfxManagerList[0], camera)
sound1 = audio3d.loadSfx('299.wav')
sound2 = audio3d.loadSfx('299.wav')
sound1.setLoop(True)
sound2.setLoop(True)
sound1.play()
sound2.play()
audio3d.attachSoundToObject(sound1, self.train1)
audio3d.attachSoundToObject(sound2, self.train2)
base.cTrav = CollisionTraverser()
audio3d.setSoundVelocityAuto(sound1)
audio3d.setSoundVelocityAuto(sound2)
audio3d.setListenerVelocityAuto()
audio3d.setDopplerFactor(40)
##########################################################################
def task(self, task):
centerx = base.win.getProperties().getXSize()/2
centery = base.win.getProperties().getYSize()/2
base.win.movePointer(0, centerx, centery)
if base.mouseWatcherNode.hasMouse():
x = base.mouseWatcherNode.getMouseX()
y = base.mouseWatcherNode.getMouseY()
camera.setH(camera.getH()-x*10)
camera.setP(camera.getP()+y*10)
return task.again
app = MyApp()
app.run()
and video:
tudou.com/programs/view/j5GoLHAQKBo/
flash=640,480http://www.tudou.com/v/j5GoLHAQKBo/&rpid=25577351&resourceId=25577351_04_05_99/v.swf/flash
I did not get the Doppler effect.