void BasePlayerImplementation::setCameraMode( unsigned int mode ) { switch ( mode ) { case Spheric: { _p_camera->setCameraOffsetPosition( _playerAttributes._camPosOffsetSpheric ); osg::Quat rot; rot.makeRotate( osg::DegreesToRadians( _playerAttributes._camRotOffsetSpheric.x() ), osg::Vec3f( 0.0f, 1.0f, 0.0f ), // roll osg::DegreesToRadians( _playerAttributes._camRotOffsetSpheric.y() ), osg::Vec3f( 1.0f, 0.0f, 0.0f ), // pitch osg::DegreesToRadians( _playerAttributes._camRotOffsetSpheric.z() ), osg::Vec3f( 0.0f, 0.0f, 1.0f ) // yaw ); _p_camera->setCameraOffsetRotation( rot ); // re-add to scenegraph ( actually we remove it first just to be on safe side ) removeFromSceneGraph(); addToSceneGraph(); } break; case Ego: { _p_camera->setCameraOffsetPosition( _playerAttributes._camPosOffsetEgo ); osg::Quat rot; rot.makeRotate( osg::DegreesToRadians( _playerAttributes._camRotOffsetEgo.x() ), osg::Vec3f( 0.0f, 1.0f, 0.0f ), // roll osg::DegreesToRadians( _playerAttributes._camRotOffsetEgo.y() ), osg::Vec3f( 1.0f, 0.0f, 0.0f ), // pitch osg::DegreesToRadians( _playerAttributes._camRotOffsetEgo.z() ), osg::Vec3f( 0.0f, 0.0f, 1.0f ) // yaw ); _p_camera->setCameraOffsetRotation( rot ); removeFromSceneGraph(); } break; default: assert( NULL && "requesting for an invalid camera mode" ); } _cameraMode = static_cast< CameraMode >( mode ); }
void BasePlayerImplementation::addToSceneGraph() { // first remove the entity transformation node from its parent(s) ( default entity group of level manager or shadow manager ) removeFromSceneGraph(); if ( _cgfShadow ) { // add it to shadow manager as only shadow thrower yaf3d::ShadowManager::get()->addShadowNode( getPlayerEntity()->getTransformationNode(), yaf3d::ShadowManager::eThrowShadow ); } // add it also to level manager's entity node as the entity mesh does not receive shadows yaf3d::EntityManager::get()->addToScene( getPlayerEntity() ); }
void EnMesh::enable( bool en ) { if ( _enable == en ) return; if ( _mesh.valid() ) { if ( en ) { addToSceneGraph(); } else { removeFromSceneGraph(); } _enable = en; } else { _enable = false; } }
void EnMesh::handleNotification( const yaf3d::EntityNotification& notification ) { // handle notifications, add and remove the transformation node to / from scenegraph on menu entring / leaving switch( notification.getId() ) { case YAF3D_NOTIFY_MENU_ENTER: { if ( _enable ) { if ( _usedInMenu ) { addToSceneGraph(); } else { removeFromSceneGraph(); } } } break; case YAF3D_NOTIFY_MENU_LEAVE: { if ( _enable ) { if ( _usedInMenu ) { removeFromSceneGraph(); } else { addToSceneGraph(); } } } break; //! Note: by default the level manager re-adds persistent entity transformation nodes to its entity group while unloading a level. // thus we have to remove shadow nodes from that entity group on unloading a level; addToSceneGraph() does this job. case YAF3D_NOTIFY_ENTITY_TRANSNODE_CHANGED: { if ( _usedInMenu ) { // this method really removes the node from all its parents yaf3d::EntityManager::get()->removeFromScene( this ); // now add it to scene graph again addToSceneGraph(); } } break; case YAF3D_NOTIFY_ENTITY_ATTRIBUTE_CHANGED: { // re-setup mesh if ( _mesh.valid() ) removeFromTransformationNode( _mesh.get() ); _mesh = setupMesh(); if ( _mesh.valid() && _enable ) addToTransformationNode( _mesh.get() ); // if the attribute changes then we enable rendering regardless of current state // this method really removes the node from all its parents yaf3d::EntityManager::get()->removeFromScene( this ); // now add it to scene graph again addToSceneGraph(); } break; case YAF3D_NOTIFY_UNLOAD_LEVEL: if ( !_usedInMenu ) removeFromSceneGraph(); break; // if used in menu then this entity is persisten, so we have to trigger its deletion on shutdown case YAF3D_NOTIFY_SHUTDOWN: { removeFromTransformationNode( _mesh.get() ); if ( _usedInMenu ) yaf3d::EntityManager::get()->deleteEntity( this ); } break; default: ; } }
PedestrianGeometry::~PedestrianGeometry() { removeFromSceneGraph(); }
void PlayerImplStandalone::handleNotification( const yaf3d::EntityNotification& notification ) { // handle some notifications switch( notification.getId() ) { case YAF3D_NOTIFY_MENU_ENTER: getChatManager()->show( false ); if ( _p_inputHandler ) _p_inputHandler->setMenuEnabled( true ); // reset player's movement and sound if ( _p_playerPhysics ) _p_playerPhysics->stopMovement(); if ( _p_playerAnimation ) _p_playerAnimation->animIdle(); if ( _p_playerSound ) _p_playerSound->stopPlayingAll(); // very important: diable the camera when we enter menu! if ( _p_camera ) _p_camera->setEnable( false ); // players are all rendered in menu, regardless of their camera mode if ( _cameraMode == Ego ) addToSceneGraph(); break; case YAF3D_NOTIFY_MENU_LEAVE: { getChatManager()->show( true ); if ( _p_inputHandler ) { _p_inputHandler->setMenuEnabled( false ); // refresh our configuration settings getConfiguration(); } // very important: enable the camera when we leave menu! if ( _p_camera ) _p_camera->setEnable( true ); // if we are in ego mode then disable player avatar rendering if ( _cameraMode == Ego ) removeFromSceneGraph(); } break; case YAF3D_NOTIFY_SHUTDOWN: case YAF3D_NOTIFY_UNLOAD_LEVEL: { // destroy the chat manager destroyChatManager(); } break; default: ; } }
void PlayerImplStandalone::postInitialize() { log_info << " setup player implementation Standalone ..." << std::endl; // attach camera entity log_debug << " - searching for camera entity '" << PLAYER_CAMERA_ENTITIY_NAME << "'..." << std::endl; // get camera entity _p_camera = dynamic_cast< EnCamera* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_CAMERA, PLAYER_CAMERA_ENTITIY_NAME ) ); if ( _p_camera ) { log_debug << " - camera entity successfully attached" << std::endl; } else { log_error << " could not attach player camera entity" << std::endl; } // attach physics entity log_debug << " - searching for physics entity '" << _playerAttributes._physicsEntity << "' ..." << std::endl; // find and attach physics component _p_playerPhysics = dynamic_cast< EnPlayerPhysics* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_PLPHYS, _playerAttributes._physicsEntity ) ); if ( _p_playerPhysics ) { _p_playerPhysics->setPlayer( this ); _p_playerPhysics->initializePhysics( _currentPos, _currentRot ); log_debug << " - physics entity successfully attached" << std::endl; } else { log_error << " could not attach player physics entity" << std::endl; } // attach animation entity log_debug << " - searching for animation entity '" << _playerAttributes._animationEntity << "' ..." << std::endl; // find and attach animation component _p_playerAnimation = dynamic_cast< EnPlayerAnimation* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_PLANIM, _playerAttributes._animationEntity ) ); if ( _p_playerAnimation ) { _p_playerAnimation->setPlayer( this ); log_debug << " - animation entity successfully attached" << std::endl; if ( _cameraMode == Ego ) // in ego mode we won't render our character { removeFromSceneGraph(); } else // if in spheric mode disable the mouse pointer { gameutils::GuiUtils::get()->showMousePointer( false ); } } else { log_error << " could not attach player animation entity" << std::endl; } // attach sound entity log_debug << " - searching for sound entity '" << _playerAttributes._soundEntity << "' ..." << std::endl; // find and attach sound component, tollerate missing sound for now _p_playerSound = dynamic_cast< EnPlayerSound* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_PLSOUND, _playerAttributes._soundEntity ) ); if ( !_p_playerSound ) log_error << " could not find sound entity '" << _playerAttributes._soundEntity << "' of type PlayerSound. player sound deactivated" << std::endl; else { _p_playerSound->setPlayer( this ); log_debug << " - sound entity successfully attached" << std::endl; } // setup camera mode setCameraMode( _cameraMode ); // create the chat manager if ( !createChatManager() ) { log_error << " - could not create chat system" << std::endl; } log_info << " player implementation successfully initialized" << std::endl; // create only the input handler when animation and physics are attached if ( _p_playerAnimation && _p_playerPhysics ) { // create a new input handler for this player _p_inputHandler = new PlayerIHCharacterCameraCtrl< PlayerImplStandalone >( this, getPlayerEntity() ); _p_inputHandler->setMenuEnabled( false ); // get configuration settings getConfiguration(); } // set initial camera transformation if ( _p_camera ) _p_camera->setCameraTransformation( getPlayerPosition(), getPlayerRotation() ); }