Example #1
0
    /*
    ==============================
    ==============================
    */
    TwLimb::TwLimb(IKALimb* l, const char* name, const ivec2& pos, const ivec2& size, const vec4& color) : bar(0), limb(0)
    {
        limb = l;

        if(limb)
        {
            limb->AddRef();
        }

        bar = TwNewBar(name);

        TwStructs* twStructs = TwStructs::GetInstance();
        ASSERT(twStructs);

        // Ball
        TwAddVarCB(bar, "BallRestRotation", twStructs->GetType(TW_STRUCT_EULER), &TwLimb::SetBallRestRotation, &TwLimb::GetBallRestRotation, 
                   reinterpret_cast<void*>(limb->ball), "group='Ball & Socket' label='Rest Rotation'");

        TwAddVarCB(bar, "BallRotation", twStructs->GetType(TW_STRUCT_EULER), &TwLimb::SetBallRotation, &TwLimb::GetBallRotation, 
                   reinterpret_cast<void*>(limb->ball), "group='Ball & Socket' label='Rotation'");

        TwAddVarCB(bar, "BallPosition", twStructs->GetType(TW_STRUCT_POSITION), &TwLimb::SetJointPosition, &TwLimb::GetJointPosition, 
                   reinterpret_cast<void*>(limb->ball), "group='Ball & Socket' label='Position'");

        // Hinge
        TwAddVarCB(bar, "HingeAxis", TW_TYPE_DIR3F, &TwLimb::SetHingeAxis, &TwLimb::GetHingeAxis, 
                   reinterpret_cast<void*>(limb->hinge), "group='Hinge' label='Axis'");

        TwAddVarCB(bar, "HingeRestAngle", TW_TYPE_FLOAT, &TwLimb::SetHingeRestAngle, &TwLimb::GetHingeRestAngle, 
                   reinterpret_cast<void*>(limb->hinge), "group='Hinge' label='Rest Angle'");

        TwAddVarCB(bar, "HingeAngle", TW_TYPE_FLOAT, &TwLimb::SetHingeAngle, &TwLimb::GetHingeAngle, 
                   reinterpret_cast<void*>(limb->hinge), "group='Hinge' label='Angle'");

        TwAddVarCB(bar, "HingePosition", twStructs->GetType(TW_STRUCT_POSITION), &TwLimb::SetJointPosition, &TwLimb::GetJointPosition, 
                   reinterpret_cast<void*>(limb->hinge), "group='Hinge' label='Position'");

        // Universal
        TwAddVarCB(bar, "UniversalAxis1", TW_TYPE_DIR3F, &TwLimb::SetUniversalAxis1, &TwLimb::GetUniversalAxis1, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Axis 1'");

        TwAddVarCB(bar, "UniversalRestAngle1", TW_TYPE_FLOAT, &TwLimb::SetUniversalRestAngle1, &TwLimb::GetUniversalRestAngle1, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Rest Angle 1'");

        TwAddVarCB(bar, "UniversalAngle1", TW_TYPE_FLOAT, &TwLimb::SetUniversalAngle1, &TwLimb::GetUniversalAngle1, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Angle 1'");

        TwAddVarCB(bar, "UniversalAxis2", TW_TYPE_DIR3F, &TwLimb::SetUniversalAxis2, &TwLimb::GetUniversalAxis2, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Axis 2'");

        TwAddVarCB(bar, "UniversalRestAngle2", TW_TYPE_FLOAT, &TwLimb::SetUniversalRestAngle2, &TwLimb::GetUniversalRestAngle2, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Rest Angle 2'");

        TwAddVarCB(bar, "UniversalAngle2", TW_TYPE_FLOAT, &TwLimb::SetUniversalAngle2, &TwLimb::GetUniversalAngle2, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Angle 2'");

        TwAddVarCB(bar, "UniversalPosition", twStructs->GetType(TW_STRUCT_POSITION), &TwLimb::SetJointPosition, &TwLimb::GetJointPosition, 
                   reinterpret_cast<void*>(limb->universal), "group='Universal' label='Position'");

        SetPos(pos);
        SetSize(size);
        SetColor(color);
    }
void TweakHydroGraphLayer::displayCurveInfo(TwBar *b, EditGraphOrthoLayer::SelectionData* curveData)
{
    TwAddVarCB(b, "Potential", TW_TYPE_FLOAT, SetCurvePotentialCallback, GetCurvePotentialCallback, curveData, " Group='CurveData' ");
    TweakGraphLayer::displayCurveInfo(b, curveData);
}
// Main
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow)
{
    // Register our window class
    WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW, MessageProc,
                        0L, 0L, instance, NULL, NULL, NULL, NULL, L"TwDX11", NULL };
    RegisterClassEx(&wcex);

    // Create a window
    RECT rc = { 0, 0, 640, 480 };
    AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
    HWND wnd = CreateWindow(L"TwDX11", L"AntTweakBar simple example using DirectX11", 
                            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 
                            rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, instance, NULL);
    if (!wnd)
    {
        MessageBox(NULL, L"Cannot create window", L"Error", MB_OK|MB_ICONERROR);
        return 0;
    }
    ShowWindow(wnd, cmdShow);
    UpdateWindow(wnd);

    // Initialize D3D11
    if (FAILED(InitDevice(wnd)))
    {
        MessageBox(wnd, L"Cannot create D3D11 device", L"Error", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }

    // Initialize the 3D scene
    if (FAILED(InitScene()))
    {
        MessageBox(wnd, L"Scene initialization failed.", L"Error", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }

    // Initialize AntTweakBar
    if (!TwInit(TW_DIRECT3D11, g_D3DDev))
    {
        MessageBoxA(wnd, TwGetLastError(), "AntTweakBar initialization failed", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }

    // Create a tweak bar
    TwBar *bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar into a DirectX11 application.' "); // Message added to the help bar.
    int barSize[2] = {224, 320};
    TwSetParam(bar, NULL, "size", TW_PARAM_INT32, 2, barSize);

    // Add variables to the tweak bar
    TwAddVarCB(bar, "Level", TW_TYPE_INT32, SetSpongeLevelCB, GetSpongeLevelCB, NULL, "min=0 max=3 group=Sponge keyincr=l keydecr=L");
    TwAddVarCB(bar, "Ambient Occlusion", TW_TYPE_BOOLCPP, SetSpongeAOCB, GetSpongeAOCB, NULL, "group=Sponge key=o");
    TwAddVarRW(bar, "Rotation", TW_TYPE_QUAT4F, &g_SpongeRotation, "opened=true axisz=-z group=Sponge");
    TwAddVarRW(bar, "Animation", TW_TYPE_BOOLCPP, &g_Animate, "group=Sponge key=a");
    TwAddVarRW(bar, "Animation speed", TW_TYPE_FLOAT, &g_AnimationSpeed, "min=-10 max=10 step=0.1 group=Sponge keyincr=+ keydecr=-");
    TwAddVarRW(bar, "Light direction", TW_TYPE_DIR3F, &g_LightDir, "opened=true axisz=-z showval=false");
    TwAddVarRW(bar, "Camera distance", TW_TYPE_FLOAT, &g_CamDistance, "min=0 max=4 step=0.01 keyincr=PGUP keydecr=PGDOWN");
    TwAddVarRW(bar, "Background", TW_TYPE_COLOR4F, &g_BackgroundColor, "colormode=hls");

    // Main message loop
    MSG msg = {0};
    while (WM_QUIT != msg.message)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            Anim();
            Render(); 
        }
    }

    TwTerminate();
    Cleanup();

    return (int)msg.wParam;
}
Example #4
0
// Setup new sub-window
void SetupSubWindow(int subWinIdx) 
{
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;
    SubWindowData *win;
    
    win = &g_SubWindowData[subWinIdx];
    win->Shape = (subWinIdx == 0) ? SHAPE_TEAPOT : SHAPE_TORUS;
	win->Zoom = 1;
	win->AutoRotate = (subWinIdx == 0);
    win->MatAmbient[0] = (subWinIdx == 1) ? 0.0f : 0.5f;; win->MatAmbient[1] = win->MatAmbient[2] = 0.2f; win->MatAmbient[3] = 1;
    win->MatDiffuse[0] = (subWinIdx == 1) ? 0.0f : 1.0f; win->MatDiffuse[1] = 1; win->MatDiffuse[2] = 0; win->MatDiffuse[3] = 1;
	win->LightMultiplier = 1;
    win->LightDirection[0] = win->LightDirection[1] = win->LightDirection[2] = -0.57735f;
    win->RotateTime = glutGet(GLUT_ELAPSED_TIME);
    SetQuaternionFromAxisAngle(axis, angle, win->Rotation);
    SetQuaternionFromAxisAngle(axis, angle, win->RotateStart);
	
	glutSetWindow(win->WinID);
    // Set GLUT callbacks
    glutDisplayFunc(DisplaySubWindow);
    glutReshapeFunc(ReshapeSubWindow);
    // Set GLUT event callbacks
    // - Register mouse button events callback
    glutMouseFunc((GLUTmousebuttonfun)MouseButtonCB);
    // - Register mouse motion events callback
    glutMotionFunc((GLUTmousemotionfun)MouseMotionCB);
    // - Register mouse "passive" motion events (same as Motion)
    glutPassiveMotionFunc((GLUTmousemotionfun)MouseMotionCB);
    // - Register keyboard events callback
    glutKeyboardFunc((GLUTkeyboardfun)KeyboardCB);
    // - Register special key events callback
    glutSpecialFunc((GLUTspecialfun)SpecialKeyCB);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Declare this window as current for AntTweakBar.
    // Here, this will create a new AntTweakBar context for this window,
    // which will be identified by the number WinID.
    TwSetCurrentWindow(win->WinID);

    // Create a tweak bar
    win->Bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to use AntTweakBar with multiple windows.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'win->Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(win->Bar, "Zoom", TW_TYPE_FLOAT, &win->Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'win->Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(win->Bar, "ObjRotation", TW_TYPE_QUAT4F, &win->Rotation, 
               " label='Object rotation' open help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(win->Bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, win, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'win->LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(win->Bar, "Multiplier", TW_TYPE_FLOAT, &win->LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'win->LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(win->Bar, "LightDir", TW_TYPE_DIR3F, &win->LightDirection, 
               " label='Light direction' open help='Change the light direction.' ");

    // Add 'win->MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(win->Bar, "Ambient", TW_TYPE_COLOR3F, &win->MatAmbient, " group='Material' ");

    // Add 'win->MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(win->Bar, "Diffuse", TW_TYPE_COLOR3F, &win->MatDiffuse, " group='Material' ");

    // Add the enum variable 'win->CurrentShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'win->CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(win->Bar, "Shape", shapeType, &win->Shape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }
}
Example #5
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();
}
void ParticleSystemDialog::setPS(int pIndex)
{
	mPSIndex = pIndex;
	if (m_dialog)
		TwDeleteBar(m_dialog);
	// Create a tweak bar
	m_dialog = TwNewBar("ParticleSystem");
	int barSize[2] = {200, 1060};
	TwDefine(" ParticleSystem position='1710 10'  ");
	TwSetParam(m_dialog, NULL, "size", TW_PARAM_INT32, 2, barSize);


	TwAddVarCB(m_dialog, "Spawn Point", TW_TYPE_DIR3F, SetSpawn, GetSpawn, (void*)this, "key=o");
	TwAddVarCB(m_dialog, "Particle Age", TW_TYPE_FLOAT, SetParticleAge, GetParticleAge, (void*)this, "key=o step=0.01 min=0.0");

	TwAddVarCB(m_dialog, "Spawn Speed", TW_TYPE_FLOAT, SetParticleSpeed, GetParticleSpeed, (void*)this, "key=o step=0.01 min=0.0");
	TwAddVarCB(m_dialog, "Spawn Direction", TW_TYPE_DIR3F, SetParticleDirection, GetParticleDirection, (void*)this, "key=o");

	TwAddVarCB(m_dialog, "Spread", TW_TYPE_FLOAT, SetSpread, GetSpread, (void*)this, "key=o step=0.01 min=0.0 max=1.0");
	TwAddVarCB(m_dialog, "Spawn Frequency", TW_TYPE_FLOAT, SetFrequency, GetFrequency, (void*)this, "key=o step=0.01 min=0.0");
	TwAddVarCB(m_dialog, "Color", TW_TYPE_COLOR4F, SetColor, GetColor, (void*)this, "key=o");

	TwAddVarCB(m_dialog, "Fade-In Stop", TW_TYPE_FLOAT, SetFadeIn, GetFadeIn, (void*)this, "key=o step=0.01");
	TwAddVarCB(m_dialog, "Fade-Out Start", TW_TYPE_FLOAT, SetFadeOut, GetFadeOut, (void*)this, "key=o step=0.01");
	TwAddVarCB(m_dialog, "Spawn Offset", TW_TYPE_FLOAT, SetSpawnOffset, GetSpawnOffset, (void*)this, "key=o step=0.01 min=0.0");
	TwAddVarCB(m_dialog, "Maximum Opacity", TW_TYPE_FLOAT, SetMaxOpacity, GetMaxOpacity, (void*)this, "key=o step=0.01 min=0.0 max=1.0");

	//Offset types
	TwAddButton(m_dialog, "On Sphere", SetOffsetOnSphere, (void*)this, " label='On Sphere' group='Offset Type'");
	TwAddButton(m_dialog, "In Sphere", SetOffsetInSphere, (void*)this, " label='In Sphere' group='Offset Type'");
	TwAddButton(m_dialog, "On Circle", SetOffsetOnCircle, (void*)this, " label='On Circle' group='Offset Type'");
	TwAddButton(m_dialog, "In Circle", SetOffsetInCircle, (void*)this, " label='In Circle' group='Offset Type'");

	//Spawn types
	TwAddButton(m_dialog, "Once", SetSpawnOnce, (void*)this, " label='Once' group='Spawn Type'");
	TwAddButton(m_dialog, "Continuously", SetSpawnContinously, (void*)this, " label='Continuously' group='Spawn Type'");

	//Spread Types
	TwAddButton(m_dialog, "In Plane", SetSpreadPlane, (void*)this, " label='In Plane' group='Spread Type'");
	TwAddButton(m_dialog, "In Space", SetSpreadSpace, (void*)this, " label='In Space' group='Spread Type'");

	//Particle Size
	TwAddVarCB(m_dialog, "Width", TW_TYPE_FLOAT, SetParticleSizeX, GetParticleSizeX, (void*)this, "key=o step=0.01 min=0.0");
	TwAddVarCB(m_dialog, "Height", TW_TYPE_FLOAT, SetParticleSizeY, GetParticleSizeY, (void*)this, "key=o step=0.01 min=0.0");

	TwAddButton(m_dialog, "Restart", Restart, (void*)this, " label='Restart'");
	TwAddButton(m_dialog, "Load Texture", LoadTexture, this, " label='Load Texture'");

	//Particles per spawn
	TwAddVarCB(m_dialog, "Particles Per Spawn", TW_TYPE_UINT32, SetParticlesPerSpawn, GetParticlesPerSpawn, (void*)this, "key=o");

	//Particle Alignment
	//TwDefine("ParticleSystem/'Billboard Alignment' opened=false ");
	TwAddButton(m_dialog, "Screen Alignment", SetScreenAlignment, (void*)this, " label='Screen Alignment' group='Billboard Alignment'");
	TwAddButton(m_dialog, "World Alignment", SetWorldAlignment, (void*)this, " label='World Alignment' group='Billboard Alignment'");
	TwAddButton(m_dialog, "Velocity Alignment", SetVelocityDirAlignment, (void*)this, " label='Velocity Alignment' group='Billboard Alignment'");
	TwAddButton(m_dialog, "Observer Alignment", SetObserverAlignment, (void*)this, " label='Observer Alignment' group='Billboard Alignment'");

	//Spawn Angular Velocity
	TwAddVarCB(m_dialog, "Spawn Angular Velocity", TW_TYPE_FLOAT, SetSpawnAngularVelocity, GetSpawnAngularVelocity, (void*)this, "key=o step=0.01");

	//Blend Modes
	TwAddButton(m_dialog, "Alpha", SetBlendAlpha, (void*)this, "group='Blend Mode'");
	TwAddButton(m_dialog, "Additive", SetBlendAdditive, (void*)this, "group='Blend Mode'");
	TwAddButton(m_dialog, "Multiply", SetBlendMultiply, (void*)this, "group='Blend Mode'");

	//Blend Modes
	TwAddButton(m_dialog, "Alpha", SetBlendAlpha, (void*)this, "group='Blend Mode'");
	TwAddButton(m_dialog, "Additive", SetBlendAdditive, (void*)this, "group='Blend Mode'");
	TwAddButton(m_dialog, "Multiply", SetBlendMultiply, (void*)this, "group='Blend Mode'");

	//Rasterizer modes
	TwAddButton(m_dialog, "No Culling", SetCullNone, (void*)this, "group='Culling'");
	TwAddButton(m_dialog, "Z-Culling", SetCullZ, (void*)this, "group='Culling'");

	//Particle space
	TwAddButton(m_dialog, "Global", SetGlobalSpace, (void*)this, "group='Particle Space'");
	TwAddButton(m_dialog, "Local Spawn", SetLocalSpawn, (void*)this, "group='Particle Space'");
	TwAddButton(m_dialog, "Local Life", SetLocalLife, (void*)this, "group='Particle Space'");
	TwAddButton(m_dialog, "Screen Space", SetScreenSpace, (void*)this, "group='Particle Space'");

	//Clone
	TwAddButton(m_dialog, "Clone", Clone, (void*)this, " label='Clone'");
	//Remove
	TwAddButton(m_dialog, "Remove", Remove, (void*)this, " label='Remove'");

	show();
}
Example #7
0
// Main
int main(int argc, char *argv[])
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutInitWindowSize( 800, 600 );
    glutCreateWindow( "Font rendering advanced tweaking" );
    glutCreateMenu( NULL );

#ifndef __APPLE__
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
        exit( EXIT_FAILURE );
    }
    fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
#endif

    glutDisplayFunc( display );
    glutReshapeFunc( reshape );
    atexit( terminate );
    TwInit( TW_OPENGL, NULL );
    glutMouseFunc( (GLUTmousebuttonfun)TwEventMouseButtonGLUT );
    glutMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT );
    glutPassiveMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT );
    glutKeyboardFunc( (GLUTkeyboardfun)TwEventKeyboardGLUT );
    glutSpecialFunc( (GLUTspecialfun)TwEventSpecialGLUT );
    TwGLUTModifiersFunc( glutGetModifiers );

    // Create a new tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine("GLOBAL "
             "help = 'This example shows how to tune all font parameters.' ");
    TwDefine("TweakBar                      "
             "size          = '280 400'     "
             "position      = '500 20'      "
             "color         = '127 127 127' "
             "alpha         = 240           "
             "label         = 'Parameters'  "
             "resizable     = True          "
             "fontresizable = True          "
             "iconifiable   = True          ");

    {
        TwEnumVal familyEV[NUM_FONTS] = {
            {VERA,      "Vera"},
            {VERA_MONO, "Vera Mono"},
            {GEORGIA,   "Georgia"},
            {TIMES,     "Times"},
            {VERDANA,   "Verdana"},
            {TAHOMA,    "Tahoma"},
            {ARIAL,     "Arial"} };
        TwType family_type = TwDefineEnum("Family", familyEV, NUM_FONTS);
        TwAddVarCB(bar, "Family", family_type, set_family, get_family, NULL, 
                   "label = 'Family'      "
                   "group = 'Font'        "
                   "help  = ' '           ");
    }
    TwAddVarCB(bar, "Size", TW_TYPE_FLOAT, set_size, get_size, NULL, 
               "label = 'Size' "
               "group = 'Font' "
               "min   = 6.0    "
               "max   = 24.0   "
               "step  = 0.05   "
               "help  = ' '    ");
    TwAddVarCB(bar, "LCD filtering", TW_TYPE_BOOL32, set_lcd_filtering, get_lcd_filtering, NULL, 
               "label = 'LCD filtering' "
              "group = 'Font'        "
               "help  = ' '             ");


    // Rendering
    TwAddVarCB(bar, "Kerning", TW_TYPE_BOOL32, set_kerning, get_kerning, NULL, 
               "label = 'Kerning'   "
               "group = 'Rendering' "
               "help  = ' '         ");
    TwAddVarCB(bar, "Hinting", TW_TYPE_BOOL32, set_hinting, get_hinting, NULL, 
               "label = 'Hinting'   "
               "group = 'Rendering' "
               "help  = ' '         ");

    // Color
    TwAddVarCB(bar, "Invert", TW_TYPE_BOOL32, set_invert, get_invert, NULL, 
               "label = 'Invert' "
               "group = 'Color'  "
               "help  = ' '      ");
    
    // Glyph
    TwAddVarCB(bar, "Width", TW_TYPE_FLOAT, set_width, get_width, NULL, 
               "label = 'Width' "
               "group = 'Glyph' "
               "min   = 0.75    "
               "max   = 1.25    " 
               "step  = 0.01    "
               "help  = ' '     ");

    TwAddVarCB(bar, "Interval", TW_TYPE_FLOAT, set_interval, get_interval, NULL, 
               "label = 'Spacing' "
               "group = 'Glyph'   "
               "min   = -0.2      "
               "max   = 0.2       "
               "step  = 0.01      "
               "help  = ' '       " );

    TwAddVarCB(bar, "Faux italic", TW_TYPE_FLOAT, set_faux_italic, get_faux_italic, NULL, 
               "label = 'Faux italic' "
               "group = 'Glyph'       "
               "min   = -30.0         "
               "max   =  30.0         "
               "step  = 0.1           "
               "help  = ' '           ");

    // Energy distribution
    TwAddVarCB(bar, "Primary", TW_TYPE_FLOAT, set_primary, get_primary, NULL,
               "label = 'Primary weight'      "
               "group = 'Energy distribution' "
               "min   = 0                     "
               "max   = 1                     "
               "step  = 0.01                  "
               "help  = ' '                   " );

    TwAddVarCB(bar, "Secondary", TW_TYPE_FLOAT, set_secondary, get_secondary, NULL,
               "label = 'Secondy weight'      "
               "group = 'Energy distribution' "
               "min   = 0                     "
               "max   = 1                     "
               "step  = 0.01                  "
               "help  = ' '                   " );

    TwAddVarCB(bar, "Tertiary", TW_TYPE_FLOAT, set_tertiary, get_tertiary, NULL,
               "label = 'Tertiary weight'      "
               "group = 'Energy distribution' "
               "min   = 0                     "
               "max   = 1                     "
               "step  = 0.01                  "
               "help  = ' '                   " );

    TwAddSeparator(bar, "",
                   "group = 'Energy distribution' " );

    TwAddVarCB(bar, "Gamma", TW_TYPE_FLOAT, set_gamma, get_gamma, NULL, 
               "label = 'Gamma correction'    "
               "group = 'Energy distribution' "
               "min   = 0.50                  "
               "max   = 2.5                   "
               "step  = 0.01                  "
               "help  = ' '                   ");

    TwAddSeparator(bar, "", "");
    TwAddButton(bar, "Reset", (TwButtonCallback) reset, NULL,
                "help='Reset all parameters to default values.'");
    TwAddSeparator(bar, "", "");
    TwAddButton(bar, "Quit", (TwButtonCallback) quit, NULL,
                "help='Quit.'");

    buffer_a = text_buffer_new( 1 ); 
    buffer_rgb = text_buffer_new( 3 ); 
    buffer = buffer_rgb;
    reset();

    glutTimerFunc( 1000.0/60.0, timer, 60 );

    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );

    glutMainLoop();
    return EXIT_SUCCESS;
}
Example #8
0
int main(void)
{
    // Create window and load extensions
    glfwSetErrorCallback(errorCallback);
    if (!glfwInit()) {
        std::exit(EXIT_FAILURE);
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(globals.width, globals.height,
        "Toon shading", NULL, NULL);
    if (!window) {
        glfwTerminate();
        std::exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glewExperimental = GL_TRUE;
    GLenum status = glewInit();
    if (status != GLEW_OK) {
        std::cerr << "Error: " << glewGetErrorString(status) << std::endl;
        std::exit(EXIT_FAILURE);
    }
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;

    glfwSetKeyCallback(window, keyCallback);
    glfwSetMouseButtonCallback(window, mouseButtonCallback);
    glfwSetCursorPosCallback(window, cursorPosCallback);
    glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
    glfwSetScrollCallback(window, scrollCallback);

    TwInit(TW_OPENGL_CORE, NULL);
    TwWindowSize(globals.width, globals.height);

    TwBar *myBar;
    myBar = TwNewBar("Toon config");

    TwAddVarCB(myBar, "X pos", TW_TYPE_FLOAT, setLightXpos, getLightXpos , &globals.lightdir_x, " step=0.5 group=Light label='x-pos' ");
    TwAddVarCB(myBar, "Y pos", TW_TYPE_FLOAT, setLightYpos, getLightYpos , &globals.lightdir_y, " step=0.5 group=Light label='y-pos' ");
    TwAddVarCB(myBar, "Z pos", TW_TYPE_FLOAT, setLightZpos, getLightZpos , &globals.lightdir_z, " step=0.01 group=Light label='z-pos' ");

    TwAddVarRW(myBar, "Ambient color", TW_TYPE_COLOR3F, &globals.ambientColor, "group=Material colormode=hls");

    TwAddVarRW(myBar, "Diffuse color", TW_TYPE_COLOR3F, &globals.diffuseColor, "group=Material colormode=hls");
    TwAddVarCB(myBar, "Diffuse intensity", TW_TYPE_FLOAT,setDifflvl, getDifflvl, &globals.material_kd, "group=Material step=0.01");

    TwAddVarRW(myBar, "Outline color", TW_TYPE_COLOR3F, &globals.outlineColor, "group=Material colormode=hls");
    TwAddVarCB(myBar, "Outline intensity", TW_TYPE_FLOAT, setOutlinelvl, getOutlinelvl , &globals.outline_intensity, " step=0.01 min=0.0 max=1.0 group=Material");

    TwAddVarCB(myBar, "Background color", TW_TYPE_COLOR3F, setBgcolorCallBack, getBgcolorCallBack, &globals.bg_color[0], "group=Misc colormode=hls");

    TwAddVarCB(myBar, "Color levels", TW_TYPE_INT8, setColorlvl, getColorlvl , &globals.colorlvl, " step=1 min=2 max=6 group=Material");


    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    // Initialize rendering
    init();

    // Start rendering loop
    while (!glfwWindowShouldClose(window)) {
        display();
        TwDraw();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();

    exit(EXIT_SUCCESS);
}
Example #9
0
void InitializeBar()
{
    ///@note Bad size errors will be thrown if this is not called before bar creation.
    TwWindowSize(g_auxWindow_w, g_auxWindow_h);

    // Create a tweak bar
    g_pTweakbar = TwNewBar("TweakBar");
    g_pShaderTweakbar = TwNewBar("ShaderTweakBar");
    g_app.m_pTweakbar = g_pTweakbar;
    g_app.m_pShaderTweakbar = g_pShaderTweakbar;

    TwDefine(" GLOBAL fontsize=3 ");
    TwDefine(" TweakBar size='300 580' ");
    TwDefine(" TweakBar position='10 10' ");
    TwDefine(" ShaderTweakBar size='300 420' ");
    TwDefine(" ShaderTweakBar position='290 170' ");

    const std::string versionStr = std::string("RiftRay version ") + pRiftRayVersion;
    const std::string varStr = " label='" + versionStr + "' ";
    TwAddButton(g_pTweakbar, "Version", NULL, NULL, varStr.c_str());

    TwAddVarCB(g_pTweakbar, "Display FPS", TW_TYPE_UINT32, NULL, GetDisplayFPS, NULL,
               " group='Performance' ");
    TwAddVarRW(g_pTweakbar, "Target FPS", TW_TYPE_INT32, &g_targetFPS,
               " min=45 max=200 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "FBO Scale", TW_TYPE_FLOAT, g_app.GetFBOScalePointer(),
               " min=0.05 max=1.0 step=0.005 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "Dynamic FBO Scale", TW_TYPE_BOOLCPP, &g_dynamicallyScaleFBO,
               "  group='Performance' ");
    TwAddVarRW(g_pTweakbar, "DynFBO Smooth", TW_TYPE_FLOAT, &g_fpsSmoothingFactor,
               " min=0.001 max=1.0 step=0.001 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "FPS Delta Threshold", TW_TYPE_FLOAT, &g_fpsDeltaThreshold,
               " min=0.0 max=100.0 step=1.0 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "Draw to Aux Window", TW_TYPE_BOOLCPP, &g_drawToAuxWindow,
               "  group='Performance' ");
    TwAddVarRW(g_pTweakbar, "CinemaScope", TW_TYPE_FLOAT, &g_app.m_cinemaScopeFactor,
               " min=0.0 max=0.95 step=0.005 group='Performance' ");

    TwAddButton(g_pTweakbar, "Disable VSync", DisableVSyncCB, NULL, " group='VSync' ");
    TwAddButton(g_pTweakbar, "Enable VSync", EnableVSyncCB, NULL, " group='VSync' ");
    TwAddButton(g_pTweakbar, "Adaptive VSync", AdaptiveVSyncCB, NULL, " group='VSync' ");


    TwAddButton(g_pTweakbar, "Recenter Pose", RecenterPoseCB, NULL, " group='Position' ");
    TwAddButton(g_pTweakbar, "Standing", StandingCB, NULL, " group='Position' ");
    TwAddButton(g_pTweakbar, "Sitting", SittingCB, NULL, " group='Position' ");
    TwAddVarRW(g_pTweakbar, "Allow Pitch", TW_TYPE_BOOLCPP, &g_allowPitch, " group='Position' ");
    TwAddVarRW(g_pTweakbar, "Allow Roll", TW_TYPE_BOOLCPP, &g_allowRoll, " group='Position' ");


    TwAddVarRW(g_pTweakbar, "Animated Thumbnails", TW_TYPE_BOOLCPP, &g_app.m_galleryScene.m_globalShadertoyState.animatedThumbnails,
               "  group='Scene' ");
    TwAddVarRW(g_pTweakbar, "Panes as Portals", TW_TYPE_BOOLCPP, &g_app.m_galleryScene.m_globalShadertoyState.panesAsPortals,
               "  group='Scene' ");
    TwAddVarRW(g_pTweakbar, "Fulldome Projection", TW_TYPE_BOOLCPP, &g_app.m_galleryScene.m_useFulldome,
               "  group='Scene' ");
    TwAddVarRW(g_pTweakbar, "Show Controls", TW_TYPE_BOOLCPP, &g_app.m_dashScene.m_pngPane.m_visible,
               "  group='Scene' ");

    TwAddButton(g_pTweakbar, "Reset Timer", ResetTimerCB, &g_app.m_galleryScene,
        " label='Reset Timer' group='Shader' ");
    TwAddVarRW(g_pTweakbar, "headSize", TW_TYPE_FLOAT, &g_app.m_headSize,
               " label='headSize' precision=4 min=0.0001 step=0.001 group='Shader' ");
#if 0
    TwAddVarRW(g_pTweakbar, "eyePos.x", TW_TYPE_FLOAT, &g_app.m_chassisPos.x,
               " label='eyePos.x' step=0.001 group='Shader' ");
    TwAddVarRW(g_pTweakbar, "eyePos.y", TW_TYPE_FLOAT, &g_app.m_chassisPos.y,
               " label='eyePos.y' step=0.001 group='Shader' ");
    TwAddVarRW(g_pTweakbar, "eyePos.z", TW_TYPE_FLOAT, &g_app.m_chassisPos.z,
               " label='eyePos.z' step=0.001 group='Shader' ");
#endif


    TwAddVarRW(g_pTweakbar, "Draw Scene", TW_TYPE_BOOLCPP, &g_app.m_floorScene.m_bDraw,
               "  group='Scene' ");
#ifdef USE_SIXENSE
    TwAddVarRW(g_pTweakbar, "Draw HydraScene", TW_TYPE_BOOLCPP, &g_app.m_hydraScene.m_bDraw,
               "  group='HydraScene' ");
    TwAddVarRW(g_pTweakbar, "Hydra Location x", TW_TYPE_FLOAT, &g_app.m_fm.m_baseOffset.x,
               " min=-10 max=10 step=0.05 group='HydraScene' ");
    TwAddVarRW(g_pTweakbar, "Hydra Location y", TW_TYPE_FLOAT, &g_app.m_fm.m_baseOffset.y,
               " min=-10 max=10 step=0.05 group='HydraScene' ");
    TwAddVarRW(g_pTweakbar, "Hydra Location z", TW_TYPE_FLOAT, &g_app.m_fm.m_baseOffset.z,
               " min=-10 max=10 step=0.05 group='HydraScene' ");
#endif

#if 0
    TwAddVarRW(g_pTweakbar, "Draw RaymarchScene", TW_TYPE_BOOLCPP, &g_app.m_raymarchScene.m_bDraw,
               "  group='RaymarchScene' ");
#endif

    int opened = 0;
    TwSetParam(g_pTweakbar, "VSync", "opened", TW_PARAM_INT32, 1, &opened);
    TwSetParam(g_pTweakbar, "Position", "opened", TW_PARAM_INT32, 1, &opened);
    TwSetParam(g_pTweakbar, "Scene", "opened", TW_PARAM_INT32, 1, &opened);
    TwSetParam(g_pTweakbar, "HydraScene", "opened", TW_PARAM_INT32, 1, &opened);
    TwSetParam(g_pTweakbar, "RaymarchScene", "opened", TW_PARAM_INT32, 1, &opened);
}
Example #10
0
bool GUI::setup(int w, int h) {
  assert(w);
  assert(h);
  win_w = w;
  win_h = h;

  TwInit(TW_OPENGL_CORE, NULL);
  bar = TwNewBar("SWNT");
  TwDefine("SWNT size='300 750'");

  // water
  TwAddVarRW(bar, "Sun Position X", TW_TYPE_FLOAT, &swnt.water.sun_pos[0], "min=-1000.0 max=1000.0 step=5.0 group='Water'");
  TwAddVarRW(bar, "Sun Position Y", TW_TYPE_FLOAT, &swnt.water.sun_pos[1], "min=-1000.0 max=1000.0 step=5.0 group='Water'");
  TwAddVarRW(bar, "Sun Position Z", TW_TYPE_FLOAT, &swnt.water.sun_pos[2], "min=-1000.0 max=1000.0 step=5.0 group='Water'");
  TwAddVarRW(bar, "Sun Color Red", TW_TYPE_FLOAT, &swnt.water.sun_color[0], "min=-5.0 max=5.0 step=0.1 group='Water'");
  TwAddVarRW(bar, "Sun Color Green", TW_TYPE_FLOAT, &swnt.water.sun_color[1], "min=-5.0 max=5.0 step=0.1 group='Water'");
  TwAddVarRW(bar, "Sun Color Blue", TW_TYPE_FLOAT, &swnt.water.sun_color[2], "min=-5.0 max=5.0 step=0.1 group='Water'");
  TwAddVarRW(bar, "Sun Shininess", TW_TYPE_FLOAT, &swnt.water.sun_shininess, "min=0.0 max=50.0 step=0.1 group='Water'");
  TwAddVarRW(bar, "Maximum Foam Depth", TW_TYPE_FLOAT, &swnt.water.foam_depth, "min=0.0 max=50.0 step=0.1 group='Water'");
  TwAddVarRW(bar, "Maximum Water Depth", TW_TYPE_FLOAT, &swnt.water.max_depth, "min=0.0 max=50.0 step=0.01 group='Water'");
  //  TwAddVarRW(bar, "Diffuse Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[1], "min=-10.0 max=10.0 step=0.01 group='Water'");
  //  TwAddVarRW(bar, "Specular Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[2], "min=-10.0 max=10.0 step=0.01 group='Water'");
  TwAddVarRW(bar, "Final Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[6], "min=0.0 max=2.0 step=0.01 group='Water'");
  TwAddVarRW(bar, "Sun Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[3], "min=-10.0 max=10.0 step=0.01 group='Water'");
  TwAddVarRW(bar, "Foam Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[4], "min=-10.0 max=10.0 step=0.01 group='Water'");
  TwAddVarRW(bar, "Diffuse Texture Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[5], "min=-10.0 max=10.0 step=0.01 group='Water'");
  TwAddVarRW(bar, "Ambient Intensity", TW_TYPE_FLOAT, &swnt.water.ads_intensities[0], "min=-10.0 max=10.0 step=0.01 group='Water'");
  TwAddVarRW(bar, "Ambient Color", TW_TYPE_COLOR3F, &swnt.water.ambient_color, "group='Water'");
  TwAddVarRW(bar, "Vortex Amount", TW_TYPE_FLOAT, &swnt.water.vortex_intensity, "group='Water' min=0.0 max=5.0 step=0.01");
  TwDefine("SWNT/Water opened=false");

  // splashes
#if USE_EFFECTS  
  Splashes& sp = swnt.effects.splashes;
  TwAddVarRW(bar, "Minimum Lifetime", TW_TYPE_FLOAT, &sp.lifetime_min, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Maximum Lifetime", TW_TYPE_FLOAT, &sp.lifetime_max, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Minimum Width", TW_TYPE_FLOAT, &sp.size_x_min, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Maximum Width", TW_TYPE_FLOAT, &sp.size_x_max, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Minimum Height", TW_TYPE_FLOAT, &sp.size_y_min, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Maximum Height", TW_TYPE_FLOAT, &sp.size_y_max, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Minimum Rotation Speed", TW_TYPE_FLOAT, &sp.rotate_speed_min, "min=-10.0 max=10.0 step=0.2 group='Splashes'");
  TwAddVarRW(bar, "Maximum Rotation Speed", TW_TYPE_FLOAT, &sp.rotate_speed_max, "min=-10.0 max=10.0 step=0.2 group='Splashes'");
  TwAddVarRW(bar, "Minimum Move Speed", TW_TYPE_FLOAT, &sp.move_speed_min, "min=0.0 max=150.0 step=0.2 group='Splashes'");
  TwAddVarRW(bar, "Maximum Move Speed", TW_TYPE_FLOAT, &sp.move_speed_max, "min=0.0 max=150.0 step=0.2 group='Splashes'");
  TwAddVarRW(bar, "Minimum Splash Size", TW_TYPE_FLOAT, &sp.size_min, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Maximum Splash Size", TW_TYPE_FLOAT, &sp.size_max, "min=0.0 max=300.0 step=1.0 group='Splashes'");
  TwAddVarRW(bar, "Animation Speed Of Texture", TW_TYPE_FLOAT, &sp.texture_anim_speed, "min=0.0 max=2.0 step=0.01 group='Splashes'");
  TwDefine("SWNT/Splashes opened=false");
#endif

  // rendering
  TwAddVarRW(bar, "Draw Flow Field", TW_TYPE_BOOLCPP, &swnt.draw_flow, "group='Rendering'");
  TwAddVarRW(bar, "Draw Water", TW_TYPE_BOOLCPP, &swnt.draw_water, "group='Rendering'");
  //TwAddVarRW(bar, "Draw Debug Eddy", TW_TYPE_BOOLCPP, &swnt.draw_vortex, "group='Rendering'");
  TwAddVarRW(bar, "Draw Tracking (Blobs, Points, Contours) ", TW_TYPE_BOOLCPP, &swnt.draw_tracking, "group='Rendering'");
  TwAddVarRW(bar, "Draw Triangulated Blobs", TW_TYPE_BOOLCPP, &swnt.tracking.draw_triangulated_blobs, "group='Rendering'");
  TwAddVarRW(bar, "Draw Points of Tracked Blobs", TW_TYPE_BOOLCPP, &swnt.tracking.draw_tracking_points, "group='Rendering'");
  TwAddVarRW(bar, "Draw Blob Contours", TW_TYPE_BOOLCPP, &swnt.tracking.draw_contours, "group='Rendering'");
  TwDefine("SWNT/Rendering opened=false");

  // general
  TwAddVarRW(bar, "Override Values With GUI", TW_TYPE_BOOLCPP, &swnt.override_with_gui, "group='Colors And Time'");
  TwAddVarCB(bar, "Time Of Day", TW_TYPE_FLOAT, set_time_of_day, get_time_of_day, this, "group='Colors And Time' min=0.25 max=0.75 step=0.001");
  TwAddVarCB(bar, "Time Of Year", TW_TYPE_FLOAT, set_time_of_year, get_time_of_year, this, "group='Colors And Time' min=0.0 max=1.0 step=0.01");

  // colors
  if(swnt.settings.colors.size() == 4) {
    TwAddVarRW(bar, "Hand Winter", TW_TYPE_COLOR3F, swnt.settings.colors[0].hand.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Hand Spring", TW_TYPE_COLOR3F, swnt.settings.colors[1].hand.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Hand Summer", TW_TYPE_COLOR3F, swnt.settings.colors[2].hand.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Hand Autumn", TW_TYPE_COLOR3F, swnt.settings.colors[3].hand.ptr(), "group='Colors And Time'");

    TwAddVarRW(bar, "Spiral Winter", TW_TYPE_COLOR3F, swnt.settings.colors[0].spiral_from.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Spiral Spring", TW_TYPE_COLOR3F, swnt.settings.colors[1].spiral_from.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Spiral Summer", TW_TYPE_COLOR3F, swnt.settings.colors[2].spiral_from.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Spiral Autumn", TW_TYPE_COLOR3F, swnt.settings.colors[3].spiral_from.ptr(), "group='Colors And Time'");

    TwAddVarRW(bar, "Water Winter", TW_TYPE_COLOR3F, swnt.settings.colors[0].water.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Water Spring", TW_TYPE_COLOR3F, swnt.settings.colors[1].water.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Water Summer", TW_TYPE_COLOR3F, swnt.settings.colors[2].water.ptr(), "group='Colors And Time'");
    TwAddVarRW(bar, "Water Autumn", TW_TYPE_COLOR3F, swnt.settings.colors[3].water.ptr(), "group='Colors And Time'");
  }

  TwDefine("SWNT/'Colors And Time' opened=false");

  // kinect
  TwAddVarRW(bar, "Kinect Far", TW_TYPE_FLOAT, &swnt.settings.kinect_far, "group='Kinect' min=0.00 max=5.00 step=0.01");
  TwAddVarRW(bar, "Kinect Near", TW_TYPE_FLOAT, &swnt.settings.kinect_near, "group='Kinect' min=0.00 max=5.00 step=0.01");
  TwDefine("SWNT/Kinect opened=false");

#if USE_SPIRALS
  Spirals& spirals = swnt.spirals;
  TwAddVarRW(bar, "Min Particle Lifetime", TW_TYPE_FLOAT, &spirals.min_lifetime, "min=0.0 max=300.0 step=1.0 group='Spirals'");
  TwAddVarRW(bar, "Max Particle Lifetime", TW_TYPE_FLOAT, &spirals.max_lifetime, "min=0.0 max=300.0 step=1.0 group='Spirals'");
  TwAddVarRW(bar, "Min Particle Mass", TW_TYPE_FLOAT, &spirals.min_mass, "min=0.0 max=15.0 step=0.001 group='Spirals'");
  TwAddVarRW(bar, "Max Particle Mass", TW_TYPE_FLOAT, &spirals.max_mass, "min=0.0 max=15.0 step=0.001 group='Spirals'");
  TwAddVarRW(bar, "Force Towards Center", TW_TYPE_FLOAT, &spirals.center_force, "min=0.0 max=400.0 step=0.1 group='Spirals'");
  TwAddVarRW(bar, "Velocity Field Force", TW_TYPE_FLOAT, &spirals.field_force, "min=0.0 max=5.0 step=0.01 group='Spirals'");
  TwAddVarRW(bar, "Min Width", TW_TYPE_FLOAT, &spirals.min_strip_width, "min=0.0 max=50.0 step=0.1 group='Spirals'");
  TwAddVarRW(bar, "Max Width", TW_TYPE_FLOAT, &spirals.max_strip_width, "min=0.0 max=50.0 step=0.1 group='Spirals'");
  TwAddVarRW(bar, "Min Tail Size", TW_TYPE_UINT32, &spirals.min_tail_size, "min=2 max=100 step=1 group='Spirals'");
  TwAddVarRW(bar, "Max Tail Size", TW_TYPE_UINT32, &spirals.max_tail_size, "min=2 max=100 step=1 group='Spirals'");
  TwAddVarRW(bar, "Number of Particles To Spawn", TW_TYPE_UINT32, &spirals.spawn_per_tracked, "min=1 max=200 step=1 group='Spirals'");
  TwDefine("SWNT/Spirals opened=false");
#endif

  TwAddVarRW(bar, "Hand Scale", TW_TYPE_FLOAT, &swnt.tracking.blob_scale, "min=1.0 max=3.0 step=0.01");
  TwAddVarRW(bar, "Hand Offset", TW_TYPE_FLOAT, &swnt.tracking.blob_offset, "min=-300.0 max=300.0 step=0.5");

  TwWindowSize(win_w, win_h);
  return true;
}
Example #11
0
void CreateMenus (void)
{
	{
		TwBar *bar = TwNewBar ("pentachoron");
		TwDefine ("pentachoron label='Pentachoron'");

		TwType rendermodeType;
		TwEnumVal rendermodeEV[] = {
			{ 0, "compose" },
			{ 1, "color" },
			{ 2, "normal" },
			{ 3, "specular" },
			{ 4, "depth" },
			{ 5, "glow" },
			{ 6, "shadow" }
		};
		rendermodeType = TwDefineEnum ("rendermode", rendermodeEV, 7);

		TwAddVarCB (bar, "FPS", TW_TYPE_UINT32,
								NULL, [&] (void *v, void*) {
									*(unsigned int*)v = fps;
								}, NULL, NULL);
		TwAddVarCB (bar, "rendermode", rendermodeType,
								[&] (const void *v, void*) {
									r->postprocess.SetRenderMode (*(unsigned int*)v);
								}, [&] (void *v, void*) {
									*(unsigned int*)v = r->postprocess.GetRenderMode ();
								}, NULL, NULL);
		TwAddVarCB (bar, "tile-based light culling", TW_TYPE_BOOLCPP,
								[&] (const void *v, void*) {
									r->composition.SetTileBased (*(bool*)v);
								}, [&] (void *v, void*){
									*(bool*)v = r->composition.GetTileBased ();
								}, NULL, NULL);
		TwAddVarCB (bar, "wireframe", TW_TYPE_BOOLCPP,
								[&] (const void *v, void*) {
									r->gbuffer.SetWireframe (*(bool*)v);
								}, [&] (void *v, void*) {
									*(bool*)v = r->gbuffer.GetWireframe ();
								}, NULL, NULL);
		TwAddVarCB (bar, "tesslevel", TW_TYPE_UINT32,
								[&] (const void *v, void*) {
									r->geometry.SetTessLevel (*(uint32_t*)v);
								}, [&] (void *v, void*) {
									*(uint32_t*)v = r->geometry.GetTessLevel ();
								}, NULL, "label='tessellation level' min=1 max=64");
		TwAddVarCB (bar, "displacement", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->geometry.SetDisplacement (*(float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->geometry.GetDisplacement ();
								}, NULL, "label='displacement' min=0 step=0.01");
	}
	{
		TwBar *bar = TwNewBar ("lights");
		TwDefine ("lights label='Lights' iconified=true");

		TwAddButton (bar, "add light", [&] (void*) {
				AddLight ();
			}, NULL, NULL);
		TwAddButton (bar, "remove", [&] (void*) {
				RemoveLight ();
			}, NULL, "label='remove light' visible=false");

		TwAddVarRW (bar, "active", TW_TYPE_UINT32,
								&active_light, "label='active light' visible=false"); 
		TwAddSeparator (bar, NULL, NULL);

		TwStructMember lightposDesc[] = {
			{ "x", TW_TYPE_FLOAT, offsetof (glm::vec4, x), "step=0.1" },
			{ "y", TW_TYPE_FLOAT, offsetof (glm::vec4, y), "step=0.1" },
			{ "z", TW_TYPE_FLOAT, offsetof (glm::vec4, z), "step=0.1" }
		};
		TwStructMember attenuationDesc[] = {
			{ "constant", TW_TYPE_FLOAT, offsetof (glm::vec4, x), "step=0.01" },
			{ "linear", TW_TYPE_FLOAT, offsetof (glm::vec4, y), "step=0.01" },
			{ "quadratic", TW_TYPE_FLOAT, offsetof (glm::vec4, z), "step=0.01" },
			{ "cull distance", TW_TYPE_FLOAT, offsetof (glm::vec4, w), "step=0.1" }
		};
		typedef struct spotparam {
			 float angle;
			 float penumbra_angle;
			 float exponent;
		} spotparam_t;
		TwStructMember spotDesc[] = {
			{ "angle", TW_TYPE_FLOAT,
				offsetof (spotparam_t, angle), "step=1 min=0 max=360" },
			{ "penumbra angle", TW_TYPE_FLOAT,
				offsetof (spotparam_t, penumbra_angle), "step=1 min=0 max=360" },
			{ "exponent", TW_TYPE_FLOAT,
				offsetof (spotparam_t, exponent), "step=0.1" }
		};
		
		TwType lightposType = TwDefineStruct ("lightpos", lightposDesc, 3,
																					sizeof (glm::vec4),
																					NULL, NULL);
		TwType spotdescType = TwDefineStruct ("spotdesc", spotDesc, 3,
																					sizeof (spotparam_t),
																					NULL, NULL);
		TwType attenuationType = TwDefineStruct ("attenuation", attenuationDesc, 4,
																						 sizeof (glm::vec4),
																						 NULL, NULL);
		TwAddVarCB (bar, "position", lightposType,
								[&] (const void *v, void*) {
									r->GetLight (active_light).position
										 = *(glm::vec4*)v;
									r->UpdateLight (active_light);
								}, [&] (void *v, void*) {
									*(glm::vec4*)v = r->GetLight (active_light).position;
								}, NULL, "visible=false");
		TwAddVarCB (bar, "direction", TW_TYPE_DIR3F,
								[&] (const void *v, void*) {
									r->GetLight (active_light).direction
										 = glm::vec4 (*(const glm::vec3*)v, 0.0f);
									r->UpdateLight (active_light);
								}, [&] (void *v, void*) {
									*(glm::vec3*)v
										 = glm::vec3 (r->GetLight (active_light).direction);
								}, NULL, "visible=false");
		TwAddVarCB (bar, "color", TW_TYPE_COLOR3F,
								[&] (const void *v, void*) {
									r->GetLight (active_light).color
										 = glm::vec4 (*(const glm::vec3*)v, 1.0f);
									r->UpdateLight (active_light);
								}, [&] (void *v, void*) {
									*(glm::vec3*)v
										 = glm::vec3 (r->GetLight (active_light).color);
								}, NULL, "visible=false");
		TwAddVarCB (bar, "spot", spotdescType,
								[&] (const void *v, void*) {
									Light &light = r->GetLight (active_light);
									light.spot.exponent = ((spotparam_t*)v)->exponent;
									light.spot.angle = (((spotparam_t*)v)->angle)
										 * PCH_PI / 180.0f;
									light.spot.cosine = cosf (light.spot.angle);
									light.spot.tangent = tanf (light.spot.angle);
									light.spot.penumbra_angle
										 = ((spotparam_t*)v)->penumbra_angle * PCH_PI / 180.0f;
									light.spot.penumbra_cosine
										 = cosf (light.spot.penumbra_angle);
									r->UpdateLight (active_light);
								}, [&] (void *v, void*){
									const Light &light = r->GetLight (active_light);
									((spotparam_t*)v)->exponent = light.spot.exponent;
									((spotparam_t*)v)->angle = light.spot.angle
										 * 180.0f / PCH_PI;
									((spotparam_t*)v)->penumbra_angle
										 = light.spot.penumbra_angle * 180.0f / PCH_PI;
								}, NULL, "visible=false");
		TwAddVarCB (bar, "attenuation", attenuationType,
								[&] (const void *v, void*) {
									r->GetLight (active_light).attenuation
										 = *(glm::vec4*)v;
									r->GetLight (active_light).attenuation.z /= 100.0f;
									r->UpdateLight (active_light);
								}, [&] (void *v, void*) {
									*(glm::vec4*)v = r->GetLight (active_light).attenuation;
									((glm::vec4*)v)->z *= 100.0f;
								}, NULL, "visible=false");
		TwAddVarCB (bar, "specular", TW_TYPE_COLOR3F,
								[&] (const void *v, void*) {
									r->GetLight (active_light).specular.color
										 = *(const glm::vec3*)v;
									r->UpdateLight (active_light);
								}, [&] (void *v, void*) {
									*(glm::vec3*)v
										 = r->GetLight (active_light).specular.color;
								}, NULL, "label='specular color' visible=false");
	}
	{
		TwBar *bar = TwNewBar ("sky");
		TwDefine ("sky label='Sky' iconified=true");

		typedef struct perezcoefficients {
			 union {
					struct {
						 float A, B, C, D, E;
					};
					float p[5];
			 };
		} perezcoefficients_t;
		TwStructMember perezDesc[] = {
			{ "Darkening/Brightening to the horizon",
				TW_TYPE_FLOAT, offsetof (perezcoefficients_t, A),
				"step=0.01" },
			{ "Luminance gradient near the horizon",
				TW_TYPE_FLOAT, offsetof (perezcoefficients_t, B),
				"step=0.01" },
			{ "Relative intensity of circumsolar region",
				TW_TYPE_FLOAT, offsetof (perezcoefficients_t, C),
				"step=0.01" },
			{ "Width of the circumsolar region",
				TW_TYPE_FLOAT, offsetof (perezcoefficients_t, D),
				"step=0.01" },
			{ "Relative backscatered light at the earth surface",
				TW_TYPE_FLOAT, offsetof (perezcoefficients_t, E),
				"step=0.01" }

		};
		TwType perezType = TwDefineStruct ("perez", perezDesc, 5,
																			 sizeof (perezcoefficients_t),
																			 NULL, NULL);

		TwAddVarCB (bar, "turbidity", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.SetTurbidity (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetTurbidity ();
								}, NULL, "step=0.1 min=1.0 max=10.0");
		TwAddVarCB (bar, "time", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.SetTimeOfDay (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetTimeOfDay ();
								}, NULL, "step=0.01 min=0.0 max=24.0");
		TwType monthType;
		TwEnumVal monthEV[] = {
			{  0, "January" },
			{  1, "February" },
			{  2, "March" },
			{  3, "April" },
			{  4, "May" },
			{  5, "June" },
			{  6, "July" },
			{  7, "August" },
			{  8, "September" },
			{  9, "October" },
			{ 10, "November" },
			{ 11, "December" }
		};
		monthType = TwDefineEnum ("month", monthEV, 12);
		TwAddVarCB (bar, "month", monthType,
								[&] (const void *v, void*) {
									int month, day;
									ToCalendarDate (r->composition.GetDate (), &month, &day);
									month = *(const unsigned int*)v;
									r->composition.SetDate (ToOrdinalDate (month, day));
								}, [&] (void *v, void*) {
									int month, day;
									ToCalendarDate (r->composition.GetDate (), &month, &day);
									*(unsigned int*)v = month;
								}, NULL, NULL);
		TwAddVarCB (bar, "day", TW_TYPE_UINT8,
								[&] (const void *v, void*) {
									int month, day;
									ToCalendarDate (r->composition.GetDate (), &month, &day);
									day = *(const unsigned char*)v;
									r->composition.SetDate (ToOrdinalDate (month, day));
								}, [&] (void *v, void*) {
									int month, day;
									ToCalendarDate (r->composition.GetDate (), &month, &day);
									*(unsigned char*)v = day;
								}, NULL, "min=1 max=31");
		TwAddVarCB (bar, "luminosity", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.SetSkyLuminosity (0.01f * *(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetSkyLuminosity () * 100.0f;
								}, NULL, "step=0.01");
		TwAddVarCB (bar, "latitude", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.SetLatitude (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetLatitude ();
								}, NULL, "step=0.1 min=0.0 max=90.0");
		TwAddVarCB (bar, "Y", perezType,
								[&] (const void *v, void*) {
									for (auto i = 0; i < 5; i++)
										 r->composition.SetPerezY
												(i, ((perezcoefficients_t*)v)->p[i]);
								}, [&] (void *v, void *) {
									for (auto i = 0; i < 5; i++)
										 ((perezcoefficients_t*)v)->p[i]
												= r->composition.GetPerezY (i);
								}, NULL, "label='Coefficients Y'");
		TwAddVarCB (bar, "x", perezType,
								[&] (const void *v, void*) {
									for (auto i = 0; i < 5; i++)
										 r->composition.SetPerezx
												(i, ((perezcoefficients_t*)v)->p[i]);
								}, [&] (void *v, void *) {
									for (auto i = 0; i < 5; i++)
										 ((perezcoefficients_t*)v)->p[i]
												= r->composition.GetPerezx (i);
								}, NULL, "label='Coefficients x'");
		TwAddVarCB (bar, "y", perezType,
								[&] (const void *v, void*) {
									for (auto i = 0; i < 5; i++)
										 r->composition.SetPerezy
												(i, ((perezcoefficients_t*)v)->p[i]);
								}, [&] (void *v, void *) {
									for (auto i = 0; i < 5; i++)
										 ((perezcoefficients_t*)v)->p[i]
												= r->composition.GetPerezy (i);
								}, NULL, "label='Coefficients y'");
	}
	{
		TwBar *bar = TwNewBar ("tonemapping");
		TwDefine ("tonemapping label='Tonemapping' iconified=true");

		TwEnumVal tonemappingmodeEV[] = {
			{  0, "Default" },
			{  1, "Reinhard" },
			{  2, "Logarithmic" },
			{  3, "URQ" },
			{  4, "Exponential" },
			{  5, "Drago" },
		};
		TwType tonemappingmodeType;
		tonemappingmodeType = TwDefineEnum ("tonemappingmode",
																				tonemappingmodeEV, 6);
		TwAddVarCB (bar, "Mode", tonemappingmodeType,
								[&] (const void *v, void*) {
									r->postprocess.SetTonemappingMode (*(const unsigned int*)v);
								}, [&] (void *v, void*) {
									*(unsigned int*)v
										 = r->postprocess.GetTonemappingMode ();
								}, NULL, NULL);
		TwAddVarCB (bar, "Image Key", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->postprocess.SetImageKey (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v
										 = r->postprocess.GetImageKey ();
								}, NULL, "step=0.001 min=0.001 max=5.0");
		TwAddVarCB (bar, "White threshold", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->postprocess.SetWhiteThreshold (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->postprocess.GetWhiteThreshold ();
								}, NULL, "step=0.01 min=0.0 max=5.0");
		TwAddVarCB (bar, "Sigma", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->postprocess.SetTonemappingSigma (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->postprocess.GetTonemappingSigma ();
								}, NULL, "step=0.01 min=0.0 max=5.0");
		TwAddVarCB (bar, "Exponent", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->postprocess.SetTonemappingExponent (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->postprocess.GetTonemappingExponent ();
								}, NULL, "step=0.01 min=0.0");

		TwStructMember avglumDesc[] = {
			{ "constant", TW_TYPE_FLOAT, offsetof (glm::vec4, x), "step=0.01" },
			{ "linear", TW_TYPE_FLOAT, offsetof (glm::vec4, y), "step=0.01" },
			{ "delta", TW_TYPE_FLOAT, offsetof (glm::vec4, z), "step=0.01" },
			{ "lod", TW_TYPE_FLOAT, offsetof (glm::vec4, w), "step=0.1" }
		};
		TwType avglumType = TwDefineStruct ("avglum", avglumDesc, 4,
																				sizeof (glm::vec4),
																				NULL, NULL);
		TwAddVarCB (bar, "avgLum", avglumType,
								[&] (const void *v, void*) {
									r->postprocess.SetAvgLumConst (((const glm::vec4*)v)->x);
									r->postprocess.SetAvgLumLinear (((const glm::vec4*)v)->y);
									r->postprocess.SetAvgLumDelta (((const glm::vec4*)v)->z);
									r->postprocess.SetAvgLumLod (((const glm::vec4*)v)->w);
								}, [&] (void *v, void*) {
									((glm::vec4*)v)->x = r->postprocess.GetAvgLumConst ();
									((glm::vec4*)v)->y = r->postprocess.GetAvgLumLinear ();
									((glm::vec4*)v)->z = r->postprocess.GetAvgLumDelta ();
									((glm::vec4*)v)->w = r->postprocess.GetAvgLumLod ();
								}, NULL, "label='Average Luminance'");
		TwEnumVal rgbworkingspaceEV[] = {
			{ 0, "Adobe RGB (1998)" },
			{  1, "AppleRGB" },
			{  2, "Best RGB" },
			{  3, "Beta RGB" },
			{  4, "Bruce RGB" },
			{  5, "CIE RGB" },
			{  6, "ColorMatch RGB" },
			{  7, "Don RGB 4" },
			{  8, "ECI RGB" },
			{  9, "Ekta Space PS5" },
			{ 10, "NTSC RGB" },
			{ 11, "PAL/SECAM RGB" },
			{ 12, "ProPhoto RGB" },
			{ 13, "SMPTE-C RGB" },
			{ 14, "sRGB" },
			{ 15, "Wide Gamut RGB" }
		};
		TwType rgbworkingspaceType;
		rgbworkingspaceType = TwDefineEnum ("rgbworkingspace",
																				rgbworkingspaceEV, 16);
		TwAddVarCB (bar, "RGB Working Space", rgbworkingspaceType,
								[&] (const void *v, void*) {
									r->postprocess.SetRGBWorkingSpace (*(const unsigned int*)v);
								}, [&] (void *v, void*) {
									*(unsigned int*)v
										 = r->postprocess.GetRGBWorkingSpace ();
								}, NULL, NULL);
	}
	{
		TwBar *bar = TwNewBar ("antialiasing");
		TwDefine ("antialiasing label='Antialiasing' iconified=true");
		TwEnumVal samplesEV[] = {
			{  0, "disabled" },
			{  4, "4x" },
			{  8, "8x" },
			{  12, "12x" },
			{  16, "16x" },
		};
		TwType samplesType;
		samplesType = TwDefineEnum ("samples",
																samplesEV, 5);
		TwAddVarCB (bar, "Mode", samplesType,
								[&] (const void *v, void*) {
									r->SetAntialiasing (*(const unsigned int*)v);
								}, [&] (void *v, void*) {
									*(unsigned int*)v
										 = r->GetAntialiasing ();
								}, NULL, NULL);
		TwAddVarCB (bar, "Threshold", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->postprocess.SetAntialiasingThreshold
										 (0.01f * *(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v
										 = 100.0f * r->postprocess.GetAntialiasingThreshold ();
								}, NULL, "step=0.1 min=0.0");
	}
	{
		TwBar *bar = TwNewBar ("glow");
		TwDefine ("glow label='Glow' iconified=true");

		TwAddVarCB (bar, "blur size", TW_TYPE_UINT32,
								[&] (const void *v, void*) {
									r->composition.GetGlow ().SetSize (*(const unsigned int*)v);
								}, [&] (void *v, void*) {
									*(unsigned int*)v = r->composition.GetGlow ().GetSize ();
								}, NULL, "min=0 max=256");
		TwAddVarCB (bar, "luminance threshold", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.SetLuminanceThreshold (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetLuminanceThreshold ();
								}, NULL, "step=0.01 min=0");
// TODO: NOT YET REIMPLEMENTED!
		TwAddVarCB (bar, "limit", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.GetGlow ().SetLimit (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetGlow ().GetLimit ();
								}, NULL, "step=0.01 min=0 visible=false");
		TwAddVarCB (bar, "exponent", TW_TYPE_FLOAT,
								[&] (const void *v, void*) {
									r->composition.GetGlow ().SetExponent (*(const float*)v);
								}, [&] (void *v, void*) {
									*(float*)v = r->composition.GetGlow ().GetExponent ();
								}, NULL, "step=0.01 min=0 visible=false");
	}
	{
		TwBar *bar = TwNewBar ("parameter");
		TwDefine ("parameter label='Material Parameters' iconified=true");

		{
			std::vector<TwEnumVal> paramNames;
			for (auto i = 0; i < r->GetNumParameters (); i++)
			{
				paramNames.push_back (TwEnumVal ());
				paramNames.back ().Value = i;
				paramNames.back ().Label = r->GetParameterName (i).c_str ();
			}
			TwType paramnameType;
			paramnameType = TwDefineEnum ("paramname", &paramNames[0],
																		paramNames.size ());
			TwAddVarRW (bar, "active", paramnameType,
									&active_light, "label='active parameter set'"); 
		}
		TwAddSeparator (bar, NULL, NULL);

		TwEnumVal specmodelEV[] = {
			{ 0, "None" },
			{  1, "Gaussian" },
			{  2, "Phong" },
			{  3, "Beckmann" }
		};
		TwType specmodelType;
		specmodelType = TwDefineEnum ("specmodel",
																	specmodelEV, 4);

		typedef struct matspec {
			 unsigned int model;
			 float param1;
			 float param2;
			 float fresnel_n;
			 float fresnel_k;
		} matspec_t;
		TwStructMember matspecDesc[] = {
			{ "Specular Model",
				specmodelType, offsetof (matspec_t, model), NULL},
			{ "Smoothness/Shininess",
				TW_TYPE_FLOAT, offsetof (matspec_t, param1),
				"step=0.01" },
			{ "Gauss Factor/Ignored",
				TW_TYPE_FLOAT, offsetof (matspec_t, param2),
				"step=0.01" },
			{ "Fresnel n",
				TW_TYPE_FLOAT, offsetof (matspec_t, fresnel_n),
				"step=0.01" },
			{ "Fresnel k",
				TW_TYPE_FLOAT, offsetof (matspec_t, fresnel_k),
				"step=0.01" }

		};
		TwType matspecType = TwDefineStruct ("matspectype", matspecDesc, 5,
																				 sizeof (matspec_t),
																				 NULL, NULL);
		TwAddVarCB (bar, "matspec", matspecType,
								[&] (const void *v, void*) {
									Parameter &p = r->GetParameters (active_parameter);
									const matspec_t *m = (const matspec_t*) v;
									p.specular.model = m->model;
									p.specular.param1 = m->param1;
									p.specular.param2 = m->param2;
									p.specular.fresnel.n = m->fresnel_n;
									p.specular.fresnel.k = m->fresnel_k;
									r->UpdateParameters (active_parameter);
								}, [&] (void *v, void*) {
									Parameter &p = r->GetParameters (active_parameter);
									matspec_t *m = (matspec_t*) v;
									m->model = p.specular.model;
									m->param1 = p.specular.param1;
									m->param2 = p.specular.param2;
									m->fresnel_n = p.specular.fresnel.n;
									m->fresnel_k = p.specular.fresnel.k;
								}, NULL, "label='Specular Parameters'");

		typedef struct matrefl {
			 float factor;
			 float fresnel_n;
			 float fresnel_k;
		} matrefl_t;
		TwStructMember matreflDesc[] = {
			{ "Factor",
				TW_TYPE_FLOAT, offsetof (matrefl_t, factor),
				"step=0.01 min=0.0 max=1.0" },
			{ "Fresnel n",
				TW_TYPE_FLOAT, offsetof (matrefl_t, fresnel_n),
				"step=0.01" },
			{ "Fresnel k",
				TW_TYPE_FLOAT, offsetof (matrefl_t, fresnel_k),
				"step=0.01" }

		};
		TwType matreflType = TwDefineStruct ("matrefltype", matreflDesc, 3,
																				 sizeof (matrefl_t),
																				 NULL, NULL);
		TwAddVarCB (bar, "matrefl", matreflType,
								[&] (const void *v, void*) {
									Parameter &p = r->GetParameters (active_parameter);
									const matrefl_t *m = (const matrefl_t*) v;
									p.reflection.factor = m->factor;
									p.reflection.fresnel.n = m->fresnel_n;
									p.reflection.fresnel.k = m->fresnel_k;
									r->UpdateParameters (active_parameter);
								}, [&] (void *v, void*) {
									Parameter &p = r->GetParameters (active_parameter);
									matrefl_t *m = (matrefl_t*) v;
									m->factor = p.reflection.factor;
									m->fresnel_n = p.reflection.fresnel.n;
									m->fresnel_k = p.reflection.fresnel.k;
								}, NULL, "label='Reflection'");
	}
}
Example #12
0
void TweakRivers::updateBar(TwBar *bar)
{
    if (drawer == NULL) {
        return;
    }
    LifeCycleParticleLayer *lifeLayer = drawer->getParticles()->getLayer<LifeCycleParticleLayer>();
    WorldParticleLayer *worldLayer = drawer->getParticles()->getLayer<WorldParticleLayer>();

    TwAddVarCB(bar, "pauseFlow", TW_TYPE_BOOL8, SetPausedCallback, GetPausedCallback, worldLayer, " group=Flow label='Update Particles' help='Activate/Deactivate the flow' false='True' true='False' ");
    TwAddVarCB(bar, "timeStep", TW_TYPE_FLOAT, SetTimeStepCallback, GetTimeStepCallback, drawer.get(), " group=Flow label='Time Step' help='Number of Time Steps between each frame' step=0.01 ");
    TwAddVarCB(bar, "flowSpeed", TW_TYPE_FLOAT, SetFlowSpeedCallback, GetFlowSpeedCallback, worldLayer, " group=Flow label='Flow Speed' help='Flow Speed' step=0.01 ");
    TwAddButton(bar, "Clear", ClearParticlesCallback, drawer->getParticles()->getStorage().get(), "group='Flow'");

    TwType twMeshDisplayType = TwDefineEnum("MeshDisplayType", NULL, 0);
    TwAddVarCB(bar, "displayMesh", twMeshDisplayType, SetMeshDisplayTypeCallback, GetMeshDisplayTypeCallback, drawer.get(), "group=Display label='Display Mode' enum='0 {Hidden}, 1 {Particle Coverage}, 5 {Advected}, 6 {Pre-Advected}, 10 {Non Advected} ' ");
    TwAddVarCB(bar, "displayGrid", TW_TYPE_BOOL8, SetDisplayGridCallback, GetDisplayGridCallback, drawer.get(), "group=Display label='Display Grid' ");
    TwAddVarCB(bar, "displayParticles", TW_TYPE_BOOL8, SetDisplayParticlesCallback, GetdisplayParticlesCallback, drawer.get(), "group=Display label='Display Particles' ");
    TwAddVarCB(bar, "displayVelocities", TW_TYPE_BOOL8, SetDisplayVelocitiesCallback, GetDisplayVelocitiesCallback, drawer.get(), "group=Display label='Display Velocities' ");
    TwAddVarCB(bar, "displaySun", TW_TYPE_BOOL8, SetDisplaySunEffectsCallback, GetDisplaySunEffectsCallback, drawer.get(), "group=Display label='Display Sun Effects' ");
    TwAddVarCB(bar, "waveSlope", TW_TYPE_FLOAT, SetWaveSlopeCallback, GetWaveSlopeCallback, drawer.get(), "group=Display label='Wave slope factor' ");
    TwAddVarCB(bar, "waveLength", TW_TYPE_FLOAT, SetWaveLengthCallback, GetWaveLengthCallback, drawer.get(), "group=Display label='Wave length factor' ");
    TwAddVarCB(bar, "riverDepth", TW_TYPE_FLOAT, SetRiverDepthCallback, GetRiverDepthCallback, drawer.get(), "group=Display label='River Depth' min='1' step='0.1' ");
    TwAddVarCB(bar, "bedLength", TW_TYPE_FLOAT, SetBedLengthCallback, GetBedLengthCallback, drawer.get(), "group=Display label='Bed texture length' min='0.001' step='0.001'");

    TwAddVarCB(bar, "fadeInTime", TW_TYPE_FLOAT, SetFadeInCallback, GetFadeInCallback, lifeLayer, "group=Other label='Fading in Time' step=0.1 ");
    TwAddVarCB(bar, "fadeOutTime", TW_TYPE_FLOAT, SetFadeOutCallback, GetFadeOutCallback, lifeLayer, "group=Other label='Fading Out Time' step=0.1 ");
    TwAddVarCB(bar, "maxAge", TW_TYPE_FLOAT, SetMaxAgeCallback, GetMaxAgeCallback, lifeLayer, "group=Other label='Max Particle Age' step=0.1 ");
    TwAddVarCB(bar, "particleSize", TW_TYPE_FLOAT, SetRadiusCallback, GetRadiusCallback, drawer.get(), "group=Other label='Particle Size' min=0.020 step=0.1 ");
//    TwAddVarCB(bar, "maxParticles", TW_TYPE_INT32, SetMaxPCallback, GetMaxPCallback, drawer.get()->particles, "group=Other label='Max Particles' min=0 ");
    TwAddVarCB(bar, "slipParameter", TW_TYPE_FLOAT, SetSlipCallback, GetSlipCallback, drawer.get(), "group=Other label='Slip Parameter' step='0.05' ");
    TwAddVarCB(bar, "potentialDelta", TW_TYPE_FLOAT, SetPotentialDeltaCallback, GetPotentialDeltaCallback, drawer.get(), "group=Other label='Potential Delta' min=0.01 step='0.01' ");

    // Defining groups
    TwSetParam(bar, "Flow", "readonly", TW_PARAM_CSTRING, 1, "false");
    TwSetParam(bar, "Flow", "opened", TW_PARAM_INT32, 1, &(barStates[0]));
    TwSetParam(bar, "Flow", "group", TW_PARAM_CSTRING, 1, "riverManager");

    TwSetParam(bar, "Display", "readonly", TW_PARAM_CSTRING, 1, "false");
    TwSetParam(bar, "Display", "opened", TW_PARAM_INT32, 1, &(barStates[1]));
    TwSetParam(bar, "Display", "group", TW_PARAM_CSTRING, 1, "riverManager");

    TwSetParam(bar, "Other", "readonly", TW_PARAM_CSTRING, 1, "false");
    TwSetParam(bar, "Other", "opened", TW_PARAM_INT32, 1, &(barStates[2]));
    TwSetParam(bar, "Other", "group", TW_PARAM_CSTRING, 1, "riverManager");

    TwSetParam(bar, "riverManager", "readonly", TW_PARAM_CSTRING, 1, "false");
    TwSetParam(bar, "riverManager", "opened", TW_PARAM_INT32, 1, &(barStates[3]));
    TwSetParam(bar, "riverManager", "label", TW_PARAM_CSTRING, 1, getName());

    currentBar = bar;
}
Example #13
0
// Main
int main(int argc, char *argv[])
{
    TwBar *bar; // Pointer to the tweak bar
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutCreateWindow("AntTweakBar simple example using GLUT");
    glutCreateMenu(NULL);

    // Set GLUT callbacks
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    atexit(Terminate);  // Called after glutMainLoop ends

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);

    // Set GLUT event callbacks
    // - Directly redirect GLUT mouse button events to AntTweakBar
    glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
    // - Directly redirect GLUT mouse motion events to AntTweakBar
    glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
    glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT key events to AntTweakBar
    glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
    // - Directly redirect GLUT special key events to AntTweakBar
    glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Create a tweak bar
    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 400' color='96 216 224' "); // change default tweak bar size and color

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

    // Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, 
               " label='Object rotation' opened=true help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, 
               " label='Light direction' opened=true help='Change the light direction.' ");

    // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");

    // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");

    // Add the enum variable 'g_CurrentShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }

    // Store time
    g_RotateTime = GetTimeMs();
    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

    // Call the GLUT main loop
    glutMainLoop();

    return 0;
}