ISceneManager* setupScene(IDevice* device) { // create scene manager ISceneManager* smgr = device->createSceneManager(); // get mesh manager IMeshManager* meshManager = IMeshManager::getInstance(); // set up ground. ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", 100.0f, 100.0f, 10, 10, 50, 50); IMeshNode* groundNode = smgr->addMeshNode(groundMesh, "ground_material", nullptr, true); // create a sphere ISimpleMesh* sphereMesh = meshManager->createSphereMesh("sphere", 1.0f, 100, 100); IMeshNode* sphereNode = smgr->addMeshNode(sphereMesh, "sphere_material", nullptr, true, XMFLOAT3(-1.2f, 1.0f, 0)); // create a box ISimpleMesh* boxMesh = meshManager->createCubeMesh("box", 1.2f, 3.0f, 1.2f); IMeshNode* boxNode = smgr->addMeshNode(boxMesh, "box_material", nullptr, true, XMFLOAT3(1.0f, 1.5f, 1.0f)); // create a teapot IModelMesh* teapotMesh = meshManager->getModelMesh("teapot.mesh"); IMeshNode* teapot = smgr->addModelMeshNode(teapotMesh, nullptr, true, XMFLOAT3(1.2f, 0, -1.0f)); teapot->setMaterialName("teapot_material"); // add 100 point light for (u32 i = 0; i < 100; i++) { XMFLOAT3 pos(math::RandomFloat(-20.0, 20.0f), math::RandomFloat(3.0, 10.0f), math::RandomFloat(-20.0, 20.0f)); XMFLOAT4 diffuse(math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), 1.0f); XMFLOAT4 specular(math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), math::RandomFloat(0, 0.3f), 32.0f); ILightNode* light = smgr->addPointLight(i, nullptr, false, pos, 20.0f); light->setSpecular(specular); light->setDiffuse(diffuse); light->setAttenuation(1.0f, 0.05f, 0); } sphereNode->addShadow(1); boxNode->addShadow(1); teapot->addShadow(1); // create a fps camera node IFpsCameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -6.0f), XMFLOAT3(0, 1.0f, 0.0f), XMFLOAT3(0, 1.0f, 0)); camera->setNearZ(1.0f); camera->setFarZ(1000.0f); // set ambient in the environment. smgr->setAmbient(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f)); return smgr; }
void setupPhysics(ISceneManager* smgr) { IMeshManager* meshManager = IMeshManager::getInstance(); PhysicsEngine* engine = PhysicsEngine::getInstance(); hkpRigidBodyCinfo groundInfo; hkVector4 groundSize(groundSize * 0.5f, 0.5, groundSize * 0.5f); hkpBoxShape* groundShape = new hkpBoxShape(groundSize, 0); groundInfo.m_shape = groundShape; groundInfo.m_motionType = hkpMotion::MOTION_FIXED; groundInfo.m_position.set(0.0f, -0.5, 0.0f); groundInfo.m_restitution = 0.9f; groundInfo.m_friction = 0.5f; hkpRigidBody* floorRigidBody = new hkpRigidBody(groundInfo); groundShape->removeReference(); engine->addRigidBody(floorRigidBody); floorRigidBody->removeReference(); // create BOX f32 boxHalfSize = 2.0f; ISimpleMesh* boxMesh = meshManager->createCubeMesh("box", boxHalfSize*2.0f, boxHalfSize * 2.0f, boxHalfSize*2.0f); IMeshNode* boxNode = smgr->addMeshNode(boxMesh, nullptr, nullptr, false); boxNode->setMaterialName("box_material"); boxNode->addShadow(1); g_box = new PhysicsCube(boxNode, XMFLOAT3(boxHalfSize, boxHalfSize, boxHalfSize), XMFLOAT3(0, 40.0f, 0), false, 0.5f, 0.5f); }
bool EditorScene::PrepareAddingObject(const std::string& meshName) { IModelMesh* mesh = mMeshManager->getModelMesh(meshName, true); IMeshNode* node = mSceneManager->addModelMeshNode(mesh, nullptr, false); node->addShadow(1); node->setTag(MESH_NODE_TAG); mAddedNode = node; return true; }
void EditorScene::UpdateNodeInfo(SNodeInfo* info) { XMMATRIX S = XMMatrixScaling(info->Scaling.x, info->Scaling.y, info->Scaling.z); XMMATRIX R = XMMatrixRotationRollPitchYaw(info->Rotation.x, info->Rotation.y, info->Rotation.z); XMMATRIX T = XMMatrixTranslation(info->Position.x, info->Position.y, info->Position.z); XMMATRIX M = S * R * T; info->Node->setTransform(M); info->Node->update(); if (info->Node->getNodeType() & ESNT_MESH) { IMeshNode* meshNode = dynamic_cast<IMeshNode*>(info->Node); if (info->ShadowCasting) meshNode->addShadow(1); else meshNode->removeShadow(1); } updateSelectedNodeCube(); }