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]); }