本文整理汇总了C++中GameObject::AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ GameObject::AddComponent方法的具体用法?C++ GameObject::AddComponent怎么用?C++ GameObject::AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject::AddComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateCameraBox
void CreateCameraBox(Game *pGame)
{
Vector3 pos;
pos.x = 0; pos.y = 0; pos.z = 0;
GameObject *pObj = pGame->CreateObject(pos,Quaternion(pos.x,0,0,0),"testent",eStaticMeshObject,false);
// render mesh component
OgreRenderInstanceComponent *pORC = dynamic_cast<OgreRenderInstanceComponent *>(pGame->CreateComponent(GameComponent::eCom_Render3D));
if (pORC) pORC->Create("Box01.mesh",pObj,true);
pObj->AddComponent(pORC);
// animation handler component
AnimationComponent *pAnim = dynamic_cast<AnimationComponent *>(pGame->CreateComponent(GameComponent::eCom_SimpleAnimation));
pAnim->setParent(pObj);
pAnim->Init(0.001f);
pObj->AddComponent(pAnim);
pGame->AddGob(pObj);
// path controller component
PathCameraComponent *pPath = dynamic_cast<PathCameraComponent *>(pGame->CreateComponent(GameComponent::eCom_PathCameraController));
if(pPath)
{
pObj->AddComponent(pPath);
pPath->Init();
}
}
示例2: CreateRandomRobot
void CreateRandomRobot(Game *pGame)
{
Vector3 pos = pGame->getRandomVector(2000.0f);
GameObject *pRobot = pGame->CreateObject(pos,Quaternion(1,0,0,0),"testent",eStaticMeshObject,false);
OgreRenderInstanceComponent *pORC = dynamic_cast<OgreRenderInstanceComponent *>(pGame->CreateComponent(GameComponent::eCom_Render3D));
if (pORC) pORC->Create("robot.mesh",pRobot,true);
pRobot->AddComponent(pORC);
MoverComponent *pMover = dynamic_cast<MoverComponent *>(pGame->CreateComponent(GameComponent::eCom_SimpleMover));
pMover->setParent(pRobot);
pMover->Init(1000.0f,70.0f,40.0f,pos,1.5f,true);
pRobot->AddComponent(pMover);
AnimationComponent *pAnim = dynamic_cast<AnimationComponent *>(pGame->CreateComponent(GameComponent::eCom_SimpleAnimation));
pAnim->setParent(pRobot);
pAnim->Init(0.001f);
pRobot->AddComponent(pAnim);
// a selector component, this allows a gameobject to know wether its selected or not
SelectionComponent *pSelect = dynamic_cast<SelectionComponent *>(pGame->CreateComponent(GameComponent::eCom_SimpleSelection));
pSelect->setParent(pRobot);
pSelect->Init();
pRobot->AddComponent(pSelect);
pGame->AddGob(pRobot);
}
示例3: Init
void TestGame::Init()
{
GameObject* planeObject = new GameObject();
GameObject* pointLightObject = new GameObject();
GameObject* spotLightObject = new GameObject();
GameObject* directionalLightObject = new GameObject();
planeObject->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks.jpg"), 0.5f, 4,
new Texture("bricks_normal.jpg"),
new Texture("bricks_disp.png"), 0.03f, -0.5f)));
planeObject->GetTransform().SetPos(Vector3f(0, -1, 5));
planeObject->GetTransform().SetScale(4.0f);
pointLightObject->AddComponent(new PointLight(Vector3f(0,1,0),0.4f,Attenuation(0,0,1)));
pointLightObject->GetTransform().SetPos(Vector3f(7,0,7));
spotLightObject->AddComponent(new SpotLight(Vector3f(0,1,1),0.4f,Attenuation(0,0,0.1f),0.7f));
spotLightObject->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), ToRadians(90.0f)));
directionalLightObject->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f));
GameObject* testMesh1 = new GameObject();
GameObject* testMesh2 = new GameObject();
//WARNING: bricks2_normal.jpg is reversed on the y axis. This is intentional, and demonstrates how normal maps are sometimes flipped.
//If you want to fix this, the easiest solution is to flip it in an image editor.
testMesh1->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks2.jpg"), 1, 8,
new Texture("bricks2_normal.jpg"),
new Texture("bricks2_disp.jpg"), 0.04f, -1.0f)));
testMesh2->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks2.jpg"), 1, 8,
new Texture("bricks2_normal.jpg"))));
testMesh1->GetTransform().SetPos(Vector3f(0, 2, 0));
testMesh1->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), 0.4f));
testMesh1->GetTransform().SetScale(1.0f);
testMesh2->GetTransform().SetPos(Vector3f(0, 0, 25));
testMesh1->AddChild(testMesh2);
AddToScene(planeObject);
AddToScene(pointLightObject);
AddToScene(spotLightObject);
AddToScene(directionalLightObject);
AddToScene(testMesh1);
testMesh2->AddChild((new GameObject())
->AddComponent(new Camera(Matrix4f().InitPerspective(ToRadians(70.0f), Window::GetAspect(), 0.1f, 1000.0f)))
->AddComponent(new FreeLook())
->AddComponent(new FreeMove()));
directionalLightObject->GetTransform().SetRot(Quaternion(Vector3f(1,0,0), ToRadians(-45)));
}
示例4:
GameObject* GameObjectManager::Create2DOverlay(const Ogre::Vector3& position, void* data) {
GameObject* go = new GameObject;
Overlay2DComponent* overlayComp = new Overlay2DComponent;
go->AddComponent(overlayComp);
OverlayCollisionCallback* overlayCallBack = new OverlayCollisionCallback;
go->AddComponent(overlayCallBack);
go->AddUpdateable(overlayCallBack);
overlayComp->Init(*static_cast<Ogre::String*>(data));
overlayCallBack->Init(m_input_manager, m_viewport);
return go;
}
示例5: CreatePointLight
GameObject* GameObjectFactory::CreatePointLight(Game* pGame)
{
GameObject* pObject = new GameObject(k_pointLightID, pGame);
//Add Transform Component
TransformComponent* pTransform = m_pComponentFactory->CreateTransformComponent(pObject);
pObject->AddComponent(k_transformComponentID, pTransform);
//Add Point Light Component
PointLightComponent* pPointLightComponent = m_pComponentFactory->CreatePointLightComponent(pObject, pTransform);
pObject->AddComponent(k_pointLightComponentID, pPointLightComponent);
return pObject;
}
示例6: CreateCamera
GameObject* GameObjectFactory::CreateCamera(Game* pGame)
{
GameObject* pObject = new GameObject(k_cameraID, pGame);
//Add Transform Component
TransformComponent* pTransform = m_pComponentFactory->CreateTransformComponent(pObject);
pObject->AddComponent(k_transformComponentID, pTransform);
//Add Camera Component
CameraComponent* pCameraComponent = m_pComponentFactory->CreateCameraComponent(pObject, pTransform, k_pRenderer, k_pTime);
pObject->AddComponent(k_cameraComponentID, pCameraComponent);
return pObject;
}
示例7: CreatePlane
GameObject* GameObjectManager::CreatePlane(const Ogre::Vector3& position, void* data){
GameObject* go = new GameObject(GAME_OBJECT_PLANE);
MeshRenderComponent* mrc = new MeshRenderComponent;
go->AddComponent(mrc);
RigidbodyComponent* rc = new RigidbodyComponent;
go->AddComponent(rc);
PlaneDef& plane_def = *static_cast<PlaneDef*>(data);
mrc->Init(plane_def.plane_name, m_scene_manager);
mrc->GetEntity()->setMaterialName(plane_def.material_name);
rc->Init(position, mrc->GetEntity(), m_physics_engine, 0.0f, COLLIDER_TRIANGLE_MESH_SHAPE, STATIC_BODY);
rc->GetRigidbody()->setRestitution(0.5);
rc->GetRigidbody()->setFriction(0.5f);
return go;
}
示例8: Initialize
void GameManager::Initialize()
{
//Initialize the resource manager
_resourceManager.Initialize(&_graphicsDevice);
//Create the main camera object
GameObject* mainCamera = new GameObject();
mainCamera->GetTransform().SetPosition(-20,15,30);
Camera* cameraComponent = (Camera*)mainCamera->AddComponent(new Camera(mainCamera, CameraType::Perspective()));
AddGameObject(mainCamera); //Takes over the ownership of the game object
//Initialize the renderer
_renderEngine.Initialize(cameraComponent, &_resourceManager, &_graphicsDevice);
_renderEngine.SetClearColor(Color::CornflowerBlue());
//Create the 2D camera
GameObject* camera2D = new GameObject();
//camera2D->GetTransform().SetPosition(Vector3(0.0f,0.0f,-0.1f));
Camera* camera2DComponent = (Camera*)camera2D->AddComponent(new Camera(camera2D, CameraType::Orthographic()));
camera2DComponent->SetNearClip(-1.0f);
camera2DComponent->SetFarClip(1.0f);
AddGameObject(camera2D); //Takes over the ownership of the game object
//Initialize the 2D renderer
_renderEngine2D.Initialize(camera2DComponent, _renderEngine.GetWindowPointer(), &_graphicsDevice);
LoadDebugComponents();
}
示例9: PostLoad
void SpriteAnimationTest::PostLoad()
{
App::PostLoad();
GameObject* playerGameObject = scene->AddGameObject(new GameObject("player"));
AnimationController* animationController = new AnimationController();
animationController->dataTypes.emplace_back(new AInt(20));
//-----------------------------------------------------------------------------------------------------------------------------------
for (size_t i = 0; i < 8; i++)
walkingLeftKeyframes->emplace_back(KeyFrame(100 * (i + 1), BF::Math::Rectangle(32 * i, 0, 32, 48)));
for (size_t i = 0; i < 6; i++)
walkingRightKeyframes->emplace_back(KeyFrame(100 * (i + 1), BF::Math::Rectangle(32 * i, 48, 32, 48)));
sequence->emplace_back(walkingLeftKeyframes);
sequence->emplace_back(walkingRightKeyframes);
AnimationData data("../Sandbox/Assets/Textures/player.png", sequence);
data.filePath = "../Sandbox/Assets/Textures/player.png";
Texture2D* texture = new Texture2D();
texture->Create(ResourceManager::Load<TextureData>(data.textureName), Texture::Format::R8G8B8A8);
BF::Graphics::Animation::Animation* walkingLeftAnimation = new BF::Graphics::Animation::Animation(texture, &(*data.sequences)[0], true);
BF::Graphics::Animation::Animation* walkingRightAnimation = new BF::Graphics::Animation::Animation(texture, &(*data.sequences)[1], true);
//-----------------------------------------------------------------------------------------------------------------------------------
AnimationNode* walkingLeftAnimationNode = new AnimationNode();
walkingLeftAnimationNode->animation = walkingLeftAnimation;
AnimationNode* walkingRightAnimationNode = new AnimationNode();
walkingRightAnimationNode->animation = walkingRightAnimation;
//-----------------------------------------------------------------------------------------------------------------------------------
Transition* startingNodeTransition = new Transition(walkingLeftAnimationNode, true);
Condition* startingCondition = new Condition(animationController->dataTypes[0], Condition::EvaluationOperator::BiggerThan, new AInt(10));
startingNodeTransition->conditions.emplace_back(startingCondition);
animationController->startingAnimationNode->transition = startingNodeTransition;
//-----------------------------------------------------------------------------------------------------------------------------------
Transition* walkingLeftTransition = new Transition(walkingRightAnimationNode, true);
Condition* walkingLeftCondition = new Condition(animationController->dataTypes[0], Condition::EvaluationOperator::BiggerThan, new AInt(10));
walkingLeftTransition->conditions.emplace_back(walkingLeftCondition);
walkingLeftAnimationNode->transitions.emplace_back(walkingLeftTransition);
//-----------------------------------------------------------------------------------------------------------------------------------
Animator* animator = (Animator*)playerGameObject->AddComponent(new Animator(animationController));
//animator->gameObject->GetTransform()->SetScale(Vector3f(3, 3, 3));
App::RunScene(*scene);
}
示例10: Initialize
void SpriteAnimationTest::Initialize()
{
scene = new Scene(*this);
BF::Input::Mouse::ShowMouseCursor(true);
BF::Engine::GetContext().EnableVsync(false);
BF::Engine::GetContext().SetWindingOrder(WindingOrder::Clockwise);
BF::Engine::GetContext().CullFace(CullingType::Back);
//BF::Engine::LimitFrameRate(60.0f);
defaultRenderLayer = renderPipeline.spriteRenderer->renderLayerManager.GetDefaultRenderLayer();
spriteRenderLayer = renderPipeline.spriteRenderer->renderLayerManager.AddRenderLayer(new RenderLayer("Sprites", RenderLayer::SortingOrder::BackToFrontRightToLeft));
GameObject* CameraGameObject = scene->AddGameObject(new GameObject("Camera"));
orthographicRectangle = BF::Math::Rectangle(0, 0, Engine::GetWindow().GetClientSize().x, Engine::GetWindow().GetClientSize().y, Vector2f(0.5, 0.5f));
BF::Math::Rectangle rect = orthographicRectangle.GetEdgeOffsetByPivot();
camera = (Camera*)CameraGameObject->AddComponent(new Camera(Matrix4::Orthographic(rect.x, rect.width, rect.y, rect.height, -1.0f, 1.0f)));
camera->SetClearType(BufferClearType::ColorAndDepth);
camera->SetClearColor(Color(0.0, 0.0f, 0.0f, 1.0f));
App::Initialize();
}
示例11: CreatePinkBubble
GameObject* GameObjectManager::CreatePinkBubble(const Ogre::Vector3& position, void* data){
GameObject* go = new GameObject(GAME_OBJECT_BLUE_BUBBLE);
MeshRenderComponent* mrc = new MeshRenderComponent;
go->AddComponent(mrc);
RigidbodyComponent* rc = new RigidbodyComponent;
go->AddComponent(rc);
mrc->Init("sphere.mesh", m_scene_manager);
Ogre::Vector3 scale(0.002,0.002,0.002);
mrc->GetSceneNode()->setScale(scale);
//mrc->GetEntity()->setMaterialName();
rc->Init(position, mrc->GetEntity(), m_physics_engine, 1.0f, COLLIDER_SPHERE, DYNAMIC_BODY);
rc->GetRigidbody()->setGravity(btVector3(0.0f, 0.0f, 0.0f));
rc->GetRigidbody()->setLinearFactor(btVector3(1,0,1));
return go;
}
示例12: CloneInto
void GameObject::CloneInto(ICloneable *clone) const
{
GameObject *go = static_cast<GameObject*>(clone);
go->SetName(m_name);
go->SetParent(nullptr);
for (GameObject *child : m_children)
{
if (child->IsEditorGameObject()) continue;
GameObject *childClone = static_cast<GameObject*>(child->Clone());
childClone->SetParent(go);
}
for (Component *comp : m_components)
{
Transform* t = dynamic_cast<Transform*>(comp);
if (!t)
{
go->AddComponent( static_cast<Component*>(comp->Clone()) );
}
else
{
m_transform->CloneInto(go->transform);
}
}
}
示例13: GetJsonRoot
GameObject * Factory::BuildJsonComposition(const char *file)
{
// Open the Json file and read in the components:
Json::Value components = GetJsonRoot(file)["Components"];
ErrorIf(!components, "Failed to open file %s.", file);
std::vector<std::string> componentList = components.getMemberNames();
GameObject *gameObject = new GameObject();
// Add each of the components to the new object:
for (unsigned i = 0; i < components.size(); ++i)
{
// 1. Check if the component is registered and has a creator
// in the component map:
ComponentCreatorMap::iterator it =
componentCreatorMap_.find(componentList.at(i));
ErrorIf(it == componentCreatorMap_.end(), "Failed to create unregistered component %s", componentList.at(i));
// 2. Create a new component once the creator is found in the
// map:
ComponentCreator *creator = it->second;
Component *component = creator->Create();
// 3. Serialize the component using the Json value in the file:
component->Deserialize(components[componentList.at(i)]);
// 4. Add the component to the composition:
gameObject->AddComponent(creator->TypeId, component);
}
IdGameObject(gameObject);
return gameObject;
}
示例14: dragEnterEvent
void OgreWidget::dragEnterEvent(QDragEnterEvent *event)
{
counter++;
QString str = event->mimeData()->text();
GameObject *go = new GameObject("object" + QString::number(counter).toStdString());
go->AddComponent(new MeshRenderer(go->name, str.toStdString(), "Robot"));
}
示例15: CreateTott
GameObject* GameObjectManager::CreateTott(const Ogre::Vector3& position, void* data){
CharControllerDef& def = *static_cast<CharControllerDef*>(data);
GameObject* go = new GameObject(GAME_OBJECT_TOTT);
AnimationComponent* acomp = new AnimationComponent;
acomp->AddAnimationStates(1);
go->AddComponent(acomp);
go->AddUpdateable(acomp);
CharacterController* contr = new CharacterController;
go->AddComponent(contr);
go->AddUpdateable(contr);
go->AddLateUpdate(contr);
acomp->Init("Yomi_2Yomi.mesh", m_scene_manager);
contr->Init(position, acomp->GetEntity(), def.step_height, def.collider_type, m_physics_engine);
contr->SetTurnSpeed(def.turn_speed);
contr->SetVelocity(def.velocity);
return go;
}