Exemplo n.º 1
0
/** Initializes GUI - only AntweakBar menu creation */
void initGUI()
{
    // Initialize AntTweakBar GUI
    if (!TwInit(TW_OPENGL, NULL))
    {
        assert(0);
    }

    TwWindowSize(g_WindowWidth, g_WindowHeight);
    TwBar *controlBar = TwNewBar("Controls");
    TwDefine("Controls position='10 10' size='200 300' refresh=0.1  color='130 140 150'");
	
	TwAddVarCB(controlBar, "gpu", TW_TYPE_BOOLCPP, cbSetGPUUsage, cbGetGPUUsage, NULL, " group='CUDA' label='Compute on:' true='GPU' false='CPU' ");
	//TwAddVarRW(controlBar, "restart", TW_TYPE_BOOLCPP, &g_initData, " group='PROGRAM' label='Restart: ' true='' false='restart' ");
    
    TwAddVarRW(controlBar, "melt", TW_TYPE_BOOLCPP, &g_melt, " group='Render' label='Melt' key=m help='Start melting' ");
	TwAddVarRW(controlBar, "wiremode", TW_TYPE_BOOLCPP, &g_WireMode, " group='Render' label='Wire mode' key=w help='Toggle wire mode.' ");
    TwAddVarRW(controlBar, "march", TW_TYPE_BOOLCPP, &g_useMarchingCubes, " group='Render' label='March. Cubes' help='Toggle marching cubes.' ");
    
    TwAddVarRW(controlBar, "auto-rotation", TW_TYPE_BOOLCPP, &g_SceneRotEnabled, " group='Scene' label='rotation' key=r help='Toggle scene rotation.' ");
    TwAddVarRW(controlBar, "Translate", TW_TYPE_FLOAT, &g_SceneTraZ, " group='Scene' label='translate' min=1 max=1000 step=10 keyIncr=t keyDecr=T help='Scene translation.' ");
    TwAddVarRW(controlBar, "SceneRotation", TW_TYPE_QUAT4F, &g_SceneRot, " group='Scene' label='rotation' open help='Toggle scene orientation.' ");
	
	TwAddVarRO(controlBar, "fps", TW_TYPE_FLOAT, &g_fps, " group='INFO' label='Current fps' ");
	TwAddVarRO(controlBar, "ice", TW_TYPE_FLOAT, &g_iceParticles, " group='INFO' label='Ice particles' ");
	
}
void RTweakBar::AddBoolR(const char* table, bool* value, const char* name)
{
	if(!GetBarByName(table))
		return;

	TwAddVarRO(GetBarByName(table), name, TwType::TW_TYPE_BOOLCPP, value, nullptr);
}
void RTweakBar::AddIntR(const char* table, int* value, const char* name, float min, float max, float step)
{
	if(!GetBarByName(table))
		return;

	TwAddVarRO(GetBarByName(table), name, TwType::TW_TYPE_INT32, value, nullptr);
}
Exemplo n.º 4
0
void InterfaceGl::implAddParam( const std::string &name, void *param, int type, const std::string &optionsStr, bool readOnly )
{
	if( readOnly )
		TwAddVarRO( mBar.get(), name.c_str(), (TwType)type, param, optionsStr.c_str() );
	else
		TwAddVarRW( mBar.get(), name.c_str(), (TwType)type, param, optionsStr.c_str() );
}
StreamEmitter::StreamEmitter(string _fileName, ID3D11Device* _GD, int _numParticles, float _rate, float _life, float _speed, string _particleName) : 
				Emitter(_fileName, _GD, _numParticles, _rate, _life, _speed, _particleName)
{
	spawnTimer = 0;

	numParticles = _numParticles;
	rate = _rate;
	life = _life;
	speed = _speed;

	//Setup Antweakbar to display current values of the emitter

	TwBar* UI = TwNewBar("Stream Emitter values");
	TwAddVarRO(UI, "Maximum particles:", TW_TYPE_INT32, &numParticles, "");
	TwAddVarRO(UI, "Rate:", TW_TYPE_FLOAT, &rate, "");
	TwAddVarRO(UI, "Lifetime:", TW_TYPE_FLOAT, &life, "");
	TwAddVarRO(UI, "Speed:", TW_TYPE_FLOAT, &speed, "");

}
Exemplo n.º 6
0
	void TweakBar::Create()
	{
		TwAddVarRO(m_act, "Active ID", TW_TYPE_INT32, &m_groupId, "");
		TwAddButton(m_bar, "Press1",	NULL, NULL, " label='| [1]Select Group 1 | [2]Select Group 2 | [WASD]Camera Movement |'");
		TwAddButton(m_bar, "Press2",	NULL, NULL, " label='-----------------------------------------------------------------'");
		TwAddButton(m_bar, "click",	NULL, NULL, " label='Select a group to select a mode'");
		TwAddButton(m_bar, "Press3",	NULL, NULL, " label='-----------------------------------------------------------------'");
		TwAddButton(m_bar, "cameramove",	NULL, NULL, " label='[Left Mouse]Click anywhere on the ground for Patrol Mode'");
		TwAddButton(m_bar, "Press4",	NULL, NULL, " label='-----------------------------------------------------------------'");
		TwAddButton(m_bar, "Press5",	NULL, NULL, " label='MODES | [I]dle | [P]atrol | Attac[K] |'");
	}
