📄 cameratrackingdemo.py
字号:
# CameraTracking.py
import localogre as ogre
import sampleframework
class CameraTrackApplication(sampleframework.Application):
def _createScene( self ):
sceneManager = self.sceneManager
sceneManager.setAmbientLight( ogre.ColourValue(0.2,0.2,0.2) )
sceneManager.setSkyDome( True, 'Examples/CloudySky', 4.0, 8.0 )
light = sceneManager.createLight( 'MainLight' )
light.setPosition( 20, 80, 50 )
plane = ogre.Plane()
plane.normal = ogre.Vector3.UNIT_Y
plane.d = 200
planeSpecification = ogre.PlaneSpecification( plane, 200000.0, 200000.0 )
planeSpecification.setTesselation( 20, 20 )
planeSpecification.setTiling( 50.0, 50.0 )
planeSpecification.upVector = ogre.Vector3.UNIT_Z
ogre.MeshManager.getSingleton().createPlane( 'FloorPlane',
planeSpecification )
##ogre.MeshManager.getSingleton().createPlane( 'FloorPlane',plane,
## 200000.0,200000.0,
## 20, 20,
## True,1,
## 50.0,50.0,
## ogre.Vector3.UNIT_Z ) # hardware stuff parameters...
# create floor entity
entity = sceneManager.createEntity( 'floor', 'FloorPlane' )
entity.setMaterialName( 'Examples/RustySteel' )
sceneManager.getRootSceneNode().createChildSceneNode( ogre.Vector3.ZERO, ogre.Quaternion.IDENTITY ).attachObject( entity )
# create head entity
headNode = sceneManager.getRootSceneNode().createChildSceneNode( ogre.Vector3.ZERO, ogre.Quaternion.IDENTITY )
entity = sceneManager.createEntity( 'head', 'ogrehead.mesh' )
headNode.attachObject( entity )
# make sure the camera track this node
self.camera.setAutoTracking( True, headNode )
# create the camera node & attach camera
cameraNode = sceneManager.getRootSceneNode().createChildSceneNode( ogre.Vector3.ZERO, ogre.Quaternion.IDENTITY )
cameraNode.attachObject( self.camera )
# set up spline animation of node
animation = sceneManager.createAnimation( 'CameraTrack', 10 )
animation.setInterpolationMode( ogre.Animation.InterpolationMode.IM_SPLINE )
animationTrack = animation.createTrack( 0, cameraNode )
key = animationTrack.createKeyFrame( 0 )
key = animationTrack.createKeyFrame( 2.5 )
key.setTranslate( ogre.Vector3( 500.0, 500.0, -1000.0 ) )
key = animationTrack.createKeyFrame( 5 )
key.setTranslate( ogre.Vector3( -1500.0, -1500.0, -600.0 ) )
key = animationTrack.createKeyFrame( 7.5 )
key.setTranslate( ogre.Vector3( 0.0, -100.0, 0.0 ) )
key = animationTrack.createKeyFrame( 10.0 )
key.setTranslate( ogre.Vector3( 0.0, 0.0, 0.0 ) )
self.animationState = sceneManager.createAnimationState( 'CameraTrack' )
self.animationState.setEnabled( True )
# add some fog
sceneManager.setFog( ogre.FogMode.FOG_EXP, ogre.ColourValue.White, 0.0002 )
def _createFrameListener( self ):
self.frameListener = CameraTrackListener( self.renderWindow, self.camera, self.animationState )
self.root.addFrameListener( self.frameListener )
class CameraTrackListener(sampleframework.FrameListener):
def __init__( self, renderWindow, camera, animationState ):
sampleframework.FrameListener.__init__( self, renderWindow, camera )
self.animationState = animationState
def frameStarted( self, frameEvent ):
self.animationState.addTime( frameEvent.timeSinceLastFrame )
return sampleframework.FrameListener.frameStarted( self, frameEvent )
if __name__ == '__main__':
application = CameraTrackApplication()
application.go()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -