//-------------------------------------------------------------------------------------- // Sets the camera to view a particular group of objects //-------------------------------------------------------------------------------------- void SetViewForGroup( int group ) { assert( group < GROUP_COUNT ); g_Camera.Reset(); static const XMVECTORF32 s_Offset0 = { 0.f, 20.f, 20.f, 0.f }; static const XMVECTORF32 s_Offset = { 0.f, 20.f, -20.f, 0.f }; XMVECTOR vecEye = g_CameraOrigins[group] + ( ( group == 0 ) ? s_Offset0 : s_Offset ); g_Camera.SetViewParams( vecEye, g_CameraOrigins[group] ); XMFLOAT3 vecAt; XMStoreFloat3( &vecAt, g_CameraOrigins[group] ); g_Camera.SetModelCenter( vecAt ); }
//-------------------------------------------------------------------------------------- // Create TweakBar and add required buttons and variables //-------------------------------------------------------------------------------------- void InitTweakBar(ID3D11Device* pd3dDevice) { g_pTweakBar = TwNewBar("TweakBar"); TwDefine(" TweakBar color='0 128 128' alpha=128 "); #ifdef TEMPLATE_DEMO TwType TW_TYPE_TESTCASE = TwDefineEnumFromString("Test Scene", "BasicTest,Scene1,Scene2,Scene3"); #endif #ifdef RIGIDBODYCOLLISIONS TwEnumVal sceneIdentifiers[SceneManager::scenes_count] = { {0, SceneManager::scene_names[0]}, { 1, SceneManager::scene_names[1] }, { 2, SceneManager::scene_names[2] } }; TwType TW_TYPE_TESTCASE = TwDefineEnum("Demo Scene", sceneIdentifiers, SceneManager::scenes_count); #endif TwAddVarRW(g_pTweakBar, "Demo Scene", TW_TYPE_TESTCASE, &g_iTestCase, ""); // HINT: For buttons you can directly pass the callback function as a lambda expression. #if (defined RIGIDBODYCOLLISIONS) TwAddButton(g_pTweakBar, "Reset Objects in Scene", resetObjectsInScene, nullptr, ""); TwAddButton(g_pTweakBar, "Reset Objects + Settings", resetScene, nullptr, ""); TwAddButton(g_pTweakBar, "Reset Camera", [](void *){g_camera.Reset(); }, nullptr, ""); TwAddVarRW(g_pTweakBar, "Scale", TW_TYPE_FLOAT, &SCM.sceneScale, "min=0.05 step=0.05"); TwAddVarRW(g_pTweakBar, "Timestep", TW_TYPE_FLOAT, &SCM.sceneTimeStep, "min=0 step=0.0005"); TwAddButton(g_pTweakBar, (SCM.simulateByStep ? "Run Step: [(space)]" : "Run Step: [continuous]"), rebuildTwBar, &SCM.simulateByStep, ""); #else TwAddButton(g_pTweakBar, "Reset Scene", resetScene, nullptr, ""); TwAddButton(g_pTweakBar, "Reset Camera", [](void *){g_camera.Reset(); }, nullptr, ""); // Run mode, step by step, control by space key TwAddVarRW(g_pTweakBar, "RunStep(space)", TW_TYPE_BOOLCPP, &g_bSimulateByStep, ""); #endif #if (defined RIGIDBODYCOLLISIONS) TwAddButton(g_pTweakBar, (SCM.enableInteraction ? "Interactions [enabled]" : "Interactions [disabled]"), rebuildTwBar, &SCM.enableInteraction, ""); if (SCM.enableInteraction) { TwAddVarRW(g_pTweakBar, " | select Box", TW_TYPE_INT32, &SCM.selectedBoxIndex, "min=-1"); TwAddVarRW(g_pTweakBar, " | select Corner", TW_TYPE_INT32, &SCM.selectedPointIndex, "min=-1 max=7"); TwAddButton(g_pTweakBar, " | apply force", applyForce, nullptr, ""); TwAddVarRW(g_pTweakBar, " | force x", TW_TYPE_FLOAT, &SCM.forceToApply.x, ""); TwAddVarRW(g_pTweakBar, " | force y", TW_TYPE_FLOAT, &SCM.forceToApply.y, ""); TwAddVarRW(g_pTweakBar, " | force z", TW_TYPE_FLOAT, &SCM.forceToApply.z, ""); } TwAddButton(g_pTweakBar, (SCM.showAdditionalProperties ? "Properties [visible]" : "Properties [hidden]"), rebuildTwBar, &SCM.showAdditionalProperties, ""); if (SCM.showAdditionalProperties) { TwAddVarRW(g_pTweakBar, " | Normals", TW_TYPE_BOOLCPP, &SCM.showNormals, ""); //TwAddVarRW(g_pTweakBar, " | Mass Indicators", TW_TYPE_BOOLCPP, &SCM.showMasses, ""); TwAddVarRW(g_pTweakBar, " | Unit Cube", TW_TYPE_BOOLCPP, &SCM.showUnitBox, ""); } TwAddButton(g_pTweakBar, (SCM.gravityEnabled ? "Gravity [enabled]" : "Gravity [disabled]"), rebuildTwBar, &SCM.gravityEnabled, ""); if (SCM.gravityEnabled) { TwAddVarRW(g_pTweakBar, " | gravity x", TW_TYPE_FLOAT, &SCM.gravityForce.x, ""); TwAddVarRW(g_pTweakBar, " | gravity y", TW_TYPE_FLOAT, &SCM.gravityForce.y, ""); TwAddVarRW(g_pTweakBar, " | gravity z", TW_TYPE_FLOAT, &SCM.gravityForce.z, ""); } TwAddButton(g_pTweakBar, (SCM.floorEnabled ? "Floor [visible]" : "Floor [hidden]"), rebuildTwBar, &SCM.floorEnabled, ""); if (SCM.floorEnabled) { TwAddVarRW(g_pTweakBar, " | Floor Height", TW_TYPE_FLOAT, &SCM.floorPosition.y, ""); } #endif #ifdef TEMPLATE_DEMO switch (g_iTestCase) { case 0: TwAddVarRW(g_pTweakBar, "Draw Spheres", TW_TYPE_BOOLCPP, &g_bDrawSpheres, ""); TwAddVarRW(g_pTweakBar, "Num Spheres", TW_TYPE_INT32, &g_iNumSpheres, "min=1"); TwAddVarRW(g_pTweakBar, "Sphere Size", TW_TYPE_FLOAT, &g_fSphereSize, "min=0.01 step=0.01"); break; case 1: TwAddVarRW(g_pTweakBar, "Draw Teapot", TW_TYPE_BOOLCPP, &g_bDrawTeapot, ""); break; case 2: TwAddVarRW(g_pTweakBar, "Draw Triangle", TW_TYPE_BOOLCPP, &g_bDrawTriangle, ""); break; default: break; } #endif }