Exemplo n.º 7
0
void outPut::init_Bars()
{
    b_scene = TwNewBar("Scene");
    _scene3d.distance = _dimensions.x+_dimensions.y;
    _scene3d.zoom = 60;
    _scene3d.focus = coords3d<float>::retournercoords3d(_dimensions.x/2,_dimensions.y/2,0);
    //_scene3d.orientation = {0, 0, 0, 1}; // direction pointing to +x and +y
    _scene3d.orientation[0]=_scene3d.orientation[1]=_scene3d.orientation[2]=0;
    _scene3d.orientation[3]=1;
    TwAddVarRW(b_scene, "Orientation", TW_TYPE_QUAT4F, &(_scene3d.orientation),"axisx=x axisy=y axisz=z");
    TwAddVarRW(b_scene, "Distance", TW_TYPE_DOUBLE, &(_scene3d.distance),"");
    TwAddVarRW(b_scene, "Zoom", TW_TYPE_DOUBLE, &(_scene3d.zoom),"min = 5 max = 200");
    TwAddVarRW(b_scene, "x", TW_TYPE_FLOAT, &(_scene3d.focus.x), "group = 'Focus' ");
    TwAddVarRW(b_scene, "y", TW_TYPE_FLOAT, &(_scene3d.focus.y), "group = 'Focus' ");
    TwAddVarRW(b_scene, "z", TW_TYPE_FLOAT, &(_scene3d.focus.z), "group = 'Focus'");
    TwAddButton(b_scene, "Centrer", cbCenterView, this, " group = 'Focus' ");
    TwAddVarRW(b_scene, "Test de profondeur résultat", TW_TYPE_BOOLCPP,
               &(_reg.ZTEST_RESULT), "label='Z test resultat'");

    TwAddVarRW(b_scene, "Temps de calcul (ms)", TW_TYPE_INT32, &(_status.drawDelay), "min=0 max=1000");

    //_scene3d.lightDir = {1,1,-1};
    _scene3d.lightDir[0]=_scene3d.lightDir[1]=1;
    _scene3d.lightDir[2]=-1;
    //_scene3d.lightPos = {-1,-1,1,0};
    _scene3d.lightPos[0]=_scene3d.lightPos[1]=-1;
    _scene3d.lightPos[2]=1;
    _scene3d.lightPos[3]=0;
    TwAddVarRW(b_scene, "Direction", TW_TYPE_DIR3F, &(_scene3d.lightDir), "group = Lumiere" );
    TwAddVarRW(b_scene, "Directionnelle", TW_TYPE_FLOAT, &(_scene3d.lightPos[3]), "group = Lumiere min=0 max =1" );

    b_reglages = TwNewBar("Reglages");
    TwAddVarRO(b_reglages, "MAX_FPS", TW_TYPE_INT32, &(_reg.MAX_FPS), "group='Window settings'");
    TwAddButton(b_reglages, "Recalculer", recalculate, this, " group = Rendu ");
    TwAddVarRW(b_reglages, "Multiplicateur", TW_TYPE_DOUBLE, &(_reg.MULTIPLIER), "group = 'Rendu' min = 0 max = 100");
    TwType colorsType;
    colorsType = TwDefineEnum("ColorsType", NULL, 0);
    //TwAddVarRW(b_reglages, "Couleurs", colorsType, &(_reg.COLORS), " enum='0 {Réelles}, 1 {Colorisé}, 2 {Uniforme}'");
    TwAddVarRW(b_reglages, "Filaire", TW_TYPE_BOOLCPP, &(_reg.WIREFRAME), " group = Rendu ");
    TwAddVarRW(b_reglages, "Normales", TW_TYPE_BOOLCPP, &(_reg.DRAW_NORMALS), "group = 'Rendu'");
    TwAddVarRW(b_reglages, "Couleur unie", TW_TYPE_COLOR3F, &(_reg.UNIFORM_COLOR), "colormode=hls group = 'Rendu'");
    b_postprocess = TwNewBar("Post-processing");
    _effect = 0;
    TwAddVarRW(b_postprocess, "Effet", TW_TYPE_INT32, &(_effect),"max=20 keyincr = p keydecr = m");

    b_pathfind = TwNewBar("Pathfind");
    TwAddVarRW(b_pathfind, "En cours", TW_TYPE_BOOLCPP, &(_status.running), "help='Fermer le programme' key=ESC");
    TwAddVarRW(b_pathfind, "Pause", TW_TYPE_BOOLCPP, &(_status.pause), "key=t");

    TwSetTopBar(b_scene);
    TwDefine(" Reglages iconified=true ");
    TwDefine(" Pathfind iconified=true ");
    TwDefine(" Post-processing iconified=true ");
}
Exemplo n.º 8
0
void SetupAntTweakBar()
{
	TwInit(TW_DIRECT3D11, (void*)device);
	TwWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	antbar = TwNewBar("VoxelAO");
	TwDefine(" VoxelAO size='260 320' ");

#ifdef ENABLE_VOXELDRAW
	TwAddVarRW(antbar, "voxeldraw", TW_TYPE_BOOLCPP, &enableDebugDraw, " label='Draw Voxels' group='Voxels'");
	TwAddVarRO(antbar, "voxelCounter", TW_TYPE_UINT32, &voxelCounter, " label='Drawn voxels' group='Voxels'");
#endif

	TwAddVarRO(antbar, "FPS", TW_TYPE_UINT32, &FPS, " label='FPS' group='Timing'");
	TwAddVarRO(antbar, "aotime", TW_TYPE_FLOAT, &AOTime, " label='AO Time' group='Timing'");
	TwAddVarRO(antbar, "voxtime", TW_TYPE_FLOAT, &voxelTime, " label='Voxel Time' group='Timing'");
	TwAddVarRW(antbar, "kernaldraw", TW_TYPE_BOOLCPP, &enableDrawKernel, " label='Draw Kernel' group='Kernel'");
	TwAddVarRW(antbar, "sizeX", TW_TYPE_INT32, &sampleOptions.sizeX, " label='Kernel size X' group='Kernel'");
	TwDefine("VoxelAO/sizeX min=1 max=32");
	TwAddVarRW(antbar, "sizeY", TW_TYPE_INT32, &sampleOptions.sizeY, " label='Kernel Size Y' group='Kernel'");
	TwDefine("VoxelAO/sizeY min=1 max=32");
	TwAddVarRW(antbar, "steps", TW_TYPE_INT32, &sampleOptions.steps, " label='Kernel Steps' group='Kernel'");
	TwDefine("VoxelAO/steps min=1");
	TwAddVarRW(antbar, "length", TW_TYPE_FLOAT, &sampleOptions.length, " label='Kernel Length' group='Kernel'");
	TwDefine("VoxelAO/length min=1");
	
	{
		TwEnumVal enumval[] = { { DRAW_NORMAL, "Normal" },{ DRAW_NO_AO, "No AO" },{ DRAW_AO_ONLY, "Only AO"} };
		TwType type = TwDefineEnum("DEBUG_DRAW_MODE", enumval, ARRAYSIZE(enumval));
		TwAddVarRW(antbar, "Drawmode", type, &drawMode, " label='Draw mode' group='Draw' ");
	}

	{
		TwEnumVal enumval[] = { { _64, "64x64x64" },{ _128, "128x128x128" },{ _256, "256x256x256" },{ _512, "512x512x512" },{ _1024, "1024x1024x1024" } };
		TwType type = TwDefineEnum("VoxelResolution", enumval, ARRAYSIZE(enumval));
		TwAddVarRW(antbar, "voxelres", type, &voxelRes, " label='Voxel Resolution' group='Voxels' ");
	}
}
Exemplo n.º 9
0
void GetFilmRewindRate_main(int dummy1,int dummy2,float *pRewindRate)
{
	static float fRewindRate = 0.0f;
	//ファイル巻取り率取得
	fRewindRate = *pRewindRate * 100;

	static bool bFirstCall = true;
	if(bFirstCall){
		TwAddVarRO(TW_Global::bar,TW_Global::sRewindRate, TW_TYPE_FLOAT, &fRewindRate, 
			   " label='Strip length' help='test' ");
		bFirstCall = false;
	}

	TwSetParam(TW_Global::bar, TW_Global::sRewindRate,"label",TW_PARAM_CSTRING,1,TW_Global::sRewindRate);

}
Exemplo n.º 10
0
void InterfaceGl::addParam( const std::string &name, const std::vector<std::string> &enumNames, int *param, const std::string &optionsStr, bool readOnly )
{
	TwEnumVal *ev = new TwEnumVal[enumNames.size()];
	for( size_t v = 0; v < enumNames.size(); ++v ) {
		ev[v].Value = v;
		ev[v].Label = const_cast<char*>( enumNames[v].c_str() );
	}

	TwType evType = TwDefineEnum( (name + "EnumType").c_str(), ev, enumNames.size() );

	if( readOnly )
		TwAddVarRO( mBar.get(), name.c_str(), evType, param, optionsStr.c_str() );
	else
		TwAddVarRW( mBar.get(), name.c_str(), evType, param, optionsStr.c_str() );
		
	delete [] ev;
}
Exemplo n.º 11
0
void setup()
{
    // Initialize AntTweakBar
    TwInit(TW_OPENGL_CORE, NULL);

    bgColor = color(100, 100, 100);
    rectColor = colorA(255, 0, 0, 200);

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    WindowSizeCB(window, width, height);

    glfwSetWindowSizeCallback(window, WindowSizeCB);
    glfwSetMouseButtonCallback(window, TwEventMouseButtonGLFW);
    glfwSetCursorPosCallback(window, TwEvenCursorPosGLFW);
    glfwSetScrollCallback(window, TwEventScrollGLFW);
    glfwSetKeyCallback(window, TwEventKeyGLFW);
    glfwSetCharCallback(window, TwEventCharGLFW);

    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar.
    // Add 'speed' to 'bar': it is a modifable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [s] and [S].
    TwAddVarRW(bar, "speed", TW_TYPE_DOUBLE, &speed,
               " label='Rot speed' min=0 max=2 step=0.01 keyIncr=s keyDecr=S help='Rotation speed (turns/second)' ");

    // Add 'wire' to 'bar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w].
    TwAddVarRW(bar, "wire", TW_TYPE_BOOL32, &wire,
               " label='Wireframe mode' key=w help='Toggle wireframe display mode.' ");

    // Add 'time' to 'bar': it is a read-only (RO) variable of type TW_TYPE_DOUBLE, with 1 precision digit
    TwAddVarRO(bar, "time", TW_TYPE_DOUBLE, &time, " label='Time' precision=1 help='Time (in seconds).' ");

    // Add 'bgColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color)
    TwAddVarRW(bar, "bgColor", TW_TYPE_COLOR3F, bgColor.rgba, " label='Background color' ");

    // Add 'rectColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR32 (32 bits color) with alpha
    TwAddVarRW(bar, "rectColor", TW_TYPE_COLOR4F, rectColor.rgba,
               " label='Rect color' alpha help='Color and transparency of the rect.' ");

}
Exemplo n.º 12
0
// Main function
int main() 
{
    // Initialize GLFW  
    if( !glfwInit() )
    {
        // A fatal error occurred
        std::cerr << "GLFW initialization failed" << std::endl;
        return 1;
    }

    // Create a window
    GLFWvidmode mode;
    glfwGetDesktopMode(&mode);
    if( !glfwOpenWindow(800, 600, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 16, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) )
    {
        // A fatal error occurred   
        std::cerr << "Cannot open GLFW window" << std::endl;
        glfwTerminate();
        return 1;
    }
    glfwSwapInterval(0);
    glfwEnable(GLFW_MOUSE_CURSOR);
    glfwEnable(GLFW_KEY_REPEAT);
    const char title[] = "AntTweakBar example: TwAdvanced1";
    glfwSetWindowTitle(title);
    // Set GLFW event callbacks
    glfwSetWindowSizeCallback(OnWindowSize);
    glfwSetMouseButtonCallback(OnMouseButton);
    glfwSetMousePosCallback(OnMousePos);
    glfwSetMouseWheelCallback(OnMouseWheel);
    glfwSetKeyCallback(OnKey);
    glfwSetCharCallback(OnChar);

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);
    // Change the font size, and add a global message to the Help bar.
    TwDefine(" GLOBAL fontSize=3 help='This example illustrates the definition of custom structure type as well as many other features.' ");

    // Initialize the 3D scene
    Scene scene;
    scene.Init(true);

    // Create a tweak bar called 'Main' and change its refresh rate, position, size and transparency
    TwBar *mainBar = TwNewBar("Main");
    TwDefine(" Main label='Main TweakBar' refresh=0.5 position='16 16' size='260 320' alpha=0");

    // Add some variables to the Main tweak bar
    TwAddVarRW(mainBar, "Wireframe", TW_TYPE_BOOLCPP, &scene.Wireframe, 
               " group='Display' key=w help='Toggle wireframe display mode.' "); // 'Wireframe' is put in the group 'Display' (which is then created)
    TwAddVarRW(mainBar, "BgTop", TW_TYPE_COLOR3F, &scene.BgColor1, 
               " group='Background' help='Change the top background color.' ");  // 'BgTop' and 'BgBottom' are put in the group 'Background' (which is then created)
    TwAddVarRW(mainBar, "BgBottom", TW_TYPE_COLOR3F, &scene.BgColor0, 
               " group='Background' help='Change the bottom background color.' ");
    TwDefine(" Main/Background group='Display' ");  // The group 'Background' of bar 'Main' is put in the group 'Display'
    TwAddVarCB(mainBar, "Subdiv", TW_TYPE_INT32, SetSubdivCB, GetSubdivCB, &scene, 
               " group='Scene' label='Meshes subdivision' min=1 max=50 keyincr=s keyDecr=S help='Subdivide the meshes more or less (switch to wireframe to see the effect).' ");
    TwAddVarRW(mainBar, "Ambient", TW_TYPE_FLOAT, &scene.Ambient, 
               " label='Ambient factor' group='Scene' min=0 max=1 step=0.001 keyIncr=a keyDecr=A help='Change scene ambient.' ");
    TwAddVarRW(mainBar, "Reflection", TW_TYPE_FLOAT, &scene.Reflection, 
               " label='Reflection factor' group='Scene' min=0 max=1 step=0.001 keyIncr=r keyDecr=R help='Change ground reflection.' ");

    // Create a new TwType called rotationType associated with the Scene::RotMode enum, and use it
    TwEnumVal rotationEV[] = { { Scene::ROT_OFF, "Stopped"}, 
                               { Scene::ROT_CW,  "Clockwise" }, 
                               { Scene::ROT_CCW, "Counter-clockwise" } };
    TwType rotationType = TwDefineEnum( "Rotation Mode", rotationEV, 3 );
    TwAddVarRW(mainBar, "Rotation", rotationType, &scene.Rotation, 
               " group='Scene' keyIncr=Backspace keyDecr=SHIFT+Backspace help='Stop or change the rotation mode.' ");

    // Add a read-only float variable; its precision is 0 which means that the fractionnal part of the float value will not be displayed
    TwAddVarRO(mainBar, "RotYAngle", TW_TYPE_DOUBLE, &scene.RotYAngle, 
               " group='Scene' label='Rot angle (degree)' precision=0 help='Animated rotation angle' ");

    // Initialize time
    double time = glfwGetTime(), dt = 0;            // Current time and elapsed time
    double frameDTime = 0, frameCount = 0, fps = 0; // Framerate

    // Main loop (repeated while window is not closed)
    while( glfwGetWindowParam(GLFW_OPENED) )
    {
        // Get elapsed time
        dt = glfwGetTime() - time;
        if (dt < 0) dt = 0;
        time += dt;

        // Rotate scene
        if( scene.Rotation==Scene::ROT_CW )
            scene.RotYAngle -= 5.0*dt;
        else if( scene.Rotation==Scene::ROT_CCW )
            scene.RotYAngle += 5.0*dt;

        // Move lights
        scene.Update(time);

        // Draw scene
        scene.Draw();

        // Draw tweak bars
        TwDraw();

        // Present frame buffer
        glfwSwapBuffers();

        // Estimate framerate
        frameCount++;
        frameDTime += dt;
        if( frameDTime>1.0 )
        {
            fps = frameCount/frameDTime;
            char newTitle[128];
            _snprintf(newTitle, sizeof(newTitle), "%s (%.1f fps)", title, fps);
            //glfwSetWindowTitle(newTitle); // uncomment to display framerate
            frameCount = frameDTime = 0;
        }
    }

    // Terminate AntTweakBar and GLFW
    TwTerminate();
    glfwTerminate();

    return 0;
}
Exemplo n.º 13
0
void CGUI::AddVar(const char* name, TwType type, const void* Var){
	TwAddVarRO(m_pGUI, name, type, Var,"");
}
Exemplo n.º 14
0
// Create / load the camera, models and textures for the scene
bool CScene::InitScene()
{
	//////////////////
	// Create camera

	//Camera = new CCamera();
	Camera.SetPosition( DirectX::XMFLOAT3(-15, 20,-40) );
	Camera.SetRotation( DirectX::XMFLOAT3(ToRadians(13.0f), ToRadians(18.0f), 0.0f) ); // ToRadians is a new helper function to convert degrees to radians
	Camera.SetNearClip( 1.0f );

	//load all textures and maps
	miNumMaps = 0;

	//Load map data
	mc_map = new MapSquare(mySettings->mapFile, mySettings);

	//caching these locally - does mean more coupling, but seems better than fetching an unchanging variable repeatedly.
	mi_mapHeight = mc_map->GetHeight();
	mi_mapWidth = mc_map->GetWidth();
	
	//mp_openSquares = new ModelBatch();
	mp_openSquares.Load( "Cube.x", mTechniques[0], false );
	mp_openSquares.SetColour(_WHITE);
	//mp_openSquares.mp_technique = mTechniques[0];

	//mp_walls = new ModelBatch();
	mp_walls.Load( "Cube.x", mTechniques[0], false );
	mp_walls.SetColour(_BLACK);
	//mp_walls.mp_technique = mTechniques[0];

	mp_pathModel.Load("TrafficCone.x", mTechniques[0], false);
	mp_pathModel.SetColour(_ORANGE);
	//mp_pathModel.mp_technique = mTechniques[0];

	mp_splineModel.Load("TrafficCone.x", mTechniques[0], false);
	mp_splineModel.SetColour(_ORANGE);
	//mp_splineModel.mp_technique = mTechniques[0];

	mp_chokeModel = new CRenderObject(
		"Sphere.x",
		DirectX::XMFLOAT3(mc_map->ms_chokePoint.x, 2.0f, mc_map->ms_chokePoint.y),
		_RED,
		mTechniques[0],
		NULL
		);
	mp_chokeModel->GetModel()->SetScale(0.05f);

	miNumLights = 0;
	/*
	//Light 1 - Orbit Light
	CModel* temp = new CModel;
	mpLights[miNumLights] = new CLight();
	if (!temp->Load("Sphere.x", mTechniques[0])) return false;
	mpLights[miNumLights]->SetModel(temp);
	mpLights[miNumLights]->SetColour(1.0f, 0.0f, 0.7f);
	mpLights[miNumLights]->GetModel()->SetPosition(DirectX::XMFLOAT3(30, 10, 0));
	mpLights[miNumLights]->GetModel()->SetScale(0.1f);
	mpLights[miNumLights]->SetBrightness(10.0f);
	mpLights[miNumLights]->SetOrbit(DirectX::XMFLOAT3(0, 20, 0), 25.0f, 0.1f);
	mpLights[miNumLights]->SetColourCycle(17.0f);

	miNumLights++;


	//Light 2 - Pulse Light
	temp = new CModel;
	mpLights[miNumLights] = new CLight();
	if (!temp->Load("Sphere.x", mTechniques[0])) return false;
	mpLights[miNumLights]->SetModel(temp);
	mpLights[miNumLights]->SetColour(1.0f, 0.8f, 0.2f);
	mpLights[miNumLights]->GetModel()->SetPosition(DirectX::XMFLOAT3(-20, 30, 50));
	mpLights[miNumLights]->GetModel()->SetScale(0.2f);
	mpLights[miNumLights]->GetModel()->UpdateMatrix();
	mpLights[miNumLights]->SetBrightness(5.0f);
	mpLights[miNumLights]->SetFade(2.0f);

	miNumLights++;

	//Light 3 - Disco Light

	temp = new CModel;
	mpLights[miNumLights] = new CLight();
	if (!temp->Load("Sphere.x", mTechniques[0])) return false;
	mpLights[miNumLights]->SetModel(temp);
	mpLights[miNumLights]->SetColour(1.0f, 0.8f, 0.2f);
	mpLights[miNumLights]->GetModel()->SetPosition(DirectX::XMFLOAT3(200, 25, 200));
	mpLights[miNumLights]->GetModel()->SetScale(0.2f);
	mpLights[miNumLights]->GetModel()->UpdateMatrix();
	mpLights[miNumLights]->SetBrightness(5.0f);
	mpLights[miNumLights]->SetDisco();

	miNumLights++;

	for (int i = 0; i < 10; i++)
	{
		temp = new CModel;
		mpLights[miNumLights] = new CLight();
		if (!temp->Load("Sphere.x", mTechniques[0])) return false;
		mpLights[miNumLights]->SetModel(temp);
		mpLights[miNumLights]->SetColour(i / 10.0f, i / 10.0f, 1.0f);
		mpLights[miNumLights]->GetModel()->SetPosition(DirectX::XMFLOAT3(200, 10, i*30.0f));
		mpLights[miNumLights]->GetModel()->SetScale(i / 10.0f);
		mpLights[miNumLights]->GetModel()->UpdateMatrix();
		miNumLights++;
	}
	*/

	mp_heavyTurretModel.Load("Cube.x", mTechniques[0], false);
	mp_heavyTurretModel.SetColour(_RED);

	mp_mediumTurretModel.Load("Cube.x", mTechniques[0], false);
	mp_mediumTurretModel.SetColour(_MRED);

	mp_lightTurretModel.Load("Cube.x", mTechniques[0], false);
	mp_lightTurretModel.SetColour(_LRED);

	for( uint32_t y = 0; y < mi_mapHeight; y++ )
	{
		for( uint32_t x = 0; x < mi_mapWidth; x++ )
		{
			switch( mc_map->GetCost( x, y ) )
			{
				case 0: //walls
					mp_matrixArray[mi_numSquares] = mp_walls.AddInstance( DirectX::XMFLOAT3( static_cast<float>(x), 0.0f, static_cast<float>(y) ), 0.1f );
					break;
				case 1: //open
					mp_matrixArray[mi_numSquares] = mp_openSquares.AddInstance( DirectX::XMFLOAT3( static_cast<float>(x), 0.0f, static_cast<float>(y) ), 0.1f );
					break;
				case 2:
					mp_p1StartModel = new CRenderObject( "Cube.x", DirectX::XMFLOAT3( static_cast<float>(x), 0.0f, static_cast<float>(y) ), DirectX::XMFLOAT3( 0.0f, 0.0f, 0.0f ), mTechniques[0], NULL );
					mp_p1StartModel->SetColour( _RED );
					mp_p1StartModel->GetModel()->SetScale(0.1f);
					mp_p1StartModel->GetModel()->UpdateMatrix();
					md_p1StartMatrix = mp_p1StartModel->GetModel()->GetWorldMatrix();
					mp_matrixArray[mi_numSquares] = &md_p1StartMatrix;
					break;
				case 3:
					mp_p2StartModel = new CRenderObject( "Cube.x", DirectX::XMFLOAT3( static_cast<float>(x), 0.0f, static_cast<float>(y) ), DirectX::XMFLOAT3( 0.0f, 0.0f, 0.0f ), mTechniques[0], NULL );
					mp_p2StartModel->SetColour( _GREEN );
					mp_p2StartModel->GetModel()->SetScale( 0.1f );
					mp_p2StartModel->GetModel()->UpdateMatrix();
					md_p2StartMatrix = mp_p2StartModel->GetModel()->GetWorldMatrix();
					mp_matrixArray[mi_numSquares] = &md_p2StartMatrix;
					break;
			}

			mi_numSquares++;
		}
	}

	mpObjects[0] = mp_p1StartModel;
	mpObjects[1] = mp_p2StartModel;
	mpObjects[2] = mp_chokeModel;
	miNumObjects = 3;

	  ///////////////////////////////////////
	 // Text                              //
	///////////////////////////////////////

	mpSpriteBatch = new DirectX::SpriteBatch( mpd3dDeviceContext );
	mpSpriteFont = new DirectX::SpriteFont(mpd3dDevice, L"Arial.spritefont");

	mb_showBase2IM = false;
	mb_showBaseIM = false;
	mb_showCost = false;
	mb_showHTIM = false;
	mb_showLTIM = false;
	mb_showMTIM = false;
	mb_showPathIM = false;
	mb_showWallIM = false;

	  ///////////////////////////////////////
	 // Tweak bars                        //
	///////////////////////////////////////

	int32_t result;
	result = TwInit(TW_DIRECT3D11, mpd3dDevice);
	TweakError(result)
	result = TwWindowSize(mySettings->resolutionX, mySettings->resolutionY);
	TweakError( result )
		
		
	mpSettingsBar = TwNewBar( "Settings" );
	TwDefine(" Settings position='5 5' ");
	result = TwAddSeparator( mpSettingsBar, "Graphics - requires restart", "" );
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "ResolutionX", TW_TYPE_UINT32, &mySettings->resolutionX, "" );
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "ResolutionY", TW_TYPE_UINT32, &mySettings->resolutionY, "" );
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "Node Model", TW_TYPE_CHAR, &mySettings->nodeModel, "");
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "Node Scale", TW_TYPE_FLOAT, &mySettings->nodeScale, "");
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "Spline Model", TW_TYPE_CHAR, &mySettings->splineModel, "");
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "Spline Scale", TW_TYPE_FLOAT, &mySettings->splineScale, "");
	TweakError( result )
	result = TwAddSeparator(mpSettingsBar, "AI - requires recalcualte", "");
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "Wall Range", TW_TYPE_UINT32, &mySettings->wallRange, "" );
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "Base Range", TW_TYPE_UINT32, &mySettings->baseRange, "" );
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "Heavy Turret Range", TW_TYPE_UINT32, &mySettings->HTRange, "" );
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "Medium Turret Range", TW_TYPE_UINT32, &mySettings->MTRange, "" );
	TweakError( result )
	result = TwAddVarRW( mpSettingsBar, "Light Turret Range", TW_TYPE_UINT32, &mySettings->LTRange, "" );
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "Minimum Path Length", TW_TYPE_UINT32, &mySettings->MinPathLength, "");
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "Maximum Path Length", TW_TYPE_FLOAT, &mySettings->MaxPathLength, "min=0.1 max=0.9 step=0.1");
	TweakError( result )
	result = TwAddVarRW(mpSettingsBar, "ChokeThreshold", TW_TYPE_UINT32, &mySettings->ChokeThreshold, "");
	TweakError( result )

	mpCalculationsBar = TwNewBar("Calculations");
	TwDefine( " Calculations position='205 5' " );
	result = TwAddButton(mpCalculationsBar, "Recalculate Walls", CalculateWallIM, mc_map, "");
	TweakError( result )
	result = TwAddButton( mpCalculationsBar, "Recalculate Path", CalculatePath, mc_map, "" );
	TweakError(result)
	result = TwAddButton(mpCalculationsBar, "Visualise Path", TWVisualisePath, mp_self, "");
	TweakError(result)
	result = TwAddButton(mpCalculationsBar, "Place Heavy Turret", TwPlaceHeavyTurret, mc_map, "");
	TweakError(result)
	result = TwAddButton(mpCalculationsBar, "Place Medium Turret", TwPlaceMediumTurret, mc_map, "");
	TweakError(result)
	result = TwAddButton(mpCalculationsBar, "Place Light Turret", TwPlaceLightTurret, mc_map, "");
	TweakError(result)
	result = TwAddButton(mpCalculationsBar, "Visualise Turrets", TwVisualiseTurrets, mp_self, "");
	TweakError(result)
	result = TwAddVarRO(mpCalculationsBar, "Last Calculation Time", TW_TYPE_FLOAT, &mc_map->mf_calcTime, "");
	TweakError(result)


	mpFileBar = TwNewBar("Files");
	TwDefine( " Files position='410 5' " );
	result = TwAddButton(mpFileBar, "Reload Settings", ReloadSettings, mySettings, "");
	TweakError( result )
	result = TwAddButton( mpFileBar, "Write Settings", WriteSettings, mySettings, "" );
	TweakError(result)
	result = TwAddSeparator(mpFileBar, "Map", "");
	TweakError(result)
	result = TwAddButton(mpFileBar, "Write map XML", WriteMapXML, mc_map, "");

	  ///////////////////////////////////////
	 // FMod                              //
	///////////////////////////////////////

	FMOD_RESULT fm_result;
	
	fm_result = FMOD::System_Create(&mp_fmodSystem);

	if (fm_result != FMOD_OK)
	{
		MessageBox(NULL, L"Error creating FMOD system.", L"Error", MB_OK);
		return false;
	}

	fm_result = mp_fmodSystem->init(10, FMOD_INIT_NORMAL, 0);

	if (fm_result != FMOD_OK)
	{
		MessageBox(NULL, L"Error initialising FMOD system.", L"Error", MB_OK);
		return false;
	}

	fm_result = mp_fmodSystem->createSound("bd.mp3", FMOD_DEFAULT, 0, &mp_bgSound);

	if (fm_result != FMOD_OK)
	{
		MessageBox(NULL, L"Error loading background sound.", L"Error", MB_OK);
		return false;
	}

	result = mp_fmodSystem->playSound(FMOD_CHANNEL_FREE, mp_bgSound, false, &mp_channel);

	return true;
}
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
	// Initialize openGL, glut, glew
	initGraphics(argc, argv);
	// Initialize AntTweakBar
	TwInit(TW_OPENGL, NULL);

	//initialize the timer frequency
	QueryPerformanceFrequency(&Frequency);

	// Set GLUT callbacks
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutMouseFunc(MouseButton);
	glutMotionFunc(MouseMotion);
	glutPassiveMotionFunc(PassiveMouseMotion);
	glutKeyboardFunc(Keyboard);
	glutSpecialFunc(Special);

	//send 'glutGetModifers' function pointer to AntTweakBar.
	//required because the GLUT key event functions do not report key modifiers states.
	//TwGLUTModifiersFunc(glutGetModifiers);


	atexit(Terminate);  //called after glutMainLoop ends


						// Create a tweak bar
	TwBar* bar = TwNewBar("TweakBar");

	TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
	TwDefine(" TweakBar size='200 600' color='96 216 224' "); // change default tweak bar size and color

	//***********************************************************************************
	//add 'g_Scale' to 'bar': this is a modifiable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [z] and [Z].
	//TwAddVarRW(bar, "Scale", TW_TYPE_DOUBLE, &g_Scale, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");
	//***********************************************************************************


	TwAddButton(bar, "LoadOBJ", loadOBJModel, NULL, "help='button to load obf file'");
	TwAddSeparator(bar, NULL, NULL);

	TwAddVarRW(bar, "reset", TW_TYPE_BOOLCPP, &g_reset, "help='reset everything'");
	TwAddVarRW(bar, "OW space", TW_TYPE_BOOLCPP, &g_space, " help='true=transforma in world space ,false=transform in object space' ");
	TwAddVarRW(bar, "OW Crd System", TW_TYPE_BOOLCPP, &g_showCrdSystem, " help='boolean variable to indicate if to show WO coordinate system or not.' ");
	TwAddVarRW(bar, "showBbox", TW_TYPE_BOOLCPP, &g_bbox, " help='boolean variable to indicate if to show the bbox or not.' ");

	TwAddVarRW(bar, "showNormals", TW_TYPE_BOOLCPP, &g_normals, " help='boolean variable to indicate if to show normals or not.' group='normals'");
	TwAddVarRW(bar, "normalsSize", TW_TYPE_DOUBLE, &g_normals_size, " min=0.1 max=100 step=0.1 keyIncr=t keyDecr=T help='Change notmals size (20=original size).' group='normals'");
	TwAddVarRW(bar, "projectionType", TW_TYPE_BOOLCPP, &g_projectionType, " help='true = orthographic, false = perspective.' group='camera'");
	TwAddVarRW(bar, "near", TW_TYPE_DOUBLE, &g_near, "step=0.01 keyIncr=n keyDecr=N  group='camera'");
	TwAddVarRW(bar, "far", TW_TYPE_DOUBLE, &g_far, "step=0.1 keyIncr=f keyDecr=F  group='camera'");
	TwAddVarRW(bar, "fovy", TW_TYPE_DOUBLE, &g_fovy, "step=0.1 keyIncr=v keyDecr=V  group='camera'");

	TwAddVarRW(bar, "centerCamera", TW_TYPE_BOOLCPP, &g_centerCam, "help='point the camera to the center of the model'  group='camera'");

	TwAddVarRW(bar, "translate X", TW_TYPE_DOUBLE, &g_translationX, "min=-30 max=30 step=1 keyIncr=right keyDecr=left   group='tranfromations' ");
	TwAddVarRW(bar, "translate Y", TW_TYPE_DOUBLE, &g_translationY, "min=-30 max=30 step=1 keyIncr=up keyDecr=down   group='tranfromations' ");
	TwAddVarRW(bar, "translate Z", TW_TYPE_DOUBLE, &g_translationZ, "min=-30 max=30 step=1 keyIncr=> keyDecr=<   group='tranfromations' ");
	TwAddButton(bar, "apply translation", applyTranslation, NULL, "help='apply translation' group='tranfromations' ");

	TwAddVarRW(bar, "scale", TW_TYPE_DOUBLE, &g_scale, " min=0.01 max=2.5 step=0.01 keyIncr=+ keyDecr=-   group='tranfromations' ");
	TwAddButton(bar, "apply scale", &applyScale, NULL, "help='apply scale' group='tranfromations' ");

	TwAddVarRW(bar, "x-rotation", TW_TYPE_DOUBLE, &g_xRotation, "min = -360 max = 360 step=1 keyIncr=x keyDecr=X   group='tranfromations' ");
	TwAddButton(bar, "apply x rotation", &applyXrotation, NULL, " help='apply scale' group='tranfromations' ");

	TwAddVarRW(bar, "y-rotation", TW_TYPE_DOUBLE, &g_yRotation, "min = -360 max = 360 step=1 keyIncr=y keyDecr=Y   group='tranfromations' ");
	TwAddButton(bar, "apply y rotation", &applyYrotation, NULL, " help='apply scale'  group='tranfromations' ");

	TwAddVarRW(bar, "z-rotation", TW_TYPE_DOUBLE, &g_zRotation, "min = -360 max = 360 step=1 keyIncr=z keyDecr=Z   group='tranfromations' ");
	TwAddButton(bar, "apply z rotation", &applyZrotation, NULL, " help='apply scale' group='tranfromations' ");

	TwAddVarRW(bar, "ambient", TW_TYPE_DOUBLE, &g_ambient, "min = 0 max = 1000 step=0.1 keyIncr=z keyDecr=Z   group='material' ");
	TwAddVarRW(bar, "diffuse", TW_TYPE_DOUBLE, &g_diffuse, "min = 0 max = 1000 step=0.1 keyIncr=z keyDecr=Z   group='material' ");
	TwAddVarRW(bar, "specular", TW_TYPE_DOUBLE, &g_specular, "min = 0 max = 1000 step=0.1 keyIncr=z keyDecr=Z   group='material' ");
	TwAddVarRW(bar, "specularExp", TW_TYPE_DOUBLE, &g_specularExp, "min = 0 max = 1000 step=1 keyIncr=z keyDecr=Z   group='material' ");

	TwAddVarRW(bar, "x-position", TW_TYPE_DOUBLE, &g_xLightPosition, "min = -1000 max = 1000 step=1 keyIncr=z keyDecr=Z   group='light' ");
	TwAddVarRW(bar, "y-position", TW_TYPE_DOUBLE, &g_yLightPosition, "min = -1000 max = 1000 step=1 keyIncr=z keyDecr=Z   group='light' ");
	TwAddVarRW(bar, "z-position", TW_TYPE_DOUBLE, &g_zLightPosition, "min = -1000 max = 1000 step=1 keyIncr=z keyDecr=Z   group='light' ");
	TwAddVarRW(bar, "x-direction", TW_TYPE_DOUBLE, &g_xLightDirection, "min = -1000 max = 1000 step=1 keyIncr=z keyDecr=Z   group='light' ");
	TwAddVarRW(bar, "y-direction", TW_TYPE_DOUBLE, &g_yLightDirection, "min = -1000 max = 1000 step=1 keyIncr=z keyDecr=Z   group='light' ");
	TwAddVarRW(bar, "z-direction", TW_TYPE_DOUBLE, &g_zLightDirection, "min = -1000 max = 1000 step=1 keyIncr=z keyDecr=Z   group='light' ");
	TwAddVarRW(bar, "point/directional", TW_TYPE_BOOLCPP, &g_lightType, "help='false=point, true=directional'  group='light'");
	TwAddVarRW(bar, "light intensity", TW_TYPE_COLOR32, &g_lightIntensity, " coloralpha=true colormode=rgb group='light'");
	TwAddButton(bar, "apply on light 1", &applyLight1, NULL, " help='apply scale' group='light' ");
	TwAddButton(bar, "apply on light 2", &applyLight2, NULL, " help='apply scale' group='light' ");
	TwAddVarRW(bar, "ambient light intensity", TW_TYPE_COLOR32, &g_ambientLight, "coloralpha=true colormode=rgb group='light' ");

	shadingType = TwDefineEnum("ShadingType", NULL, 0);
	TwAddVarRW(bar, "shading type", shadingType, &g_shadingType, " enum='0 {FLAT}, 1 {GOURAUD}, 2 {PHONG}' group='shading'");
	TwAddVarRW(bar, "show mesh model", TW_TYPE_BOOLCPP, &g_mesh, "help='false=shading, true=meshmodel'  group='shading'");

	TwAddSeparator(bar, NULL, NULL);

	//time display - don't delete
	TwAddVarRO(bar, "time (us)", TW_TYPE_UINT32, &ElapsedMicroseconds.LowPart, "help='shows the drawing time in micro seconds'");

	// Call the GLUT main loop
	glutMainLoop();

	return 0;
}
Exemplo n.º 16
0
void Camera::AddToATB(TwBar* bar)
{
    TwAddButton(bar, "Camera", NULL, NULL, "");                
    TwAddVarRW(bar, "Position", TW_TYPE_OGLDEV_VECTOR3F, (void*)&m_pos, NULL);
    TwAddVarRO(bar, "Direction", TW_TYPE_DIR3F, &m_target, " axisz=-z ");
}
Exemplo n.º 17
0
void AimerDemo::on_open()
{
    ConstrainedClothoidDemo::on_open();

    // Alter TwBar
    TwAddVarRO(twbar(), "a", TW_TYPE_FLOAT, &m_a, nullptr);
    TwAddVarRO(twbar(), "s", TW_TYPE_FLOAT, &m_s, nullptr);
    TwAddVarCB(
        twbar(), "Iters", TW_TYPE_INT32,
        set_refine_steps_cb, get_refine_steps_cb,
        this, "min=0 max=10"
    );

    // Clothoid
    gl::create_buffer(&m_cloth_vertices);
    m_cloth_ready = false;

    gl::link_program(&m_cloth_program,
        "shaders/aimer_demo_cloth_vx.glsl", "shaders/uniform4_ft.glsl");
    m_cloth_matrix_uniform = gl::get_uniform_location(m_cloth_program, "matrix");
    m_cloth_color_uniform = gl::get_uniform_location(m_cloth_program, "color");
    m_cloth_position_attrib = gl::get_attrib_location(m_cloth_program, "position");

    glUseProgram(m_cloth_program);
    glUniform4f(m_cloth_color_uniform, 0, 0, 0, 1);

    // Aimer grid and samples

    gl::link_program(&m_aimer_program, "shaders/mat3_pos2_vx.glsl", "shaders/uniform3_ft.glsl");
    m_aimer_matrix_uniform = gl::get_uniform_location(m_aimer_program, "matrix");
    m_aimer_color_uniform = gl::get_uniform_location(m_aimer_program, "color");
    m_aimer_position_attrib = gl::get_attrib_location(m_aimer_program, "position");

    // Grid

    std::vector<vec2f> grid_vertices;
    grid_vertices.reserve(4 * (ClothoidAimer::GRID_SIZE + 1));
    for (int i = 0; i <= ClothoidAimer::GRID_SIZE; ++i)
    {
        float t = lerp(-1.0f, 1.0f, float(i) / float(ClothoidAimer::GRID_SIZE));
        grid_vertices.emplace_back( t, -1);
        grid_vertices.emplace_back( t,  1);
        grid_vertices.emplace_back(-1,  t);
        grid_vertices.emplace_back( 1,  t);
    }
    gl::create_buffer(&m_grid_vertices, grid_vertices);

    // Samples

    const float SAMPLE_SIZE = 0.02f;
    std::vector<vec2f> sample_vertices;
    for (const ClothoidAimer::Sample& sample : m_aimer.m_samples)
    {
        float x = sample.p.x, y = sample.p.y;
        sample_vertices.emplace_back(x - SAMPLE_SIZE, y);
        sample_vertices.emplace_back(x + SAMPLE_SIZE, y);
        sample_vertices.emplace_back(x, y - SAMPLE_SIZE);
        sample_vertices.emplace_back(x, y + SAMPLE_SIZE);
    }
    gl::create_buffer(&m_sample_vertices, sample_vertices);

    aim();
}
Exemplo n.º 18
0
// Main
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow)
{
    // Register our window class
    WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC|CS_DBLCLKS, MessageProc, 0L, 0L, 
                        instance, NULL, NULL, NULL, NULL, "TwDX9", NULL };
    RegisterClassEx(&wcex);

    // Create a window
    const int W = 640;
    const int H = 480;
    BOOL fullscreen = FALSE; // Set to TRUE to run in fullscreen
    RECT rect = { 0, 0, W, H };
    DWORD style = fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW;
    AdjustWindowRect(&rect, style, FALSE);
    HWND wnd = CreateWindow("TwDX9", "AntTweakBar simple example using DirectX9", 
                            style, CW_USEDEFAULT, CW_USEDEFAULT, 
                            rect.right-rect.left, rect.bottom-rect.top, NULL, NULL, instance, NULL);
    if( !wnd )
    {
        MessageBox(NULL, "Cannot create window", "Error", MB_OK|MB_ICONERROR);
        return FALSE;
    }
    ShowWindow(wnd, cmdShow);
    UpdateWindow(wnd);

    // Initialize Direct3D
    g_D3D = Direct3DCreate9(D3D_SDK_VERSION);
    if( !g_D3D )
    {
        MessageBox(wnd, "Cannot initialize DirectX", "Error", MB_OK|MB_ICONERROR);
        return FALSE;
    }

    // Create a Direct3D device
    ZeroMemory( &g_D3Dpp, sizeof(D3DPRESENT_PARAMETERS) );
    g_D3Dpp.Windowed = !fullscreen;
    if( fullscreen )
    {
        g_D3Dpp.BackBufferWidth = W;
        g_D3Dpp.BackBufferHeight = H;
    }
    g_D3Dpp.BackBufferCount = 1;
    g_D3Dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
    if( fullscreen )
        g_D3Dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    else
        g_D3Dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    g_D3Dpp.hDeviceWindow = wnd;

    g_D3Dpp.EnableAutoDepthStencil = TRUE;
    g_D3Dpp.AutoDepthStencilFormat = D3DFMT_D16;
    g_D3Dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    HRESULT hr = g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 
                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING, &g_D3Dpp, &g_D3DDev);
    if( FAILED(hr) )
    {
        //DXTRACE_ERR_MSGBOX("Cannot create DirectX device", hr);
        MessageBox(wnd, "Cannot create DirectX device", "Error", MB_OK|MB_ICONERROR);
        g_D3D->Release();
        g_D3D = NULL;
        return FALSE;
    }

    // This example draws a moving strip;
    // create a buffer of vertices for the strip
    struct Vertex
    {
        float x, y, z;
        DWORD color;
    };
    Vertex vertices[2002];
    int numSec = 100;            // number of strip sections
    float color[] = { 1, 0, 0 }; // strip color
    unsigned int bgColor = D3DCOLOR_ARGB(255, 128, 196, 196); // background color

    // Init some D3D states
    InitD3D();

    // Initialize AntTweakBar
    // (note that the Direct3D device pointer must be passed to TwInit)
    if( !TwInit(TW_DIRECT3D9, g_D3DDev) )
    {
        MessageBox(wnd, TwGetLastError(), "Cannot initialize AntTweakBar", MB_OK|MB_ICONERROR);
        g_D3DDev->Release();
        g_D3DDev = NULL;
        g_D3D->Release();
        g_D3D = NULL;
        return FALSE;
    }

    
    // Create a tweak bar
    TwBar *bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar in a DirectX9 application.' "); // Message added to the help bar.
    TwDefine(" TweakBar color='128 224 160' text=dark "); // Change TweakBar color and use dark text

    // Add 'numSec' to 'bar': it is a modifiable (RW) variable of type TW_TYPE_INT32. Its shortcuts are [s] and [S].
    TwAddVarRW(bar, "NumSec", TW_TYPE_INT32, &numSec, 
               " label='Strip length' min=1 max=1000 keyIncr=s keyDecr=S help='Number of segments of the strip.' ");

    // Add 'color' to 'bar': it is a modifiable variable of type TW_TYPE_COLOR3F (3 floats color)
    TwAddVarRW(bar, "Color", TW_TYPE_COLOR3F, &color, " label='Strip color' ");

    // Add 'bgColor' to 'bar': it is a modifiable variable of type TW_TYPE_COLOR32 (32 bits color)
    TwAddVarRW(bar, "BgColor", TW_TYPE_COLOR32, &bgColor, " label='Background color' ");

    // Add 'width' and 'height' to 'bar': they are read-only (RO) variables of type TW_TYPE_INT32.
    TwAddVarRO(bar, "Width", TW_TYPE_INT32, &g_D3Dpp.BackBufferWidth, 
               " label='wnd width' help='Current graphics window width.' ");
    TwAddVarRO(bar, "Height", TW_TYPE_INT32, &g_D3Dpp.BackBufferHeight, 
               " label='wnd height' help='Current graphics window height.' ");


    // Main loop
    bool quit = false;
    while( !quit )
    {
        // Clear screen and begin draw
        g_D3DDev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, bgColor, 1.0f, 0);
        g_D3DDev->BeginScene();

        // Draw scene
        float s, t = (float)GetTickCount()/1000.0f;
        for( int i=0; i<=numSec; ++i )  // update vertices
        {
            s = (float)i/100;
            vertices[2*i+0].x = 0.05f+0.7f*cosf(2.0f*s+5.0f*t);
            vertices[2*i+1].x = vertices[2*i+0].x + (0.25f+0.1f*cosf(s+t));
            vertices[2*i+0].y = vertices[2*i+1].y = 0.7f*(0.7f+0.3f*sinf(s+t))*sinf(1.5f*s+3.0f*t);
            vertices[2*i+0].z = vertices[2*i+1].z = 0;
            s = (float)i/numSec;
            vertices[2*i+0].color = vertices[2*i+1].color = 
                D3DCOLOR_XRGB((int)(255*color[0]*s), (int)(255*color[1]*s), (int)(255*color[2]*s));
        }
        g_D3DDev->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
        g_D3DDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2*numSec, vertices, sizeof(Vertex)); // draw strip
 
        // Draw tweak bars
        TwDraw();

        // End draw
        g_D3DDev->EndScene();

        // Present frame buffer
        g_D3DDev->Present(NULL, NULL, NULL, NULL);

        // Process windows messages
        MSG msg;
        while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
        {
            if( msg.message==WM_QUIT )
                quit = true;
            else if( !TranslateAccelerator(msg.hwnd, NULL, &msg) ) 
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    } // End of main loop


    // Terminate AntTweakBar
    TwTerminate();

    // Release Direct3D
    g_D3DDev->Release();
    g_D3DDev = NULL;
    g_D3D->Release();
    g_D3D = NULL;

    return 0;
}
Exemplo n.º 19
0
int main(int argc, char *argv[]) 
{
    // Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(640, 480);
    glutCreateWindow("AntTweakBar string example");
    glutCreateMenu(NULL);

    // Set GLUT callbacks
    glutDisplayFunc(OnDisplay);
    glutReshapeFunc(OnReshape);
    atexit(OnTerminate);  // Called after glutMainLoop ends

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);

    // Set GLUT event callbacks
    // - Directly redirect GLUT mouse button events to AntTweakBar
    glutMouseFunc(OnMouseButton);
    // - Directly redirect GLUT mouse motion events to AntTweakBar
    glutMotionFunc(OnMouseMotion);
    // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
    glutPassiveMotionFunc(OnMouseMotion);
    // - Directly redirect GLUT key events to AntTweakBar
    glutKeyboardFunc(OnKeyboard);
    // - Directly redirect GLUT special key events to AntTweakBar
    glutSpecialFunc(OnSpecial);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);


    // Create a tweak bar
    TwBar *bar = TwNewBar("Main");
    TwDefine(" Main label='~ String variable examples ~' fontSize=3 position='180 16' size='270 440' valuesWidth=100 ");


    //
    // 1) C++ std::string variable example
    //

    TwAddButton(bar, "Info1.1", NULL, NULL, " label='1) This example uses' ");
    TwAddButton(bar, "Info1.2", NULL, NULL, " label='std::string variables' ");
    
    // Define the required callback function to copy a std::string (see TwCopyStdStringToClientFunc documentation)
    TwCopyStdStringToClientFunc(CopyStdStringToClient);
    
    // Adding a std::string variable
    std::string newBarTitle = "a title";
    TwAddVarRW(bar, "NewBarTitle", TW_TYPE_STDSTRING, &newBarTitle, 
               " label='Bar title' group=StdString help='Define a title for the new tweak bar.' ");
    
    // Add a button to create a new bar using the title
    TwAddButton(bar, "NewBarCreate", CreateBarCB, &newBarTitle, 
                " label='--> Create' group=StdString key=c help='Create a new tweak bar.' ");
    
    // Set the group label & separator
    TwDefine(" Main/StdString label='Create a new tweak bar' help='This example demonstates different use of std::string variables.' ");
    TwAddSeparator(bar, "Sep1", "");
    TwAddButton(bar, "Blank1", NULL, NULL, " label=' ' ");


    //
    // 2) C-Dynamic string variable example
    //

    TwAddButton(bar, "Info2.1", NULL, NULL, "label='2) This example uses' ");
    TwAddButton(bar, "Info2.2", NULL, NULL, "label='C-Dynamic string variables' ");
    
    // Define the required callback function to copy a CDString (see TwCopyCDStringToClientFunc documentation)
    TwCopyCDStringToClientFunc(CopyCDStringToClient);
    
    // Add a CDString variable
    char *someText = NULL;
    TwAddVarRW(bar, "Input", TW_TYPE_CDSTRING, &someText, 
               " label='Text input' group=CDString help=`The text to be copied to 'Text output'.` ");
    TwAddVarRO(bar, "Output", TW_TYPE_CDSTRING, &someText, 
               " label='Text output' group=CDString help=`Carbon copy of the text entered in 'Text input'.` ");
    
    // Add a line of text (we will use the label of a inactive button)
    #define TEXTLINE "a line of text"
    TwAddButton(bar, "Echo", NULL, NULL, 
                " label=`" TEXTLINE "` group=CDString help='Echo of the text entered in the next field' ");
    
    // Add a CDString variable accessed through callbacks
    char *textLine = (char *)malloc(sizeof(TEXTLINE)+1);
    strncpy(textLine, TEXTLINE, sizeof(TEXTLINE));
    TwAddVarCB(bar, "TextLine", TW_TYPE_CDSTRING, SetTextLineCB, GetTextLineCB, &textLine, 
               " label='Change text above' group=CDString help='The text to be echoed.' ");

    // Set the group label & separator
    TwDefine(" Main/CDString label='Echo some text' help='This example demonstates different use of C-Dynamic string variables.' ");
    TwAddSeparator(bar, "Sep2", "");
    TwAddButton(bar, "Blank2", NULL, NULL, " label=' ' ");


    //
    // 3) C-Static string variable example
    //

    TwAddButton(bar, "Info3.1", NULL, NULL, "label='3) This example uses' ");
    TwAddButton(bar, "Info3.2", NULL, NULL, "label='C strings of fixed size' ");

    // Add a CSString
    char tenStr[] = "0123456789"; // 10 characters + null_termination_char -> size = 11
    TwAddVarRW(bar, "Ten", TW_TYPE_CSSTRING(sizeof(tenStr)), tenStr, 
               " label='10 chars max' group=CSString help='A string with a length of 10 characters max.' ");

    // Add a CSString accessed through callbacks. The callbacks will convert the string characters to upper or lower case
    int capCase = 1; // O: lower-case, 1: upper-case
    TwAddVarCB(bar, "Capitalize", TW_TYPE_CSSTRING(sizeof(g_CapStr)), SetCapStrCB, GetCapStrCB, &capCase, 
               " group=CSString help='A string of fixed size to be converted to upper or lower case.' ");

    // Add a bool variable
    TwAddVarRW(bar, "Case", TW_TYPE_BOOL32, &capCase, 
               " false=lower true=UPPER group=CSString key=Space help=`Changes the characters case of the 'Capitalize' string.` ");

    // Set the group label & separator
    TwDefine(" Main/CSString label='Character capitalization' help='This example demonstates different use of C-Static sized variables.' ");
    TwAddSeparator(bar, "Sep3", "");


    // Call the GLUT main loop
    glutMainLoop();

    return 0;
}
Exemplo n.º 20
0
void CreateBar(){
	TwBar *bar = TwNewBar("Gestures_controller");
	TwDefine(" Gestures_controller label='Gestures controller' fontSize=3 position='16 16' size='300 230' valuesWidth=100 ");

	TwCopyStdStringToClientFunc(CopyStdStringToClient);

	TwAddVarCB(bar, "Gesture name", TW_TYPE_STDSTRING, SetMyStdStringCB, GetMyStdStringCB, NULL, "");
	
	TwAddButton(bar, "NewGestureCreate", CreateGesture, NULL, " label='--> Create <--' ");
	TwAddButton(bar, "GestureRecognize", RecognizeGesture, NULL, " label='--> Recognize <--' ");
	

	TwAddSeparator(bar, NULL, "");

	TwAddVarRO(bar, "Hands:", TW_TYPE_INT32, &g_leapListener.numHands, "group='Captured values'");
	TwAddVarRO(bar, "Extended fingers:", TW_TYPE_INT32, &g_leapListener.numFingers, "group='Captured values'");

	TwAddSeparator(bar, NULL, "");
	TwAddVarRO(bar, "Recognized gesture", TW_TYPE_STDSTRING, &g_leapListener.recognizedGesture, "");
	TwAddVarRO(bar, "F_crit", TW_TYPE_FLOAT, &g_leapListener.f_crit, "");
	TwAddVarRO(bar, "F_value", TW_TYPE_FLOAT, &g_leapListener.f_value, "");


	TwBar *trials = TwNewBar("trials");
	TwDefine("trials label='Trials Controller' fontSize=3 position='16 250' size='300 130'");

	TwAddVarRO(trials, "Active trial:", TW_TYPE_STDSTRING, &trial, "");
	TwAddVarRO(trials, "Attempt:", TW_TYPE_INT32, &g_leapListener.nRecognize, "");
	TwAddButton(trials, "trial1", Trial1, NULL, " label='--> Trial 1  <--' ");
	TwAddButton(trials, "trial2", Trial2, NULL, " label='--> Trial 2  <--' ");
	TwAddButton(trials, "trial3", Trial3, NULL, " label='--> Trial 3  <--' ");

	bar2 = TwNewBar("gestures");
	TwDefine("gestures label='Saved Gestures' fontSize=3 position='780 16' size='250 650'");
	TwAddButton(bar2, "ClearDatabase", ClearDatabase, NULL, " label='--> Clear Database <--' ");
	TwAddSeparator(bar2, NULL, "");

	for (int i = 0; i < g_gestureManager.gestures.size(); i++){
		std::string params;
		params.append("");

		if (i >= next_gesture_id){
			params.append("visible='false'");
		}

		std::string varname;
		varname.append(std::to_string(i+1));
		varname.append(" - Name:");
		TwAddVarRO(bar2, varname.c_str(), TW_TYPE_STDSTRING, &g_gestureManager.gestures[i].name, params.c_str());

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - ID:");
		TwAddVarRO(bar2, varname.c_str(), TW_TYPE_INT32, &g_gestureManager.gestures[i].id, params.c_str());

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - Hands:");
		TwAddVarRO(bar2, varname.c_str(), TW_TYPE_INT32, &g_gestureManager.gestures[i].numHands, params.c_str());

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - Fingers:");
		TwAddVarRO(bar2, varname.c_str(), TW_TYPE_INT32, &g_gestureManager.gestures[i].numFingers, params.c_str());
		
		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - sep:");
		TwAddSeparator(bar2, varname.c_str(), params.c_str());
	}

	glfwSetWindowSizeCallback(WindowSizeCB);
	glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW);
	glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW);
	glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW);
	glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW);
	glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW);
}
Exemplo n.º 21
0
	void DebugUIWidget::AddROVariable(const std::string& name, CL_BaseTypes variableType, void* variable, const char* def)
	{
		TwType type = GetType(variableType);
		TwAddVarRO(m_widget->widget, name.c_str(), type, variable, def);
	}
