Dawgmatic
13-01-2006 20:44:24
I just wanted a show of hands, if some people would like to collaborate to develop a framework on top of pyOgre
Dawgmatic
13-01-2006 20:44:24
griminventions
13-01-2006 21:14:21
mthorn
17-01-2006 23:00:16
griminventions
18-01-2006 01:01:03
mthorn
19-01-2006 19:37:44
griminventions
19-01-2006 20:30:30
mthorn
26-01-2006 07:34:01
griminventions
26-01-2006 11:29:33
__author__ = "Jason McIntosh, www.griminventions.com"
from globals import *
import component
import componentManager
import logging
import math
import ogre3d
import pyogre.ogre as ogre
logger = logging.getLogger( "chaseCamComponent" )
logger.addHandler( logHandler )
#------------------------------------------------------------------------------
# ChaseCamComponent
#------------------------------------------------------------------------------
CAM_MODE_SHOULDER = hash( "camShoulderChase" ) # over the shoulder
CAM_MODE_FIXED = hash( "camFixedChase" ) # fixed distance above (not implemented)
CAM_MODE_FREE = hash( "camFreeChase" ) # freely rotate (not implemented)
class ChaseCamComponent( component.Component ):
def __init__( self, name, node = None, **kw ):
component.Component.__init__( self, name, "chaseCamComponent", **kw )
self.node = node # the node to follow
self.camNode = None # node the camera's attached to
self.targetNode = None # node the camera tries to match position to
self.lookAtNode = None # node the camera tracks
self.tightness = 0.075
self.mode = CAM_MODE_SHOULDER
def delete( self ):
logger.debug( "deleting " + self.name )
if self.camNode is not None:
self.camNode.detachAllObjects()
if self.camNode.parentSceneNode is not None:
self.camNode.parentSceneNode.removeChild( self.camNode )
ogre3d.SceneManager.destroySceneNode( self.camNode.name )
self.camNode = None
if self.targetNode is not None:
self.targetNode.detachAllObjects()
if self.targetNode.parentSceneNode is not None:
self.targetNode.parentSceneNode.removeChild( self.targetNode )
ogre3d.SceneManager.destroySceneNode( self.targetNode.name )
self.targetNode = None
if self.lookAtNode is not None:
self.lookAtNode.detachAllObjects()
if self.lookAtNode.parentSceneNode is not None:
self.lookAtNode.parentSceneNode.removeChild( self.lookAtNode )
ogre3d.SceneManager.destroySceneNode( self.lookAtNode.name )
self.lookAtNode = None
self.node = None
def initialize( self ):
componentManager.addUpdater( self, self.getUpdater )
if self.node is None:
self.node = self.entity.getComponentByType( "nodeComponent" )
if self.node is not None and self.node.node is not None:
# targetNode follows the entity rigidly from behind
# the camNode will reposition smoothly to be at the targetNode
self.targetNode = self.node.node.createChildSceneNode( "camTargetNode" )
self.targetNode.position = 0, 10, -100
# the camNode will look at the lookAtNode (in front of entity)
self.lookAtNode = self.node.node.createChildSceneNode( "camLookAtNode" )
self.lookAtNode.position = 0, 0, 150
# camNode will move to follow the entity
self.camNode = self.node.node.parentSceneNode.createChildSceneNode( "camNode" )
self.camNode.setAutoTracking( True, self.lookAtNode )
self.camNode.setFixedYawAxis( True )
self.camNode.attachObject( ogre3d.camera )
def pause( self ):
componentManager.removeUpdater( self )
def unpause( self ):
componentManager.addUpdater( self, self.getUpdater )
def getUpdater( self ):
"Update the camera's position to follow the targetNode."
while True:
if self.mode == CAM_MODE_SHOULDER:
# move cam toward target node
v1 = self.camNode.worldPosition
v2 = self.targetNode.worldPosition
dir = v2 - v1
self.camNode.translate( dir * self.tightness )
# don't let the cam go below the node being chased
x, y, z = v2
x2, y2, z2 = self.camNode.position
if y2 < y + 3:
self.camNode.position = x2, y + 3, z2
# force camera above ground
raySceneQuery = ogre3d.SceneManager.createRayQuery(
ogre.Ray( self.camNode.position, ogre.Vector3.NEGATIVE_UNIT_Y ) )
for queryResult in raySceneQuery.execute():
if queryResult.worldFragment is not None:
if queryResult.distance < 20.0:
x, y, z = self.camNode.position
self.camNode.position = (x, y - queryResult.distance + 20.0, z)
yield None
mthorn
26-01-2006 15:28:22
@mthorn: I'll probably stay with sourceforge, but if you can offer something they can't, I'm definitely interested. Thanks for the generosity!
Kentamanos
26-01-2006 23:54:07
santagada
28-01-2006 17:06:01
griminventions
01-02-2006 13:07:57
This is a great idea, but maybe it would be better using ALPY and not pysonic as fmod is expensive for comercial games.
...if you can please register your project at http://cheeseshop.python.org/pypi so every python programmer has an easy way to find your package.