Exemple #1
0
GameObject* GameObjectManager::CreateQuestItem(const Ogre::Vector3& position, void* data, const Ogre::String& id){
	
	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;
	QuestItemDef& quest_item_def = *static_cast<QuestItemDef*>(data);
	GameObject* go = new GameObject(GAME_OBJECT_QUEST_ITEM);
	DestroyCallbackComponent* dcc = new DestroyCallbackComponent;
	go->AddComponent(dcc);
	NodeComponent* node_comp = new NodeComponent;
	go->AddComponent(node_comp);
	MeshRenderComponent* mrc = new MeshRenderComponent;
	go->AddComponent(mrc);
	RigidbodyComponent* rc = new RigidbodyComponent;
	go->AddComponent(rc);
	RotationComponent* rot_comp = new RotationComponent;
	go->AddComponent(rot_comp);
	go->AddUpdateable(rot_comp);
	StringComponent* string_comp = new StringComponent;
	go->AddComponent(string_comp);


	string_comp->Init(quest_item_def.id);
	std::function<void()> func = [&] { IEvent evt; evt.m_type = EVT_QUEST_ITEM_REMOVE; m_message_system->Notify(&evt); };
	dcc->Init(func);

	std::ostringstream stream;
	stream << "Quest_Item_" << m_quest_item_iterations;
	m_quest_item_iterations++;
	Ogre::String quest_item_id = stream.str();

	node_comp->Init(position, m_scene_manager);
	node_comp->SetId(quest_item_id);
	mrc->Init(quest_item_def.mesh_name, m_scene_manager);
	
	RigidBodyDef body_def;
	body_def.body_type = DYNAMIC_BODY;
	body_def.collider_type = COLLIDER_SPHERE;
	body_def.friction = 1.0;
	body_def.mass = 1.0f;
	body_def.collision_filter.filter = COL_QUESTITEM;
	body_def.collision_filter.mask = COL_PLAYER | COL_TOTT | COL_WORLD_STATIC | COL_BUBBLE;
	body_def.sync_orientation = false;
	rc->Init(position,  mrc->GetEntity(), m_physics_engine, body_def);
	rc->GetRigidbody()->setGravity(btVector3(0.0f, -0.3f, 0.0f));
	rc->GetRigidbody()->setContactProcessingThreshold(btScalar(0));
	rc->GetRigidbody()->setActivationState(DISABLE_DEACTIVATION);
	rc->GetRigidbody()->setDamping(0.5, 0.5);
	rc->SetId(quest_item_id);
	rot_comp->Init(node_comp->GetSceneNode(), VariableManager::GetSingletonPtr()->GetAsFloat("QuestItemRotationSpeed"));

	return go;
};
Exemple #2
0
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;
}