Exemplo n.º 22
0
int APIENTRY WinMain(HINSTANCE       hInst,
	HINSTANCE       hPrevInstance,
	LPSTR           lpCmdLine,
	int                     nCmdShow)
{
	MSG                     msg;            // Windows message structure
	WNDCLASS        wc;                     // Windows class structure
	HWND            hWnd;           // Storeage for window handle

	hInstance = hInst;

	// Register Window style
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = (WNDPROC)WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = NULL;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);

	// No need for background brush for OpenGL window
	wc.hbrBackground = NULL;

	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
	wc.lpszClassName = lpszAppName;

	// Register the window class
	if (RegisterClass(&wc) == 0)
		return FALSE;


	// Create the main application window
	hWnd = CreateWindow(
		lpszAppName,
		lpszAppName,

		// OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,

		// Window position and size
		50, 50,
		1000, 1000,
		NULL,
		NULL,
		hInstance,
		NULL);
	TwInit(TW_OPENGL, NULL);
	TwWindowSize(800,800);
	
	TwBar *bar;
	bar = TwNewBar("Moonlander");
	TwDefine(" Moonlander size='240 400' ");
	TwDefine(" Moonlander text=dark refresh=0.1 ");
	TwAddSeparator(bar, NULL, " group='Velocity' ");
	TwAddVarRO(bar, "Velocity[m/s]", TW_TYPE_FLOAT, &velocity,"precision=1");
	TwAddVarRO(bar, "Velocity X[m/s]", TW_TYPE_FLOAT, &velocityx, "precision=1");
	TwAddVarRO(bar, "Velocity Z[m/s]", TW_TYPE_FLOAT, &velocityz, "precision=1");
	TwAddSeparator(bar, NULL, " group='Engines' ");
	TwAddVarRO(bar, "Main Engine", TW_TYPE_BOOLCPP, &spisSet, "");
	TwAddVarRO(bar, "Engine 1", TW_TYPE_BOOLCPP, &w, "");
	TwAddVarRO(bar, "Engine 2", TW_TYPE_BOOLCPP, &s, "");
	TwAddVarRO(bar, "Engine 3", TW_TYPE_BOOLCPP, &a, "");
	TwAddVarRO(bar, "Engine 4", TW_TYPE_BOOLCPP, &d, "");
	TwAddVarRO(bar, "Fuel Left[kg]", TW_TYPE_FLOAT, &fuel, "precision=2");
	TwAddSeparator(bar, NULL, " group='Position' ");
	TwAddVarRO(bar, "x", TW_TYPE_FLOAT, &position.x, "precision=1");
	TwAddVarRO(bar, "y", TW_TYPE_FLOAT, &position.y, "precision=1");
	TwAddVarRO(bar, "z", TW_TYPE_FLOAT, &position.z, "precision=1");
	TwAddSeparator(bar, NULL, " group='--------------------------------' ");
	TwAddVarRO(bar, "Actual score:", TW_TYPE_INT32, &score, "");
	TwAddVarRO(bar, "Highscore:", TW_TYPE_INT32, &highscore, "");

	// If window was not created, quit
	if (hWnd == NULL)
		return FALSE;

	static HDC hDC = GetDC(hWnd);

	world->initiate();
	world->populate();

	// Display the window
	ShowWindow(hWnd, SW_SHOW);
	UpdateWindow(hWnd);


	// Process application messages until the application closes
		while (GetMessage(&msg, NULL, 0, 0))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}


	return msg.wParam;
}
Exemplo n.º 23
0
// Main
int main() 
{
    GLFWvidmode mode;   // GLFW video mode
    TwBar *bar;         // Pointer to a tweak bar
    
    double time = 0, dt;// Current time and enlapsed time
    double turn = 0;    // Model turn counter
    double speed = 0.3; // Model rotation speed
    int wire = 0;       // Draw model in wireframe?
    float bgColor[] = { 0.1f, 0.2f, 0.4f };         // Background color 
    unsigned char cubeColor[] = { 255, 0, 0, 128 }; // Model color (32bits RGBA)

    // Intialize GLFW   
    if( !glfwInit() )
    {
        // An error occured
        fprintf(stderr, "GLFW initialization failed\n");
        return 1;
    }

    // Create a window
    glfwGetDesktopMode(&mode);
    if( !glfwOpenWindow(640, 480, mode.RedBits, mode.GreenBits, mode.BlueBits, 
                        0, 16, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) )
    {
        // A fatal error occured    
        fprintf(stderr, "Cannot open GLFW window\n");
        glfwTerminate();
        return 1;
    }
    glfwEnable(GLFW_MOUSE_CURSOR);
    glfwEnable(GLFW_KEY_REPEAT);
    glfwSetWindowTitle("AntTweakBar simple example using GLFW");

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar.

    // Add 'speed' to 'bar': it is a modifable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [s] and [S].
    TwAddVarRW(bar, "speed", TW_TYPE_DOUBLE, &speed, 
               " label='Rot speed' min=0 max=2 step=0.01 keyIncr=s keyDecr=S help='Rotation speed (turns/second)' ");

    // Add 'wire' to 'bar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w].
    TwAddVarRW(bar, "wire", TW_TYPE_BOOL32, &wire, 
               " label='Wireframe mode' key=w help='Toggle wireframe display mode.' ");

    // Add 'time' to 'bar': it is a read-only (RO) variable of type TW_TYPE_DOUBLE, with 1 precision digit
    TwAddVarRO(bar, "time", TW_TYPE_DOUBLE, &time, " label='Time' precision=1 help='Time (in seconds).' ");         

    // Add 'bgColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color)
    TwAddVarRW(bar, "bgColor", TW_TYPE_COLOR3F, &bgColor, " label='Background color' ");

    // Add 'cubeColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR32 (32 bits color) with alpha
    TwAddVarRW(bar, "cubeColor", TW_TYPE_COLOR32, &cubeColor, 
               " label='Cube color' alpha help='Color and transparency of the cube.' ");

    // Set GLFW event callbacks
    // - Redirect window size changes to the callback function WindowSizeCB
    glfwSetWindowSizeCallback(WindowSizeCB);
    // - Directly redirect GLFW mouse button events to AntTweakBar
    glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW);
    // - Directly redirect GLFW mouse position events to AntTweakBar
    glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW);
    // - Directly redirect GLFW mouse wheel events to AntTweakBar
    glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW);
    // - Directly redirect GLFW key events to AntTweakBar
    glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW);
    // - Directly redirect GLFW char events to AntTweakBar
    glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW);


    // Initialize time
    time = glfwGetTime();

    // Main loop (repeated while window is not closed and [ESC] is not pressed)
    while( glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC) )
    {
        // Clear frame buffer using bgColor
        glClearColor(bgColor[0], bgColor[1], bgColor[2], 1);
        glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

        // Rotate model
        dt = glfwGetTime() - time;
        if( dt < 0 ) dt = 0;
        time += dt;
        turn += speed*dt;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotated(360.0*turn, 0.4, 1, 0.2);
        glTranslated(-0.5, -0.5, -0.5);     
    
        // Set color and draw model
        glColor4ubv(cubeColor);
        DrawModel(wire);
        
        // Draw tweak bars
        TwDraw();

        // Present frame buffer
        glfwSwapBuffers();
    }

    // Terminate AntTweakBar and GLFW
    TwTerminate();
    glfwTerminate();

    return 0;
}
Exemplo n.º 24
0
void GUI::addParameter(float &parameter, const std::string &name, const std::string &definition, bool readandwrite){
    if (readandwrite)
        TwAddVarRW(m_bar, name.c_str(), TW_TYPE_FLOAT, &parameter,definition.c_str());
    else
        TwAddVarRO(m_bar, name.c_str(), TW_TYPE_FLOAT, &parameter,definition.c_str());
}
void CDebugHelperImplementation::RegisterBar(const SDebugBar& bar)
{
	// TODO: registrar una ventana de debug
	
	int status = 0;
	std::unordered_map<std::string, TwBar*>::iterator it = m_Bars.find(bar.name);
	if (it != m_Bars.end())
	{
		status = TwDeleteBar(it->second);
		assert(status);
	}

	TwBar* twBar = TwNewBar(bar.name.c_str());

	for (int i = 0; i < bar.variables.size(); ++i)
	{
		if (bar.variables[i].type == BUTTON)
		{
			status = TwAddButton(twBar, bar.variables[i].name.c_str(), bar.variables[i].callback, bar.variables[i].data, "");
			assert(status);
		}
		else
		{
			TwType type = TW_TYPE_FLOAT;
			const char* params = "";
			switch (bar.variables[i].type)
			{
			case BOOL:
				type = TW_TYPE_BOOLCPP;
				break;
			case FLOAT:
				type = TW_TYPE_FLOAT;
				break;
			case INT:
				type = TW_TYPE_INT32;
				break;
			case COLOR32:
				type = TW_TYPE_COLOR32;
				params = " coloralpha=true colororder=argb ";
				break;
			case COLOR:
				type = TW_TYPE_COLOR4F;
				break;
			case STRING:
				type = TW_TYPE_CSSTRING(100);
				break;

			case POSITION_ORIENTATION:
				type = m_PosRotType;
				break;

			default:
				break;
			}

			switch (bar.variables[i].mode)
			{
			case READ:
				status = TwAddVarRO(twBar, bar.variables[i].name.c_str(), type, bar.variables[i].ptr, params);
				assert(status);
				break;

			case READ_WRITE:
				status = TwAddVarRW(twBar, bar.variables[i].name.c_str(), type, bar.variables[i].ptr, params);
				assert(status);
				break;

			default:
				break;
			}
		}
	}

	m_Bars[bar.name] = twBar;
	
}
Exemplo n.º 26
0
WorldClock::WorldClock(double multiplier, double t) :
	m_multiplier(multiplier), m_dt(t), m_t(t)
{
	TwAddVarRW(GLOBALS.m_overlay_bar, "Multiplier", TW_TYPE_DOUBLE, &m_multiplier, "step=1 group=WorldClock ");
	TwAddVarRO(GLOBALS.m_overlay_bar, "Time", TW_TYPE_DOUBLE, &m_t, " group=WorldClock ");
}