Ejemplo n.º 1
0
void SetShaderToEntity( EntityHandle<>& entity, ShaderHandle& shader, ShaderTechniqueHandle& tech )
{
	shared_ptr<CCopyEntity> pEntity = entity.Get();
	if( !pEntity )
		return;

	if( !pEntity->m_pMeshRenderMethod )
	{
		pEntity->m_pMeshRenderMethod.reset( new MeshContainerRenderMethod );
	}

//	vector<SubsetRenderMethod>& render_methods
//		= pEntity->m_pMeshRenderMethod->m_vecMeshRenderMethod;

//	if( render_methods.empty() )
//		render_methods.resize( 1 );

	SubsetRenderMethod& render_method = pEntity->m_pMeshRenderMethod->PrimaryMeshRenderMethod();

	render_method.m_Shader = shader;
	render_method.m_Technique = tech;

	if( pEntity->GetEntityFlags() & BETYPE_LIGHTING )
	{
		vector< shared_ptr<ShaderParamsLoader> >& params_loaders =
			render_method.m_vecpShaderParamsLoader;

		int params_loader_index = -1;
		for( size_t i=0; i<params_loaders.size(); i++ )
		{
			if( params_loaders[i]
			&& typeid(*params_loaders[i]) == typeid(CEntityShaderLightParamsLoader) )
			{
				params_loader_index = (int)i;
				break;
			}
		}

		if( params_loader_index == -1 )
//		if( params_loaders.empty() )
		{
			// Params loader for lighting was not found - add to the list of params loaders
			params_loaders.push_back( shared_ptr<ShaderParamsLoader>() );
			params_loaders.back()
				= shared_ptr<ShaderParamsLoader>( new CEntityShaderLightParamsLoader(pEntity) );
//			params_loader_index = (int)params_loaders.size() - 1;
		}
	}
}
Ejemplo n.º 2
0
// Creates a default render method for the entity.
// - If the lighting is enabled for the entity, a light parameter loader is set
// - If the mesh of the entity is skeletal, a blend transforms loader is set.
void CreateMeshRenderMethod( EntityHandle<>& entity, 
							 ShaderHandle& shader,
							 ShaderTechniqueHandle& tech )
{
	shared_ptr<CCopyEntity> pEntity = entity.Get();

	if( !pEntity )
		return;

	// create mesh render method from shader and shader technique of the base entity

	pEntity->m_pMeshRenderMethod.reset( new MeshContainerRenderMethod() );

	SubsetRenderMethod& render_method = pEntity->m_pMeshRenderMethod->PrimaryMeshRenderMethod();
	render_method.m_Shader    = shader;
	render_method.m_Technique = tech;

	InitMeshRenderMethod( *pEntity );
}
Ejemplo n.º 3
0
	void UpdateShaderParams( ShaderManager& rShaderMgr )
	{
		boost::shared_ptr<CCopyEntity> pEntity = m_Entity.Get();
		if( pEntity )
			SetLightsToShader( *(pEntity.get()), rShaderMgr );
	}
