Esempio n. 1
0
bool EC_Mesh::AttachMeshToBone(QObject* targetMesh, const QString& boneName)
{
    if (!entity_)
        return false;
    
    // First make sure that the target mesh is valid, and the bone can be found
    EC_Mesh* targetMeshPtr = dynamic_cast<EC_Mesh*>(targetMesh);
    if (!targetMeshPtr)
        return false;
    Ogre::Entity* targetEntity = targetMeshPtr->GetEntity();
    if (!targetEntity)
        return false;
    std::string boneNameStd = boneName.toStdString();
    Ogre::SkeletonInstance* skeleton = targetEntity->getSkeleton();
    if (!skeleton)
        return false;
    if (!skeleton->hasBone(boneNameStd))
        return false;
    
    // We are ready to go. Detach the entity from its normal scene node first
    DetachMeshFromBone();
    DetachEntity();
    
    bone_tagpoint_ = targetEntity->attachObjectToBone(boneNameStd, entity_);
    bone_parent_mesh_ = targetMeshPtr;
    bone_parent_mesh_->bone_attached_mesh_ = this;
    attached_to_bone_ = true;
    
    // Force the adjustment for the tagpoint now
    OnAttributeUpdated(&nodeTransformation);
    
    return true;
}
Esempio n. 2
0
void OgreAppLogic::createScene(void)
{
	// setup some basic lighting for our scene
	mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
	// make a cube to bounce around
	Entity *ent1;
	SceneNode *boxNode;
	
	ManualObject *cmo = createCubeMesh("manual", "");
	cmo->convertToMesh("cube");
	ent1 = mSceneMgr->createEntity("Cube", "cube.mesh");
	ent1->setCastShadows(true);
	boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	boxNode->attachObject(ent1);
	boxNode->setScale(Vector3(0.1,0.1,0.1)); // for some reason converttomesh multiplied dimensions by 10
	
    mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
    mSceneMgr->createLight()->setPosition(20, 80, 50);
	// create a floor mesh resource
	MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
	Plane(Vector3::UNIT_Y, -30), 1000, 1000, 10, 10, true, 1, 8, 8, Vector3::UNIT_Z);

	// create a floor entity, give it a material, and place it at the origin
    Entity* floor = mSceneMgr->createEntity("Floor", "floor");
    floor->setMaterialName("Examples/BumpyMetal");
    mSceneMgr->getRootSceneNode()->attachObject(floor);
	
	mSceneMgr->getRootSceneNode()->attachObject(mSceneMgr->createEntity("Head", "ogrehead.mesh"));
	mSceneMgr->setSkyBox(true, "Examples/GridSkyBox");
	
	Ogre::Entity* ent = mSceneMgr->createEntity("Sinbad.mesh");	//1x1_cube.mesh //Sinbad.mesh //axes.mesh

	mObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("cube");	
	mObjectNode->setOrientation(Quaternion(Degree(90.f), Vector3::UNIT_X));
	Ogre::Real scale = 22;
	mObjectNode->setPosition(10, 10, 10*scale);
	mObjectNode->setScale(Ogre::Vector3::UNIT_SCALE*scale);
	mObjectNode->attachObject(ent);
	mObjectNode->setVisible(true);

	// create swords and attach them to sinbad
	Ogre::Entity* sword1 = mSceneMgr->createEntity("SinbadSword1", "Sword.mesh");
	Ogre::Entity* sword2 = mSceneMgr->createEntity("SinbadSword2", "Sword.mesh");
	ent->attachObjectToBone("Sheath.L", sword1);
	ent->attachObjectToBone("Sheath.R", sword2);
	mAnimState = ent->getAnimationState("Dance");
	mAnimState->setLoop(true);
	mAnimState->setEnabled(true);

}
OgreCharacterController::OgreCharacterController(Ogre::Camera * Camera, const Ogre::String& name, const Ogre::Vector3& position)
  : CharacterController(Camera, position, name, "Sinbad.mesh", Ogre::Vector3(3, 3, 3)), lastTop(0), lastBase(0), 
  mSword1(0), mSword2(0), swordsOut(false), sliceDir(false), animTimer(0)
{
  Ogre::SceneManager * smgr = Camera->getSceneManager();
  Ogre::Entity * ent = getEntity();

  ent->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);

  mSword1 = smgr->createEntity("Sword1", "Sword.mesh");
  mSword2 = smgr->createEntity("Sword2", "Sword.mesh");
  ent->attachObjectToBone("Sheath.L", mSword1);
  ent->attachObjectToBone("Sheath.R", mSword2);

  getTargetNode()->setFixedYawAxis(true);
}
Esempio n. 4
0
void MenuState::Enter(){
	m_scene_manager = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "MenuStateSceneManager");
	m_sound_manager = new SoundManager;
	m_sound_manager->Init(m_scene_manager);
	m_sound_manager->LoadAudio();
	m_fade->SetFadeInCallBack(NULL);
	m_fade->FadeIn(VariableManager::GetSingletonPtr()->GetAsFloat("Fade_in_timer"));
	std::function<void()> func = [this] { ChangeStateToPlayState(); };
	m_fade->SetFadeOutCallBack(func);
	
	m_scene_manager->setSkyBox(true, "_MySky", 2300.0f);

	m_camera = m_scene_manager->createCamera("MenuCamera");
	m_camera->setNearClipDistance(1.0f);
	m_viewport = m_render_window->addViewport(m_camera);
	m_camera->setAspectRatio(Ogre::Real(m_viewport->getActualWidth()) / Ogre::Real(m_viewport->getActualHeight()));
	

	m_physics_engine = new PhysicsEngine;
	m_physics_engine->Init();
	m_game_object_manager = new GameObjectManager;
	m_game_object_manager->Init(m_physics_engine, m_scene_manager, m_input_manager, m_viewport, m_sound_manager, m_message_system, NULL);
	
	Ogre::Plane plane(Vector3::UNIT_Y, -0.9f);
	Ogre::MeshManager::getSingleton().createPlane("plane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 20, 20, 5, 5, true, 1, 5, 5, Vector3::UNIT_Z);

	Ogre::Entity* yomi_house = m_scene_manager->createEntity("YomiHouse.mesh");
	Ogre::Entity* yomi = m_scene_manager->createEntity("Yomi.mesh");
	Ogre::Entity* yomi_staff = m_scene_manager->createEntity("Staff.mesh");
	yomi->attachObjectToBone("CATRigLArmDigit21", yomi_staff);
	Ogre::Entity* tree = m_scene_manager->createEntity("JumpLeafTree_1.mesh");
	m_house_node = m_scene_manager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(4.0f,2.0f,-24.0f));
	m_house_node->yaw(Ogre::Radian(1.4f));
	m_house_node->attachObject(yomi_house);
	m_yomi_node = m_scene_manager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(1.0f, -0.8f, -3.0f));
	m_yomi_node->attachObject(yomi);
	m_tree_node = m_scene_manager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-2.0f, 1.5f, -20.0f));
	m_tree_node->attachObject(tree);

	PlaneDef plane_def;
	plane_def.material_name = "Examples/BeachStones";
	plane_def.plane_name = "plane";
	plane_def.friction = 1.0f;
	plane_def.restitution = 0.8f;
	plane_def.collision_filter.filter = COL_WORLD_STATIC;
	plane_def.collision_filter.mask = COL_BUBBLE | COL_PLAYER | COL_TOTT;
	m_game_object_manager->CreateGameObject(GAME_OBJECT_PLANE, Ogre::Vector3(0,0,0), &plane_def);

	OverlayDef menuBackground;
	menuBackground.overlay_name = "Menu";
	menuBackground.cont_name = "Menu/Background";
	m_game_object_manager->CreateGameObject(GAME_OBJECT_OVERLAY, Ogre::Vector3(0,0,0), &menuBackground);

	menuBackground.overlay_name = "Menu";
	menuBackground.cont_name = "Menu/BackgroundBubbles";
	m_game_object_manager->CreateGameObject(GAME_OBJECT_OVERLAY, Ogre::Vector3(0,0,0), &menuBackground);

	ButtonDef buttonDef;
	buttonDef.overlay_name = "Menu";
	buttonDef.cont_name = "Menu/Start";
	buttonDef.mat_start_hover = "Menu/StartHover";
	buttonDef.mat_start = "Menu/Start";
	buttonDef.func = [this] { m_fade->FadeOut(VariableManager::GetSingletonPtr()->GetAsFloat("Fade_out_timer"));};
	
	m_buttons[0] = m_game_object_manager->CreateGameObject(GAME_OBJECT_BUTTON, Ogre::Vector3(0,0,0), &buttonDef);

	buttonDef.overlay_name = "Menu";
	buttonDef.cont_name = "Menu/Options";
	buttonDef.mat_start_hover = "Menu/OptionsHover";
	buttonDef.mat_start = "Menu/Options";
	buttonDef.func = [this] {  };
	m_buttons[1] = m_game_object_manager->CreateGameObject(GAME_OBJECT_BUTTON, Ogre::Vector3(0,0,0), &buttonDef);

	buttonDef.overlay_name = "Menu";
	buttonDef.cont_name = "Menu/Credits";
	buttonDef.mat_start_hover = "Menu/CreditsHover";
	buttonDef.mat_start = "Menu/Credits";
	buttonDef.func = [this] {  };
	m_buttons[2] = m_game_object_manager->CreateGameObject(GAME_OBJECT_BUTTON, Ogre::Vector3(0,0,0), &buttonDef);

	buttonDef.overlay_name = "Menu";
	buttonDef.cont_name = "Menu/Quit";
	buttonDef.mat_start_hover = "Menu/QuitHover";
	buttonDef.mat_start = "Menu/Quit";
	buttonDef.func = [this] { ChangeStateToExit(); };
	m_buttons[3] = m_game_object_manager->CreateGameObject(GAME_OBJECT_BUTTON, Ogre::Vector3(0,0,0), &buttonDef);
}