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); }
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 LoadingScene::setupScene() { math::SAxisAlignedBox aabb; aabb.Center = XMFLOAT3(0, 0.0f, 0); aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f); ISceneManager* smgr = mDevice->createSceneManager(aabb); mSceneManager = smgr; IMeshManager* meshManager = IMeshManager::getInstance(); ISimpleMesh* cubeMesh = meshManager->createCubeMesh("debug_loading", 3.0f, 3.0f, 3.0f); IMeshNode* meshNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, false); meshNode->setMaterialName("picking_cube_material"); ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 0.0f, -15.0f), XMFLOAT3(0, 0, 0.0f), XMFLOAT3(0, 1.0f, 0), true); mVideoDriver->setDeferredShading(false); ITextureManager* textureManager = ITextureManager::getInstance(); mLoadingImage = textureManager->get("loading_image.jpg"); }
int main() { //int avg = 2 * 90 + 3 * 88 + 4 * 87 + 3 * 84 + 4 * 92 + 2 * 93 + 2 * 83 + 2 * 80 + 2 * 95; //std::cout << "Avg : " << avg << std::endl; SDeviceContextSettings settings; settings.MultiSamplingCount = 4; settings.MultiSamplingQuality = 32; IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IMeshManager* meshManager = driver->getMeshManager(); IMaterialManager* materialManager = driver->getMaterialManager(); IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager(); resourceGroupManager->init("Resources.cfg"); resourceGroupManager->loadResourceGroup("General"); ISimpleMesh* cubeMesh = meshManager->createCubeMesh("cube1"); IMeshNode* cubeMeshNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, XMFLOAT3(0, 3.0f, 0)); cubeMeshNode->setMaterialName("test/material01"); //cubeMeshNode->remove(); ISimpleMesh* planeMesh = meshManager->createPlaneMesh("plane1", 10.0, 10.0f, 50, 50, 10.0f, 10.0f); IMeshNode* planeMeshNode = smgr->addMeshNode(planeMesh, nullptr); planeMeshNode->setMaterialName("test/ground_material"); IAnimatedMesh* animMesh = meshManager->getAnimatedMesh("lxq.mesh"); IAnimatedMeshNode* animNode = smgr->addAnimatedMeshNode(animMesh); animNode->scale(0.02f, 0.02f, 0.02f); IModelMesh* heroMesh = meshManager->getModelMesh("hero.mesh"); IMeshNode* heroNode = smgr->addModelMeshNode(heroMesh); heroNode->scale(0.01f, 0.01f, 0.01f); heroNode->translate(2.0f, 0.5f, 0); // create sampler state SSamplerDesc samplerDesc; samplerDesc.Filter = ESF_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = EAM_WRAP; samplerDesc.AddressV = EAM_WRAP; samplerDesc.AddressW = EAM_WRAP; ISampler* sampler = driver->getSamplerManager()->create(std::string("sampler1"), samplerDesc); IPipeline* pipeline = driver->getPipelineManager()->get("test/pipeline01"); //pipeline->setSampler(std::string("sampleType"), sampler); ILightNode* light = smgr->addLightNode(1); light->setType(ELT_POINT); light->setAmbient(XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f)); light->setPosition(2.0f, 5.0f, -3.0f); light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f)); light->setDiffuse(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f)); light->setAttenuation(1.0f, 0.0f, 0.0f); light->setRange(100.0f); materialManager->destroy(std::string("test/material02")); //ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f)); ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f)); f32 rotx = 0; f32 roty = 0; f32 rotz = 0; char caption[200]; //FILE* fp = fopen("log.txt", "w"); ITimer* timer = device->createTimer(); timer->reset(); while (device->run()) { const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f }; driver->beginScene(true, true, clearColor); float dt = timer->tick(); rotx += dt * 2.0f; roty += dt * 1.0f; rotz += dt * 0.5f; if (rotx > XM_2PI) rotx -= XM_2PI; if (roty > XM_2PI) roty -= XM_2PI; if (rotz > XM_2PI) rotz -= XM_2PI; XMMATRIX Mx = XMMatrixRotationX(rotx); XMMATRIX My = XMMatrixRotationY(roty); XMMATRIX Mz = XMMatrixRotationZ(rotz); XMMATRIX rotM = Mx * My * Mz; cubeMeshNode->setOrientation(rotM); // heroNode->yaw(dt); animNode->addTime(dt * 3000.0f); updateCamera(camera, dt); // std::cout << dt << std::endl; smgr->drawAll(); driver->endScene(); sprintf(caption, "FPS:%f", getFps(dt)); device->setWindowCaption(caption); } device->drop(); return 0; }