//----------------------------------------------------------------------------------- void World::makeBullets() { float _rotation = getPlayerRotation(); Vec4 position = getPlayerPosition(); Vec4 offset = getPlayerPosition(); Vec4 colour = Vec4(1.0f, 1.0f, 1.0f); Vec4 size = Vec4(0.2f, 0.2f, 0.2f); Vec4 destination( (0.1*sin((PI *_rotation)/180)), 0, (0.1*cos((PI *_rotation)/180)) ); Bullet* tmp = new Bullet(position, offset, colour, size, destination); //Vec4(position.m_x - 0.1, position.m_y - 0.1, position.m_z - 0.1), //Vec4(position.m_x + 0.1,position.m_y + 0.1,position.m_z + 0.1)); m_bodies.push_back(tmp); }
void PlayerImplStandalone::update( float deltaTime ) { // first update the physics entity getPlayerPhysics()->updateEntity( deltaTime ); // update player's actual position and rotation once per frame getPlayerEntity()->setPosition( _currentPos ); getPlayerEntity()->setRotation( _currentRot ); // adjust the camera to updated position and rotation. the physics updates the translation of player. if ( _p_camera ) _p_camera->setCameraTransformation( getPlayerPosition(), getPlayerRotation() ); getChatManager()->update( deltaTime ); // update sound getPlayerSound()->updatePosition( _currentPos ); }
void PlayerImplClient::update( float deltaTime ) { // first update the physics entity getPlayerPhysics()->updateEntity( deltaTime ); if ( !_isRemoteClient ) { // update player's actual position and rotation once per frame getPlayerEntity()->setPosition( _currentPos ); getPlayerEntity()->setRotation( _currentRot ); getPlayerNetworking()->updatePosition( _currentPos._v[ 0 ], _currentPos._v[ 1 ], _currentPos._v[ 2 ] ); getPlayerNetworking()->updateRotation( _rotZ + osg::PI ); getPlayerNetworking()->updateAnimationFlags( getPlayerAnimation()->getAnimationFlags() ); // adjust the camera to updated position and rotation. the physics updates the translation of player. _p_camera->setCameraTranslation( getPlayerPosition(), getPlayerRotation() ); // update chat gui getChatManager()->update( deltaTime ); } else { // update remote client's rotation and position osg::Vec3f lastpos = _currentPos; float lastrot = _rotZ; osg::Vec3f clientpos; getPlayerNetworking()->getPosition( clientpos._v[ 0 ], clientpos._v[ 1 ], clientpos._v[ 2 ] ); getPlayerNetworking()->getRotation( _rotZ ); _currentRot.makeRotate( -_rotZ + osg::PI, osg::Vec3f( 0.0f, 0.0f, 1.0f ) ); getPlayerEntity()->setRotation( _currentRot ); getPlayerEntity()->setPosition( _currentPos ); // calculate the current velocity osg::Vec3f vel( clientpos - lastpos ); // do we need a hard position correction? if ( vel.length2() > NW_POS_CORRECTION_THRESHOLD ) { osg::Matrix mat; mat.makeRotate( _currentRot ); //mat.setTrans( lastpos + vel * deltaTime ); mat.setTrans( clientpos ); getPlayerPhysics()->setTransformation( mat ); getPlayerPhysics()->setDirection( 0.0f, 0.0f ); } else { vel._v[ 2 ] = 0.0f; // limit velocity if ( vel.length2() > 1.0f ) vel.normalize(); getPlayerPhysics()->setDirection( vel.x(), vel.y() ); } // set animation depending on position and rotation changes if ( ( ( clientpos.z() - lastpos.z() ) > NW_JUMP_THRESHOLD ) && !getPlayerPhysics()->isJumping() ) { getPlayerPhysics()->jump(); getPlayerAnimation()->setAnimation( EnPlayerAnimation::eIdle ); getPlayerAnimation()->setAnimation( EnPlayerAnimation::eJump ); } else if ( vel.length2() > NW_WALK_THRESHOLD ) { getPlayerAnimation()->setAnimation( EnPlayerAnimation::eWalk ); } else { getPlayerAnimation()->setAnimation( EnPlayerAnimation::eIdle ); } if ( fabs( lastrot - _rotZ ) > NW_ROT_THRESHOLD ) getPlayerAnimation()->setAnimation( EnPlayerAnimation::eTurn ); } // update sound getPlayerSound()->updatePosition( _currentPos ); }
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() ); }