void ClientGameObjectManagerAddon::createSpaceShip(int &threadOwnershipMask)
{

	//create hierarchy:
	//scene root
	//  scene node // tracks position/orientation
	//    SpaceShip

	//game object manager
	//  SpaceShipController
	//    scene node

	PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
	MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);

	pMeshInstance->addDefaultComponents();
	pMeshInstance->initFromFile("space_frigate_6.mesha", "FregateTest", threadOwnershipMask);

	// need to create a scene node for this mesh
	PE::Handle hSN("SCENE_NODE", sizeof(SceneNode));
	SceneNode *pSN = new(hSN) SceneNode(*m_pContext, m_arena, hSN);
	pSN->addDefaultComponents();

	Vector3 spawnPos(0, 0, 0.0f);
	pSN->m_base.setPos(spawnPos);

	pSN->addComponent(hMeshInstance);

	RootSceneNode::Instance()->addComponent(hSN);

	// now add game objects

	PE::Handle hSpaceShip("ClientSpaceShip", sizeof(ClientSpaceShip));
	ClientSpaceShip *pSpaceShip = new(hSpaceShip) ClientSpaceShip(*m_pContext, m_arena, hSpaceShip, 0.05f, spawnPos,  0.05f);
	pSpaceShip->addDefaultComponents();

	addComponent(hSpaceShip);

	// add the same scene node to tank controller
	static int alllowedEventsToPropagate[] = {0}; // we will pass empty array as allowed events to propagate so that when we add
	// scene node to the square controller, the square controller doesnt try to handle scene node's events
	// because scene node handles events through scene graph, and is child of space ship just for referencing purposes
	pSpaceShip->addComponent(hSN, &alllowedEventsToPropagate[0]);

	pSpaceShip->activate();
}
void ClientGameObjectManagerAddon::createTank(int index, int &threadOwnershipMask)
{

	//create hierarchy:
	//scene root
	//  scene node // tracks position/orientation
	//    Tank

	//game object manager
	//  TankController
	//    scene node
	
	PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
	MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);

	pMeshInstance->addDefaultComponents();
	pMeshInstance->initFromFile("kingtiger.x_main_mesh.mesha", "Default", threadOwnershipMask);

	// need to create a scene node for this mesh
	PE::Handle hSN("SCENE_NODE", sizeof(SceneNode));
	SceneNode *pSN = new(hSN) SceneNode(*m_pContext, m_arena, hSN);
	pSN->addDefaultComponents();

	Vector3 spawnPos(-36.0f + 6.0f * index, 0 , 21.0f);
	pSN->m_base.setPos(spawnPos);
	
	pSN->addComponent(hMeshInstance);

	RootSceneNode::Instance()->addComponent(hSN);

	// now add game objects

	PE::Handle hTankController("TankController", sizeof(TankController));
	TankController *pTankController = new(hTankController) TankController(*m_pContext, m_arena, hTankController, 0.05f, spawnPos,  0.05f);
	pTankController->addDefaultComponents();

	addComponent(hTankController);

	// add the same scene node to tank controller
	static int alllowedEventsToPropagate[] = {0}; // we will pass empty array as allowed events to propagate so that when we add
	// scene node to the square controller, the square controller doesnt try to handle scene node's events
	// because scene node handles events through scene graph, and is child of square controller just for referencing purposes
	pTankController->addComponent(hSN, &alllowedEventsToPropagate[0]);
}
Exemplo n.º 3
0
Flyer::Flyer(PE::GameContext &context, PE::MemoryArena arena, PE::Handle hMyself, int &threadOwnershipMask) 
: Component(context, arena, hMyself)
, m_prevCameraType(CameraManager::CameraType_Count)
{
	// NUI testing
#ifdef _XBOX
	// Could also try for a bit more smoothing ( 0.25f, 0.25f, 0.25f, 0.03f, 0.05f );
	m_JointFilter.Init( 0.5f, 0.5f, 0.5f, 0.05f, 0.05f );

	// create event which will be signaled when frame processing ends
	m_hFrameEndEvent = CreateEvent( NULL,
		FALSE,  // auto-reset
		FALSE,  // create unsignaled
		"NuiFrameEndEvent" );

	if ( !m_hFrameEndEvent )
	{
		ATG_PrintError( "Failed to create NuiFrameEndEvent\n" );
		return;
		// return E_FAIL;
	}

	HRESULT hr = NuiInitialize( NUI_INITIALIZE_FLAG_USES_SKELETON |
		NUI_INITIALIZE_FLAG_USES_COLOR |
		NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX,
		NUI_INITIALIZE_DEFAULT_HARDWARE_THREAD );

	if( FAILED( hr ))
	{
		ATG::NuiPrintError( hr, "NuiInitialize" );
		return;
		// return E_FAIL;
	}
	
	// register frame end event with NUI
	hr = NuiSetFrameEndEvent( m_hFrameEndEvent, 0 );
	if( FAILED(hr) )
	{
		ATG::NuiPrintError( hr, "NuiSetFrameEndEvent" );
		return;
		// return E_FAIL;
	}

	/*
	// Open the color stream
	hr = NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 1, NULL, &m_hImage );
	if( FAILED (hr) )
	{
		ATG::NuiPrintError( hr, "NuiImageStreamOpen" );
		return E_FAIL;
	}

	// Open the depth stream
	hr = NuiImageStreamOpen( NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, NUI_IMAGE_RESOLUTION_320x240, 0, 1, NULL, &m_hDepth );
	if( FAILED (hr) )
	{
		ATG::NuiPrintError( hr, "NuiImageStreamOpen" );
		return E_FAIL;
	}
	*/
	hr = NuiSkeletonTrackingEnable( NULL, 0 );
	if( FAILED( hr ))
	{
		ATG::NuiPrintError( hr, "NuiSkeletonTrackingEnable" );
	}

	m_pNuiJointConverterConstrained = new ATG::NuiJointConverter();
	if( m_pNuiJointConverterConstrained == NULL )
	{
		// return E_FAIL;
		return;
	}

	m_pNuiJointConverterConstrained->AddDefaultConstraints();
	
	Handle hSN("SceneNode", sizeof(SceneNode));
	m_pNuiSN = new(hSN) SceneNode(context, arena, hSN);
	m_pNuiSN->addDefaultComponents();
	m_pNuiSN->m_base.setPos(Vector3(0.0f, 0, 25.0f));
	m_pNuiSN->m_base.turnRight(1.2f * 3.1415f);
	RootSceneNode::Instance()->addComponent(hSN);
	for (int i = 0; i < XAVATAR_MAX_SKELETON_JOINTS; i++)
	{
		PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
		MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);
		pMeshInstance->addDefaultComponents();

		pMeshInstance->initFromFile("box.x_main_mesh.mesha", "Default", threadOwnershipMask);
		
		Handle hSN("SceneNode", sizeof(SceneNode));
		m_sceneNodes[i] = new(hSN) SceneNode(context, arena, hSN);
		m_sceneNodes[i]->addDefaultComponents();
		m_sceneNodes[i]->addComponent(hMeshInstance);
		m_pNuiSN->addComponent(hSN);

		if (m_pNuiJointConverterConstrained->MapAvatarJointToNUI_POSITION_INDEX(i) == NUI_SKELETON_POSITION_SHOULDER_RIGHT)
		{
			PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
			MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);
			pMeshInstance->addDefaultComponents();
			pMeshInstance->initFromFile("wings.x_rwing_mesh.mesha", "City", threadOwnershipMask);
			
			m_sceneNodes[i]->addComponent(hMeshInstance);
		}

		if (m_pNuiJointConverterConstrained->MapAvatarJointToNUI_POSITION_INDEX(i) == NUI_SKELETON_POSITION_SHOULDER_LEFT)
		{
			
			PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
			MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);

			pMeshInstance->addDefaultComponents();
			pMeshInstance->initFromFile("wings.x_lwing_mesh.mesha", "City", threadOwnershipMask);

			m_sceneNodes[i]->addComponent(hMeshInstance);
		}
	}
	{
			// put a camera here

		PE::Handle hMeshInstance("MeshInstance", sizeof(MeshInstance));
		MeshInstance *pMeshInstance = new(hMeshInstance) MeshInstance(*m_pContext, m_arena, hMeshInstance);

		pMeshInstance->addDefaultComponents();
		pMeshInstance->initFromFile("box.x_main_mesh.mesha", "Default", threadOwnershipMask);

		// we put camera in a scene node so we can rotate the camera within that scene node, but we could have also just added camera on its own
		Handle hSN("SceneNode", sizeof(SceneNode));
		m_pCamSN = new(hSN) SceneNode(context, arena,hSN);
		m_pCamSN->addDefaultComponents();
		m_pCamSN->addComponent(hMeshInstance);
		m_pNuiSN->addComponent(hSN);
		m_pCamSN->m_base.setPos(Vector3(0, +1.0f, +1.5f));

		Handle hDebugCamera("Camera", sizeof(Camera));
		Camera *debugCamera = new(hDebugCamera) Camera(context, arena, hDebugCamera, hSN);
		debugCamera->addDefaultComponents();
		CameraManager::Instance()->setCamera(CameraManager::PLAYER, hDebugCamera);
		//SceneNode *pCamSN = debugCamera->getCamSceneNode();

		}
	m_framesWithNoData = 0;
	m_framesWithData = 0;
#endif // #ifdef _XBOX
}