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(); } }
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); }
GameObject* GameObjectManager::CreatePlane(const Ogre::Vector3& position, void* data, const Ogre::String& id){ GameObject* go = new GameObject(GAME_OBJECT_PLANE); NodeComponent* node_comp = new NodeComponent; go->AddComponent(node_comp); MeshRenderComponent* mrc = new MeshRenderComponent; go->AddComponent(mrc); RigidbodyComponent* rc = new RigidbodyComponent; go->AddComponent(rc); node_comp->Init(position, m_scene_manager); PlaneDef& plane_def = *static_cast<PlaneDef*>(data); mrc->Init(plane_def.plane_name, m_scene_manager); mrc->GetEntity()->setMaterialName(plane_def.material_name); mrc->GetEntity()->setCastShadows(false); RigidBodyDef def; def.body_type = STATIC_BODY; def.collider_type = COLLIDER_TRIANGLE_MESH_SHAPE; def.friction = plane_def.friction; def.restitution = plane_def.restitution; def.mass = 0.0f; def.collision_filter.filter = COL_WORLD_STATIC; def.collision_filter.mask = COL_PLAYER | COL_BUBBLE | COL_TOTT; rc->Init(position, mrc->GetEntity(), m_physics_engine, def); rc->GetCollisionDef().flag = COLLISION_FLAG_STATIC; return go; }
GameObject* GameObjectManager::CreateCompanion(const Ogre::Vector3& position, void* data, const Ogre::String& id){ ButtonDef& buttonDef = *static_cast<ButtonDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_COMPANION); TimerComponent* timer = new TimerComponent; go->AddComponent(timer); go->AddUpdateable(timer); TriggerComponent* tc = new TriggerComponent; go->AddComponent(tc); return go; }
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))); }
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; }
GameObject* GameObjectManager::CreateSpeechBubble(const Ogre::Vector3& position, void* data, const Ogre::String& id){ //Ogre::SceneNode* node = *static_cast<Ogre::SceneNode**>(data); std::ostringstream stream; stream << "Speech_Bubble_" << m_speech_bubble_iterations; m_speech_bubble_iterations++; Ogre::String spbubble_id = stream.str(); GameObject* tott = *static_cast<GameObject**>(data); Ogre::SceneNode* node = static_cast<NodeComponent*>(tott->GetComponent(COMPONENT_NODE))->GetSceneNode(); TottDef tott_def = static_cast<TottController*>(tott->GetComponent(COMPONENT_CHARACTER_CONTROLLER))->m_def; static_cast<TottController*>(tott->GetComponent(COMPONENT_CHARACTER_CONTROLLER))->SetSpeechBubble(spbubble_id); GameObject* go = new GameObject(GAME_OBJECT_SPEECH_BUBBLE, spbubble_id); NodeComponent* node_comp = new NodeComponent; go->AddComponent(node_comp); MeshRenderComponent* mrc = new MeshRenderComponent; go->AddComponent(mrc); SyncedTriggerComponent* trc = new SyncedTriggerComponent; go->AddComponent(trc); go->AddUpdateable(trc); SpeechBubbleComponent* sbcomp = new SpeechBubbleComponent; go->AddComponent(sbcomp); go->AddUpdateable(sbcomp); node_comp->Init(node, m_scene_manager); node_comp->SetId(spbubble_id); mrc->Init("PratBubblaCherry.mesh", m_scene_manager, node_comp->GetSceneNode()->getName());//, node->getName()); sbcomp->Init(node, m_scene_manager, tott); /* node_comp->Init(position, m_scene_manager); mrc->Init("PratBubbla.mesh", m_scene_manager);//, m_temp_node->getName());//, node->getName()); sbcomp->Init(m_temp_node, m_scene_manager); */ TriggerDef trdef; trdef.body_type = DYNAMIC_BODY; trdef.collider_type = COLLIDER_SPHERE; trdef.mass = 0.0f; trdef.radius = 2.5f; trdef.collision_filter.filter = COL_WORLD_TRIGGER; trdef.collision_filter.mask = COL_PLAYER; trc->Init(position, m_physics_engine, &trdef); return go; };
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; }
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; }
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; }
GameObject* GameObjectManager::CreateTott(const Ogre::Vector3& position, void* data, const Ogre::String& id){ static int tott_counter = 0; Ogre::String tott_id = "Tott" + NumberToString(tott_counter); TottDef& def = *static_cast<TottDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_TOTT, tott_id); NodeComponent* node_comp = new NodeComponent; go->AddComponent(node_comp); TottAIComponent* ai_comp = new TottAIComponent; go->AddComponent(ai_comp); go->AddUpdateable(ai_comp); AnimationComponent* acomp = new AnimationComponent; go->AddComponent(acomp); go->AddUpdateable(acomp); CharacterController* contr = new CharacterController; go->AddComponent(contr); go->AddUpdateable(contr); node_comp->Init(position, m_scene_manager); node_comp->SetId(tott_id); def.node_name = node_comp->GetSceneNode()->getName(); acomp->Init(def.mesh_name, m_scene_manager); if (def.type_name == "Hidehog"){ acomp->AddAnimationState("Run", true); } else if (def.type_name == "Kittyshroom"){ acomp->AddAnimationState("walk", true); } else if (def.type_name == "Nightcap"){ acomp->AddAnimationState("walk", true); } else if (def.type_name == "Shroomfox"){ acomp->AddAnimationState("idle", true); } else{ acomp->AddAnimationState("Run", true); } ai_comp->Init(def.ai_states); m_sound_manager->GetTottNode(node_comp->GetSceneNode()->getName()); contr->Init(position, m_physics_engine, def.character_controller); contr->GetRigidbody()->setContactProcessingThreshold(btScalar(0)); contr->GetRigidbody()->setActivationState(DISABLE_DEACTIVATION); acomp->GetEntity()->setRenderingDistance(100.0f); tott_counter++; return go; }
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(); }
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); }
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(); }
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; }
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); } } }
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; }
GameObject* GameObjectManager::Create2DOverlay(const Ogre::Vector3& position, void* data, const Ogre::String& id) { OverlayDef& overlayDef = *static_cast<OverlayDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_OVERLAY); Overlay2DComponent* overlayComp = new Overlay2DComponent; go->AddComponent(overlayComp); OverlayCollisionCallbackComponent* coll_comp = new OverlayCollisionCallbackComponent; go->AddComponent(coll_comp); go->AddUpdateable(coll_comp); coll_comp->Init(m_input_manager, m_viewport); overlayComp->Init(overlayDef.overlay_name, overlayDef.cont_name); go->SetGameObjectManager(this); return go; }
GameObject* GameObjectManager::CreateButton(const Ogre::Vector3& position, void* data, const Ogre::String& id) { ButtonDef& buttonDef = *static_cast<ButtonDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_BUTTON); OverlayCollisionCallbackComponent* collisionCallBack = new OverlayCollisionCallbackComponent; go->AddComponent(collisionCallBack); go->AddUpdateable(collisionCallBack); Overlay2DAnimatedComponent* overlay2DAnim = new Overlay2DAnimatedComponent; go->AddComponent(overlay2DAnim); OverlayCallbackComponent* overlaycallback = new OverlayCallbackComponent; go->AddComponent(overlaycallback); overlaycallback->Init(buttonDef.func); collisionCallBack->Init(m_input_manager, m_viewport); overlay2DAnim->Init(buttonDef.overlay_name, buttonDef.mat_start_hover, buttonDef.mat_start, buttonDef.cont_name); return go; }
GameObject* GameObjectManager::CreateNextLevelTrigger(const Ogre::Vector3& position, void* data, const Ogre::String& id){ TriggerDef& def = *static_cast<TriggerDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_NEXT_LEVEL); TriggerComponent* tc = new TriggerComponent; go->AddComponent(tc); tc->Init(position, m_physics_engine, def); return go; }
GameObject* GameObjectManager::CreateTerrain(const Ogre::Vector3& position, void* data, const Ogre::String& id){ GameObject* go = new GameObject(GAME_OBJECT_TERRAIN, "Terrain"); TerrainComponent* tc = new TerrainComponent; go->AddComponent(tc); go->AddUpdateable(tc); tc->Init(m_scene_manager, m_physics_engine, this, m_sound_manager, *static_cast<Ogre::String*>(data)); return go; }
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")); }
GameObject* GameObjectManager::CreatePinkBubble(const Ogre::Vector3& position, void* data, const Ogre::String& id){ BubbleDef& def = *static_cast<BubbleDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_PINK_BUBBLE); BubbleController* bc = new BubbleController; go->AddComponent(bc); go->AddUpdateable(bc); NodeComponent* node_comp = new NodeComponent; go->AddComponent(node_comp); MeshRenderComponent* mrc = new MeshRenderComponent; go->AddComponent(mrc); Point2PointConstraintComponent* cons = new Point2PointConstraintComponent; go->AddComponent(cons); RigidbodyComponent* rc = new RigidbodyComponent; go->AddComponent(rc); node_comp->Init(position, m_scene_manager); mrc->Init("PinkBubble.mesh", m_scene_manager); mrc->GetEntity()->setRenderQueueGroup(60); Ogre::Vector3 scale(def.start_scale); node_comp->GetSceneNode()->setScale(scale); //bc->SetCustomVariables(VariableManager::GetSingletonPtr()->GetAsFloat("Pink_Bubble_Life_Time")); //mrc->GetEntity()->setMaterialName("PinkBubble"); RigidBodyDef body_def; body_def.body_type = DYNAMIC_BODY; body_def.collider_type = COLLIDER_SPHERE; body_def.friction = def.friction; body_def.mass = 1.0f; body_def.collision_filter.filter = COL_BUBBLE; body_def.collision_filter.mask = COL_PLAYER | COL_TOTT | COL_BUBBLE | COL_WORLD_STATIC | COL_QUESTITEM; rc->Init(position, mrc->GetEntity(), m_physics_engine, body_def); rc->GetRigidbody()->setGravity(btVector3(0.0f, 0.0f, 0.0f)); //rc->GetRigidbody()->setLinearFactor(btVector3(1,0,1)); rc->GetRigidbody()->setContactProcessingThreshold(btScalar(0)); rc->GetRigidbody()->setActivationState(DISABLE_DEACTIVATION); //rc->GetRigidbody()->setDamping(0.5, 0.5); rc->SetId("body"); cons->Init(m_physics_engine,rc->GetRigidbody(), def.connection_body, btVector3(0,0,0), btVector3(0,0,0)); bc->Init(m_physics_engine, m_message_system, VariableManager::GetSingletonPtr()->GetAsFloat("OnBubbleImpulse"), VariableManager::GetSingletonPtr()->GetAsFloat("OnBubbleMaxVelocity"), def.start_scale); this->CheckBubbleSize(); m_bubbles.push_back(go); return go; }
GameObject* GameObjectManager::CreateLevelChange(const Ogre::Vector3& position, void* data, const Ogre::String& id){ TriggerDef& def = *static_cast<TriggerDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_LEVEL_CHANGE, id); TriggerComponent* trigger_comp = new TriggerComponent; go->AddComponent(trigger_comp); trigger_comp->Init(position, m_physics_engine, def); return go; }
GameObject* GameObjectManager::CreateRockSlide(const Ogre::Vector3& position, void* data, const Ogre::String& id){ GameObject* go = new GameObject(GAME_OBJECT_ROCK_SLIDE, id); NodeComponent* node_component = new NodeComponent; go->AddComponent(node_component); MeshRenderComponent* mesh = new MeshRenderComponent; go->AddComponent(mesh); RigidbodyComponent* body = new RigidbodyComponent; go->AddComponent(body); TriggerComponent* trigger = new TriggerComponent; go->AddComponent(trigger); RigidBodyDef body_def; body_def.body_type = COLLIDER_TRIANGLE_MESH_SHAPE; body_def.collision_filter.filter = COL_WORLD_STATIC; body_def.collision_filter.mask = COL_BUBBLE | COL_PLAYER | COL_QUESTITEM | COL_TOTT; return go; }
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; }
GameObject* GameObjectFactory::CreatePlanet(Game* pGame) { GameObject* pObject = new GameObject(k_planetID, pGame); //Add Transform Component TransformComponent* pTransform = m_pComponentFactory->CreateTransformComponent(pObject); pObject->AddComponent(k_transformComponentID, pTransform); //Add Render Component RenderComponent* pRenderComponent = m_pComponentFactory->CreateRenderComponent(pObject, pTransform); pObject->AddComponent(k_renderComponentID, pRenderComponent); //Add Planet Controller PlanetController* pPlanetController = m_pComponentFactory->CreatePlanetController(pObject, pTransform); pObject->AddComponent(k_planetComponentID, pPlanetController); return pObject; }
void CreateRandomBarrel(Game *pGame) { Vector3 pos = pGame->getRandomVector(4000.0f); GameObject *pHouse = pGame->CreateObject(pos,Quaternion(pos.x,0,0,0),"testent",eStaticMeshObject,false); OgreRenderInstanceComponent *pORC = dynamic_cast<OgreRenderInstanceComponent *>(pGame->CreateComponent(GameComponent::eCom_Render3D)); if (pORC) pORC->Create("Barrel.mesh",pHouse); pHouse->AddComponent(pORC); pGame->AddGob(pHouse); }
GameObject* GameObjectManager::CreateParticleEffect(const Ogre::Vector3& position, void* data, const Ogre::String& id){ ParticleDef& particleDef = *static_cast<ParticleDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_PARTICLE, id); ParticleComponent* particle = new ParticleComponent; go->AddComponent(particle); NodeComponent* node_comp = new NodeComponent; go->AddComponent(node_comp); node_comp->Init(position, m_scene_manager); node_comp->GetSceneNode()->setPosition(Ogre::Vector3(position)); std::ostringstream stream; stream << "Particle_" << m_particle_iterations; m_particle_iterations++; Ogre::String particle_id = stream.str(); particle->Init(m_scene_manager, particle_id, particleDef.particle_name, Ogre::Vector3(0,0,0), node_comp->GetSceneNode()); return go; };
GameObject* GameObjectManager::CreateLeaf(const Ogre::Vector3& position, void* data, const Ogre::String& id){ ParticleDef& particleDef = *static_cast<ParticleDef*>(data); GameObject* go = new GameObject(GAME_OBJECT_LEAF); ParticleComponent* particle = new ParticleComponent; go->AddComponent(particle); NodeComponent* node_comp = new NodeComponent; go->AddComponent(node_comp); MeshRenderComponent* mrc = new MeshRenderComponent; go->AddComponent(mrc); BobbingComponent* bc = new BobbingComponent; go->AddComponent(bc); go->AddUpdateable(bc); TriggerComponent* stc = new TriggerComponent; go->AddComponent(stc); Ogre::Vector3 scale = Ogre::Vector3(0.6f); node_comp->Init(position, m_scene_manager); node_comp->GetSceneNode()->setPosition(Ogre::Vector3(position)); node_comp->GetSceneNode()->setScale(scale); mrc->Init("Collectable_Leaf.mesh", m_scene_manager); mrc->GetEntity()->setMaterialName("CollectibleLeaf"); bc->Init(node_comp->GetSceneNode()); std::ostringstream stream; stream << "Leaf_" << m_leaf_iterations; m_leaf_iterations++; Ogre::String leaf_id = stream.str(); particle->Init(m_scene_manager, leaf_id, particleDef.particle_name, node_comp->GetSceneNode()->getPosition(), node_comp->GetSceneNode()); //particle->CreateParticle(node_comp->GetSceneNode(), node_comp->GetSceneNode()->getPosition(), Ogre::Vector3(0,-1.8f,0)); TriggerDef trdef; trdef.body_type = STATIC_BODY; trdef.collider_type = COLLIDER_SPHERE; trdef.mass = 0.0f; trdef.radius = 0.4f; trdef.collision_filter.filter = COL_WORLD_TRIGGER; trdef.collision_filter.mask = COL_PLAYER; stc->Init(position, m_physics_engine, trdef); return go; }