Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions example/testApp.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
Example for ofxTwBar.
Bridge to AntTweakBar - "a light and intuitive graphical user interface"
Bridge to AntTweakBar - "a light and intuitive graphical user interface"
<http://www.antisphere.com/Wiki/tools:anttweakbar>

A simple example using AntTweakBar with OpenGL and GLUT .
Example from <http://www.antisphere.com/Wiki/tools:anttweakbar:examples#twsimpleglut>
*/
Expand All @@ -27,11 +27,11 @@ ofVec3f g_LightDirection;

//--------------------------------------------------------------
void testApp::setup(){

g_Rotation = ofQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
g_RotateStart = ofQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
g_LightDirection.set(-0.57735f, -0.57735f, -0.57735f);

// Create some 3D objects (stored in display lists)
glNewList(SHAPE_TEAPOT, GL_COMPILE);
glutSolidTeapot(1.0);
Expand All @@ -42,21 +42,21 @@ void testApp::setup(){
glNewList(SHAPE_CONE, GL_COMPILE);
glutSolidCone(1.0, 1.5, 64, 4);
glEndList();


float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
float angle = 0.8f;

// Init rotation
SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

//TWEAK BAR
bar.init("TweakBar", 200, 400, 200, 200, 200, 100);
bar.enable();

bar.addParam("Zoom", &g_Zoom, " min=0.01 max=500.0 step=1.0 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ", false);
bar.addParam("ObjRotation", &g_Rotation, " label='Object rotation' open help='Change the object orientation.' ", false);
bar.addParam("ObjRotation", &g_Rotation, " label='Object rotation' open help='Change the object orientation.' ", false);
bar.addParam("Multiplier", &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ", false);
bar.addParam("LightDir", &g_LightDirection, " label='Light direction' open help='Change the light direction.' ", false);
bar.addSeparator("separator");
Expand All @@ -72,15 +72,15 @@ void testApp::update(){
void testApp::draw(){
float v[4]; // will be used to set light paramters
float mat[4*4]; // rotation matrix

// Clear frame buffer
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);

// Set light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
Expand All @@ -90,11 +90,11 @@ void testApp::draw(){
glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
v[0] = -g_LightDirection.x; v[1] = -g_LightDirection.y; v[2] = -g_LightDirection.z; v[3] = 0.0f;
glLightfv(GL_LIGHT0, GL_POSITION, v);

// Set material
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse);

// Rotate and draw shape
glPushMatrix();
//glTranslatef(0.5f, -0.3f, 0.0f);
Expand All @@ -104,7 +104,7 @@ void testApp::draw(){
glScalef(g_Zoom, g_Zoom, g_Zoom);
glCallList(g_CurrentShape);
glPopMatrix();

//TWEAK BAR
bar.draw();
}
Expand All @@ -120,7 +120,7 @@ void testApp::SetQuaternionFromAxisAngle(const float *axis, float angle, ofQuate
quat._v[1] = sina2 * axis[1] / norm;
quat._v[2] = sina2 * axis[2] / norm;
quat._v[3] = (float)cos(0.5f * angle);

}


Expand Down
4 changes: 2 additions & 2 deletions example/testApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class testApp : public ofBaseApp{
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);

ofxTwBar bar;

void SetQuaternionFromAxisAngle(const float *axis, float angle, ofQuaternion quat);
void ConvertQuaternionToMatrix(const ofQuaternion quat, float *mat);
void MultiplyQuaternions(const ofQuaternion q1, const ofQuaternion q2, ofQuaternion qout);
Expand Down
10 changes: 5 additions & 5 deletions libs/AntTweakBar/include/AntTweakBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// @file AntTweakBar.h
//
// @brief AntTweakBar is a light and intuitive graphical user interface
// that can be readily integrated into OpenGL and DirectX
// @brief AntTweakBar is a light and intuitive graphical user interface
// that can be readily integrated into OpenGL and DirectX
// applications in order to interactively tweak them.
//
// @author Philippe Decaudin - http://www.antisphere.com
Expand Down Expand Up @@ -241,7 +241,7 @@ TW_API int TW_CALL TwKeyPressed(int key, int modifiers);
typedef enum ETwMouseAction
{
TW_MOUSE_RELEASED,
TW_MOUSE_PRESSED
TW_MOUSE_PRESSED
} TwMouseAction;
typedef enum ETwMouseButtonID
{
Expand Down Expand Up @@ -275,7 +275,7 @@ TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W6

// For libSDL event loop
TW_API int TW_CALL TwEventSDL(const void *sdlEvent);

// For GLFW event callbacks
TW_API int TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction);
TW_API int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction);
Expand All @@ -299,7 +299,7 @@ typedef void (TW_GLUT_CALL *GLUTmousemotionfun)(int mouseX, int mouseY);
typedef void (TW_GLUT_CALL *GLUTkeyboardfun)(unsigned char glutKey, int mouseX, int mouseY);
typedef void (TW_GLUT_CALL *GLUTspecialfun)(int glutKey, int mouseX, int mouseY);


// ----------------------------------------------------------------------------
// Make sure the types have the right sizes
// ----------------------------------------------------------------------------
Expand Down
30 changes: 15 additions & 15 deletions src/ofxTwBar.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
Copyright (c) 2010, Hugues Bruyère - <http://www.smallfly.com>
All rights reserved.

Bridge to AntTweakBar - "a light and intuitive graphical user interface" - <http://www.antisphere.com/Wiki/tools:anttweakbar>

Based on code from Cinder Lib.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Expand Down Expand Up @@ -45,13 +45,13 @@ void ofxTwBar::init( const std::string &title, const int w, const int h, const i
cout << "AntTweakBar initialization failed: " << TwGetLastError() << endl;
}
mBar = TwNewBar(title.c_str());//, TwDeleteBar);

char optionsStr[1024];
sprintf( optionsStr, "%s size='%i %i' color='%i %i %i' alpha=%i", title.c_str(), w, h, r, g, b, a);
TwDefine( optionsStr );

TwGLUTModifiersFunc(glutGetModifiers);

mouseLocked = false;
}

Expand All @@ -74,7 +74,7 @@ void ofxTwBar::enable(bool enableMousePressed) {
// ofAddListener(ofEvents.update, this, &ofxTwBar::update);
// ofAddListener(ofEvents.draw, this, &ofxTwBar::draw);
ofAddListener(ofEvents.windowResized, this, &ofxTwBar::resize);

ofAddListener(ofEvents.keyPressed, this, &ofxTwBar::keyPressed);
ofAddListener(ofEvents.mouseDragged, this, &ofxTwBar::mouseDragged);
ofAddListener(ofEvents.mouseMoved, this, &ofxTwBar::mouseMoved);
Expand All @@ -88,7 +88,7 @@ void ofxTwBar::disable() {
// ofRemoveListener(ofEvents.update, this, &ofxTwBar::update);
// ofRemoveListener(ofEvents.draw, this, &ofxTwBar::draw);
ofRemoveListener(ofEvents.windowResized, this, &ofxTwBar::resize);

ofRemoveListener(ofEvents.keyPressed, this, &ofxTwBar::keyPressed);
ofRemoveListener(ofEvents.mouseDragged, this, &ofxTwBar::mouseDragged);
ofRemoveListener(ofEvents.mouseMoved, this, &ofxTwBar::mouseMoved);
Expand All @@ -107,23 +107,23 @@ void ofxTwBar::implAddParam( const std::string &name, void *param, int type, con
//--------------------------------------------------------------
void ofxTwBar::addParam( const std::string &name, bool *param, const std::string &optionsStr, bool readOnly ) {
implAddParam( name, param, TW_TYPE_BOOLCPP, optionsStr, readOnly );
}
}

//--------------------------------------------------------------
void ofxTwBar::addParam( const std::string &name, float *param, const std::string &optionsStr, bool readOnly, int type ) {
implAddParam( name, param, type, optionsStr, readOnly );
}
}

//--------------------------------------------------------------
void ofxTwBar::addParam( const std::string &name, int *param, const std::string &optionsStr, bool readOnly )
{
implAddParam( name, param, TW_TYPE_INT32, optionsStr, readOnly );
}
}

//--------------------------------------------------------------
void ofxTwBar::addParam( const std::string &name, ofVec3f *param, const std::string &optionsStr, bool readOnly ) {
implAddParam( name, param, TW_TYPE_DIR3F, optionsStr, readOnly );
}
}
//
//--------------------------------------------------------------
void ofxTwBar::addParam( const std::string &name, ofQuaternion *param, const std::string &optionsStr, bool readOnly ) {
Expand Down Expand Up @@ -162,12 +162,12 @@ void ofxTwBar::keyPressed(ofKeyEventArgs & args){
cout << "SHIFT pressed.";
kmod |= TW_KMOD_SHIFT;
}

if( ofKeyControl() ) {
cout << "CONTROL pressed.";
kmod |= TW_KMOD_CTRL;
}

if( args.key == 9 ) {
cout << "ALT pressed.";
kmod |= TW_KMOD_ALT;
Expand Down
40 changes: 20 additions & 20 deletions src/ofxTwBar.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
Copyright (c) 2010, Hugues Bruyère - <http://www.smallfly.com>
All rights reserved.

Bridge to AntTweakBar - "a light and intuitive graphical user interface" - <http://www.antisphere.com/Wiki/tools:anttweakbar>

Based on code from Cinder Lib.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Expand All @@ -32,29 +32,29 @@
#include "AntTweakBar.h"
#include <string>
#include <GLUT/GLUT.h>

class ofxTwBar {
public:
ofxTwBar();
~ofxTwBar();

bool mouseLocked;

void init( const std::string &title, const int w, const int h, const int r, const int g, const int b, const int a );
void update();
void resize(ofResizeEventArgs & args);
void draw();

void enable(bool enableMousePressed = true);
void disable();

void keyPressed(ofKeyEventArgs & args);
void mouseMoved(ofMouseEventArgs & args);
void mouseDragged(ofMouseEventArgs & args);
void mousePressed(ofMouseEventArgs & args);
void mousePressed(int x, int y, int button);
void mouseReleased(ofMouseEventArgs & args);

void addParam( const std::string &name, bool *boolParam, const std::string &optionsStr = "", bool readOnly = false );
void addParam( const std::string &name, float *quatParam, const std::string &optionsStr = "", bool readOnly = false, int type = TW_TYPE_FLOAT );
void addParam( const std::string &name, int *intParam, const std::string &optionsStr = "", bool readOnly = false );
Expand All @@ -63,21 +63,21 @@ class ofxTwBar {
void addParam( const std::string &name, std::string *strParam, const std::string &optionsStr = "", bool readOnly = false );
void addSeparator( const std::string &name = "", const std::string &optionsStr = "" );
void addButton( const std::string &name = "", const std::string &optionsStr = "" );

void removeParam(const std::string &name);

void addGroupToGroup(const std::string &optionsStr = "");



protected:
void implAddParam( const std::string &name, void *param, int type, const string &optionsStr, bool readOnly );
void implAddParam( const std::string &name, void *param, int type, const string &optionsStr, bool readOnly );

TwBar *mBar;
int mouseX, mouseY;
bool ofKeyAlt();
bool ofKeyShift();
bool ofKeyControl();

};