CCharacterMotionControlAppTask::CCharacterMotionControlAppTask()
:
m_vPrevCamPos( Vector3(0,0,0) )
{
	ScriptManager::ms_UseBoostPythonModules = true;

	m_pKeyBind.reset( new KeyBind );

	// keyboad & mouse keybinds
	m_pKeyBind->Assign( GIC_UP,              ACTION_MOV_FORWARD );
	m_pKeyBind->Assign( GIC_DOWN,            ACTION_MOV_BACKWARD );
	m_pKeyBind->Assign( GIC_RIGHT,           ACTION_MOV_TURN_R );
	m_pKeyBind->Assign( GIC_LEFT,            ACTION_MOV_TURN_L );
	m_pKeyBind->Assign( GIC_LSHIFT,          ACTION_MOV_BOOST );
	m_pKeyBind->Assign( GIC_SPACE,           ACTION_MOV_JUMP );
	m_pKeyBind->Assign( GIC_MOUSE_BUTTON_L,  ACTION_ATK_FIRE);
	m_pKeyBind->Assign( 'G',                 ACTION_ATK_FIRE);
	m_pKeyBind->Assign( GIC_MOUSE_BUTTON_R,  ACTION_CAMERA_ALIGN );
	m_pKeyBind->Assign( 'Z',                 ACTION_CAMERA_ALIGN );

	// for FPS dudes
	m_pKeyBind->Assign( 'W',                 ACTION_MOV_FORWARD );
	m_pKeyBind->Assign( 'S',                 ACTION_MOV_BACKWARD );
	m_pKeyBind->Assign( 'D',                 ACTION_MOV_TURN_R );
	m_pKeyBind->Assign( 'A',                 ACTION_MOV_TURN_L );

	// gamepad keybinds
	m_pKeyBind->Assign( GIC_GPD_BUTTON_00,   ACTION_CAMERA_ALIGN );
	m_pKeyBind->Assign( GIC_GPD_BUTTON_01,   ACTION_MOV_JUMP );

	// analog input
	// - may need to invert the fParam1.
	// - inversion is currently turned on, and is done in CCharacterMotionNodeAlgorithm::HandleInput()
//	m_pKeyBind->Assign( GIC_GPD_AXIS_Y,   ACTION_MOV_FORWARD );
	m_pKeyBind->Assign( GIC_GPD_AXIS_Y,   ACTION_MOV_BACKWARD );
	m_pKeyBind->Assign( GIC_GPD_AXIS_X,   ACTION_MOV_TURN_R );
//	m_pKeyBind->Assign( GIC_GPD_AXIS_Z,   ACTION_MOV_TURN_R );

	m_pKeyBind->Assign( GIC_MOUSE_AXIS_Y, ACTION_MOV_LOOK_UP );

	StageLoader stg_loader;
//	m_pStage = stg_loader.LoadStage( "shadow_for_directional_light.bin" );
	m_pStage = stg_loader.LoadStage( sg_TestStageScriptToLoad );

	GetCameraController()->SetPose( Matrix34( Vector3(0.8f,1.9f,-3.5f), Matrix33Identity() ) );

	m_pThirdPersonCameraController.reset( new ThirdPersonCameraController );

	m_pThirdPersonMotionController.reset( new ThirdPersonMotionController );

	// trigger shape that detects collision of the character and other objects
	physics::CCapsuleShapeDesc cap_desc;
	cap_desc.fLength = 1.00f;
	cap_desc.fRadius = 0.25f;
//	cap_desc.ShapeFlags = physics::ShapeFlag::TriggerEnable;

	// core - used to make actor desc valid
//	physics::CBoxShapeDesc core_box_desc;
//	core_box_desc.vSideLength = Vector3(1,1,1) * 0.01f;

	physics::CActorDesc actor_desc;
	actor_desc.WorldPose = Matrix34Identity();
//	actor_desc.WorldPose.vPosition = Vector3( 380.0f, 20.0f, 320.0f );
	actor_desc.WorldPose.vPosition = Vector3( 0.0f, 1.0f, 0.0f );
	actor_desc.BodyDesc.fMass = 0.1f;
	actor_desc.BodyDesc.LinearVelocity = Vector3(0,0,0);
//	actor_desc.BodyDesc.Flags = physics::PhysBodyFlag::Kinematic;
	actor_desc.BodyDesc.Flags = physics::PhysBodyFlag::DisableGravity;
	actor_desc.vecpShapeDesc.push_back( &cap_desc );
//	actor_desc.vecpShapeDesc.push_back( &core_box_desc );

	string motion_fsm_filepath = "motions/test_motion_fsm.bin";

	const int num_characters = 1;
	m_pCharacterItems.resize( num_characters );
	const char *meshes[] = { "models/male_skinny_young.msh", "models/female99-age17-muscle73-weight66-height1.52.msh" };
	for( int i=0; i<num_characters; i++ )
	{
		m_pCharacterItems[i].reset( new SkeletalCharacter );

		Result::Name res = m_pCharacterItems[i]->LoadCharacterMesh( meshes[i] );

		m_pCharacterItems[i]->InitMotionFSMs( motion_fsm_filepath );

		vector< shared_ptr<CCharacterMotionNodeAlgorithm> > pMotionNodes;
		pMotionNodes.resize( 4 );
		pMotionNodes[0].reset( new CFwdMotionNode );
		pMotionNodes[1].reset( new CRunMotionNode );
		pMotionNodes[2].reset( new CStandingMotionNode );
		pMotionNodes[3].reset( new CJumpMotionNode );

		const char *motion_names[] = { "fwd", "run", "standing", "vertical_jump" };
		for( size_t j=0; j<pMotionNodes.size(); j++ )
			m_pCharacterItems[i]->SetMotionNodeAlgorithm( motion_names[j], pMotionNodes[j] );  

/*		shared_ptr<CMeshObjectContainer> pMeshContainer;
		if( m_pCharacterItems[i]->MeshContainerRootNode().GetNumMeshContainers() == 0 )
		{
			pMeshContainer.reset( new CMeshObjectContainer );
			m_pCharacterItems[i]->MeshContainerRootNode().AddMeshContainer( pMeshContainer );
		}
		else
			pMeshContainer = m_pCharacterItems[i]->MeshContainerRootNode().GetMeshContainer( 0 );

		pMeshContainer->m_MeshDesc.ResourcePath = meshes[i];
		pMeshContainer->m_MeshDesc.MeshType = CMeshType::SKELETAL;
		bool mesh_loaded = m_pCharacterItems[i]->LoadMeshObject();*/
	}

	CItemStageUtility stg_util( m_pStage );
//	shared_ptr<SkeletalCharacter> pCharacter( new SkeletalCharacter ); // create an item
	shared_ptr<GameItem> pItem = m_pCharacterItems[0];
//	EntityHandle<ItemEntity> entity = stg_util.CreateItemEntity( pItem, Vector3(0,0,0) ); // create an entity for the item
	EntityHandle<ItemEntity> entity = stg_util.CreateItemEntity( pItem, actor_desc ); // create an entity for the item
	shared_ptr<ItemEntity> pEntity = entity.Get();
	if( pEntity )
	{
		m_pCharacterItems[0]->OnEntityCreated( *pEntity ); // set pointer of mesh render method to CCopyEntity::m_pMeshRenderMethod
		pEntity->RaiseEntityFlags( BETYPE_LIGHTING );
		pEntity->ClearEntityFlags( BETYPE_USE_PHYSSIM_RESULTS );
		pEntity->sState |= CESTATE_LIGHT_INFORMATION_INVALID;
		pEntity->InitMesh();
//		pEntity->pBaseEntity->SetMeshRenderMethod( *pEntity ); // error: cannot access protected member declared in class 'CBaseEntity'

		if( m_pThirdPersonCameraController )
			m_pThirdPersonCameraController->SetCameraPose( pEntity->GetWorldPose() );
//		m_CameraOrientation.target = m_CameraOrientation.current = Quaternion( pEntity->GetWorldPose().matOrient );
	}

	m_CharacterItemEntity = entity;

	m_pThirdPersonCameraController->SetTargetEntity( EntityHandle<>( weak_ptr<CCopyEntity>(pEntity) ) );

	// set keybind to the character item
	m_pCharacterItems[0]->SetKeyBind( m_pKeyBind );

	m_pThirdPersonMotionController->SetSkeletalCharacter( m_pCharacterItems[0] );

//	m_pInputHandler.reset( new CCharacterMotionInputHandler(pCharacter,m_pKeyBind) );
//	GetInputHub().SetInputHandler( 0, m_pInputHandler.get() );

	m_pInputHandler.reset( new CInputDataDelegate<CCharacterMotionControlAppTask>( this ) );
	if( GetInputHub().GetInputHandler(2) )
		GetInputHub().GetInputHandler(2)->AddChild( m_pInputHandler.get() );
	else
		GetInputHub().PushInputHandler( 2, m_pInputHandler.get() );

	m_ScrollEffect.SetTextureFilepath( "textures/precipitation_mid-density-512.dds" );
//	m_ScrollEffect.SetTextureFilepath( "textures/tex1024_red.bmp" );
	m_ScrollEffect.Init();

	ScaleAnalogInputValueRanges();
}
Ejemplo n.º 5
0
/// NOTE: the specified item is searched in the item list of the single player.
PyObject* CreateEntityFromCurrentVehicleItem( PyObject* self, PyObject* args )
{
    Py_INCREF( Py_None );

//	const char *item_name   = "";
	const char *entity_name = "";
	const char *base_name   = "";
	Vector3 pos = Vector3(0,0,0), vel = Vector3(0,0,0);
	float heading = 0, pitch = 0, roll = 0;

	int result = PyArg_ParseTuple( args, "|ssfffffffff",
//		&item_name,
		&entity_name, &base_name,
		&pos.x, &pos.y, &pos.z,
		&heading, &pitch, &roll,
		&vel.x, &vel.y, &vel.z );

	CStage *pStage = GetStageForScriptCallback();
	if( !pStage )
		return Py_None;

	BaseEntityHandle base_entity_handle;
	base_entity_handle.SetBaseEntityName( base_name );

	bool loaded = pStage->GetEntitySet()->LoadBaseEntity( base_entity_handle );

	BaseEntity *pBaseEntity = pStage->GetEntitySet()->FindBaseEntity( base_name );
	if( !pBaseEntity )
		return Py_None;

	CItemStageUtility item_stg_util( pStage->GetWeakPtr().lock() );

//	boost::shared_ptr<GameItem> pItem = SinglePlayerInfo().GetItemByName<GameItem>(item_name);
//	if( !pItem )
//		return Py_None;

	boost::shared_ptr<CGI_Aircraft> pVehicle = SinglePlayerInfo().GetAircraft();
	if( !pVehicle )
		return Py_None;

	Matrix33 matOrient = Matrix33RotationHPR_deg( heading, pitch, roll );

	physics::CActorDesc actor_desc = pBaseEntity->GetPhysicsActorDesc();
	actor_desc.WorldPose.vPosition = pos;
	actor_desc.WorldPose.matOrient = matOrient;

	EntityHandle<ItemEntity> entity = item_stg_util.CreateItemEntity( pVehicle, base_entity_handle, actor_desc );

	boost::shared_ptr<ItemEntity> pEntity = entity.Get();
	if( pEntity )
	{
		pEntity->SetName( entity_name );
		pEntity->GroupIndex = pBaseEntity->GetEntityGroupID();
		pEntity->SetItemEntityFlags( ItemEntity::SF_USE_ENTITY_ATTRIBUTES_FOR_RENDERING );
		pEntity->InitMesh();
	}
	else
		LOG_PRINT_WARNING( fmt_string(" Failed to create the item entity (entity name: %s).", entity_name) );

	return Py_None;
}