├── src ├── MSACoreGL.h ├── MSACoreCommon.h ├── MSACore.h ├── MSACoreGL.cpp ├── MSACore-Cinder.h ├── MSACoreMath.h └── MSACore-OF.h ├── addon_config.mk ├── README.md ├── .gitignore └── license.md /src/MSACoreGL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace msa { 4 | 5 | void drawQuadAtCorner(); 6 | void drawQuadAtCenter(); 7 | 8 | void drawTexture(GLuint texId, GLenum textureTarget = GL_TEXTURE_2D); 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/MSACoreCommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MSACoreMath.h" 4 | #include "MSACoreGL.h" 5 | 6 | namespace msa { 7 | #define DelPointer(p) if(p) { delete p; p = NULL; } 8 | #define DelArray(p) if(p) { delete []p; p = NULL; } 9 | } 10 | 11 | namespace MSA = msa; // for backwards compatibility 12 | 13 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | meta: 2 | ADDON_NAME = ofxMSACore 3 | ADDON_DESCRIPTION = Core wrappers for ofxMSA addons 4 | ADDON_AUTHOR = Memo Akten, www.memo.tv 5 | ADDON_TAGS = "" 6 | ADDON_URL = https://github.com/memo/ofxMSACore 7 | 8 | common: 9 | # dependencies with other addons, a list of them separated by spaces 10 | # or use += in several lines 11 | ADDON_DEPENDENCIES = 12 | -------------------------------------------------------------------------------- /src/MSACore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // uncomment only ONE of the below #defines 4 | // better to do this via project settings, but AFAIK neither openFrameworks or Cinder have a global #define 5 | 6 | #define MSA_HOST_OPENFRAMEWORKS 7 | //#define MSA_HOST_CINDER 8 | 9 | 10 | //--------------------- 11 | 12 | #if defined( MSA_HOST_OPENFRAMEWORKS ) 13 | #include "MSACore-OF.h" 14 | 15 | #elif defined( MSA_HOST_CINDER ) 16 | #include "MSACore-Cinder.h" 17 | 18 | #else 19 | This will give an error. you need to make sure a host is #defined either above, or in project settings 20 | #endif 21 | 22 | #include "MSACoreCommon.h" 23 | 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ofxMSACore 2 | ===================================== 3 | 4 | Introduction 5 | ------------ 6 | A very lightweight C++ wrapper which maps basic types to allow tight integration with [openFrameworks](www.openframeworks.cc) and [Cinder](www.libcinder.org) - or potentially any other C++ frameworks. Used by most of my other ofxMSAxxx addons. 7 | 8 | Licence 9 | ------- 10 | The code in this repository is available under the [MIT License](https://secure.wikimedia.org/wikipedia/en/wiki/Mit_license). 11 | Copyright (c) 2008-2012 Memo Akten, [www.memo.tv](http://www.memo.tv) 12 | The Mega Super Awesome Visuals Company 13 | 14 | 15 | Installation 16 | ------------ 17 | Copy to your openFrameworks/addons folder. 18 | 19 | Dependencies 20 | ------------ 21 | none 22 | 23 | Compatibility 24 | ------------ 25 | openFrameworks 0072 26 | I am generally testing only with [openFrameworks](www.openframeworks.cc), however it should work with [Cinder](www.libcinder.org) too. If it doesn't, please file an issue. 27 | 28 | 29 | 30 | 31 | 32 | Known issues 33 | ------------ 34 | none 35 | 36 | Version history 37 | ------------ 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/MSACoreGL.cpp: -------------------------------------------------------------------------------- 1 | #include "MSACore.h" 2 | 3 | namespace msa { 4 | 5 | static GLfloat tex_coords[] = { 6 | 0, 0, 7 | 1, 0, 8 | 1, 1, 9 | 0, 1 10 | }; 11 | 12 | static GLfloat verts[] = { 13 | -0.5f, -0.5f, 14 | 0.5f, -0.5f, 15 | 0.5f, 0.5f, 16 | -0.5f, 0.5f 17 | }; 18 | 19 | 20 | void drawQuadAtCorner() { 21 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 22 | glTexCoordPointer(2, GL_FLOAT, 0, tex_coords ); 23 | glEnableClientState(GL_VERTEX_ARRAY); 24 | glVertexPointer(2, GL_FLOAT, 0, verts ); 25 | glDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); 26 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 27 | } 28 | 29 | void drawQuadAtCenter() { 30 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 31 | glTexCoordPointer(2, GL_FLOAT, 0, tex_coords ); 32 | glEnableClientState(GL_VERTEX_ARRAY); 33 | glVertexPointer(2, GL_FLOAT, 0, verts ); 34 | glDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); 35 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 36 | } 37 | 38 | 39 | void drawTexture(GLuint texId, GLenum textureTarget ) { 40 | glEnable(textureTarget); 41 | glBindTexture(textureTarget, texId); 42 | drawQuadAtCenter(); 43 | glDisable(textureTarget); 44 | } 45 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Some general ignore patterns 2 | 3 | */bin/* 4 | !*/bin/data/ 5 | # for bin folder in root 6 | /bin/* 7 | !/bin/data/ 8 | 9 | build/ 10 | obj/ 11 | *.o 12 | Debug*/ 13 | Release*/ 14 | *.mode* 15 | *.app/ 16 | *.pyc 17 | .svn/ 18 | 19 | # IDE-specific ignore patterns (e.g. user-specific files) 20 | 21 | #XCode 22 | *.pbxuser 23 | *.perspective 24 | *.perspectivev3 25 | *.mode1v3 26 | *.mode2v3 27 | #XCode 4 28 | xcuserdata 29 | *.xcworkspace 30 | 31 | #Code::Blocks 32 | *.depend 33 | *.layout 34 | *.cbTemp 35 | 36 | #Visual Studio 37 | *.sdf 38 | *.opensdf 39 | *.suo 40 | ipch/ 41 | 42 | #Eclipse 43 | .metadata 44 | local.properties 45 | .externalToolBuilders 46 | 47 | # OS-specific ignore patterns 48 | 49 | #Linux 50 | *~ 51 | # KDE 52 | .directory 53 | 54 | #OSX 55 | .DS_Store 56 | *.swp 57 | *~.nib 58 | # Thumbnails 59 | ._* 60 | 61 | #Windows 62 | # Windows image file caches 63 | Thumbs.db 64 | # Folder config file 65 | Desktop.ini 66 | 67 | #Android 68 | .csettings 69 | 70 | # Packages 71 | # it's better to unpack these files and commit the raw source 72 | # git has its own built in compression methods 73 | *.7z 74 | *.dmg 75 | *.gz 76 | *.iso 77 | *.jar 78 | *.rar 79 | *.tar 80 | *.zip 81 | 82 | # Logs and databases 83 | *.log 84 | *.sql 85 | *.sqlite 86 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The code in this repository is available under the [MIT License](https://secure.wikimedia.org/wikipedia/en/wiki/Mit_license). 2 | 3 | Copyright (c) 2008-2012 Memo Akten, [www.memo.tv](http://www.memo.tv) 4 | The Mega Super Awesome Visuals Company 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/MSACore-Cinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#define msa cinder // so cinder namespaces are also accessible within MSA 4 | 5 | 6 | #include "cinder/Cinder.h" 7 | #include "cinder/gl/gl.h" 8 | #include "cinder/Rand.h" 9 | #include "cinder/Vector.h" 10 | #include "cinder/Color.h" 11 | #include "cinder/app/AppBasic.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | namespace msa { 20 | 21 | #define MSA_HOST_SUFFIX "-Cinder" 22 | 23 | //todo: 24 | #if defined (CINDER_MAC) 25 | #define MSA_TARGET_OSX 26 | 27 | #elif defined (CINDER_LINUX) 28 | #define MSA_TARGET_LINUX 29 | 30 | #elif defined (CINDER_MSW) 31 | #define MSA_TARGET_WIN32 32 | 33 | #elif defined (CINDER_COCOA_TOUCH) 34 | #define MSA_TARGET_IPHONE 35 | #endif 36 | 37 | #if defined (CINDER_GLES) 38 | #define MSA_TARGET_OPENGLES 39 | #endif 40 | 41 | typedef ci::Vec2f Vec2f; 42 | typedef ci::Vec3f Vec3f; 43 | typedef ci::Vec4f Vec4f; 44 | typedef ci::ColorA Color; 45 | 46 | 47 | inline string dataPath(string path, bool absolute = false) { return "todo"; } 48 | 49 | inline double getElapsedSeconds() { return ci::app::getElapsedSeconds(); } 50 | inline long int getElapsedFrames() { return ci::app::getElapsedFrames(); } 51 | 52 | inline int getWindowWidth() { return ci::app::getWindowWidth(); } 53 | inline int getWindowHeight() { return ci::app::getWindowHeight(); } 54 | inline float getWindowAspectRatio() { return ci::app::getWindowAspectRatio(); } 55 | inline Vec2f getWindowSize() { return ci::app::getWindowSize(); } 56 | inline Vec2f getWindowCenter() { return ci::app::getWindowCenter(); } 57 | 58 | inline void drawString(string s, float x, float y) { return; /* todo */ } 59 | 60 | inline float clamp(float a, float min, float max) { 61 | return ci::constrain(a, min, max); 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /src/MSACoreMath.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace msa { 4 | #ifndef PI 5 | #define PI 3.14159265358979323846 6 | #endif 7 | 8 | #ifndef TWO_PI 9 | #define TWO_PI 6.28318530717958647693 10 | #endif 11 | 12 | #ifndef M_TWO_PI 13 | #define M_TWO_PI 6.28318530717958647693 14 | #endif 15 | 16 | #ifndef FOUR_PI 17 | #define FOUR_PI 12.56637061435917295385 18 | #endif 19 | 20 | #ifndef HALF_PI 21 | #define HALF_PI 1.57079632679489661923 22 | #endif 23 | 24 | #ifndef DEG_TO_RAD 25 | #define DEG_TO_RAD (PI/180.0) 26 | #endif 27 | 28 | #ifndef RAD_TO_DEG 29 | #define RAD_TO_DEG (180.0/PI) 30 | #endif 31 | 32 | // returns always positive modulo 33 | inline int mod(int dividend, int divisor) { 34 | dividend %= divisor; 35 | if(dividend<0) dividend += divisor; 36 | return dividend; 37 | } 38 | 39 | 40 | inline float fastInvSquareRoot(float x) { 41 | float xhalf = 0.5f*x; 42 | int i = *(int*)&x; 43 | i = 0x5f3759df - (i>>1); 44 | x = *(float*)&i; 45 | x = x*(1.5f - xhalf*x*x); 46 | return x; 47 | } 48 | 49 | // inline void fastNormalize(Vec3f &p) { 50 | // float f = fastInvSquareRoot(p.lengthSquared()); 51 | // p *= f; 52 | // } 53 | 54 | 55 | template void SWAP( T& a, T& b) { T tmp = b; b = a; a = tmp; } 56 | 57 | template 58 | float mapRange(T value, T inputMin, T inputMax, T outputMin, T outputMax, bool clamp = false) { 59 | T outVal = ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); 60 | 61 | if(clamp){ 62 | if(outputMax < outputMin){ 63 | if( outVal < outputMax )outVal = outputMax; 64 | else if( outVal > outputMin )outVal = outputMin; 65 | }else{ 66 | if( outVal > outputMax )outVal = outputMax; 67 | else if( outVal < outputMin )outVal = outputMin; 68 | } 69 | } 70 | return outVal; 71 | } 72 | 73 | template 74 | void bounce(T &pos, T &vel, T min, T max, float bounceFactor = 1) { 75 | if(pos < min) { 76 | pos = min; 77 | vel = fabs(vel) * bounceFactor; 78 | } else if(pos > max) { 79 | pos = max; 80 | vel = -fabs(vel) * bounceFactor; 81 | } 82 | } 83 | 84 | template 85 | bool inRange(T a, T min, T max) { 86 | return (a >= min) && (a <= max); 87 | } 88 | 89 | 90 | 91 | } -------------------------------------------------------------------------------- /src/MSACore-OF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | //#include "cinder-lite/CinderMath.h" 6 | //#include "cinder-lite/Color.h" 7 | //#include "cinder-lite/Vector.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | //windows 14 | #ifndef M_PI 15 | # define M_PI 3.14159265358979323846 16 | #endif 17 | 18 | using namespace std; 19 | 20 | namespace msa { 21 | 22 | #define MSA_HOST_SUFFIX "-OF" 23 | 24 | #if defined (TARGET_OSX) 25 | #define MSA_TARGET_OSX 26 | 27 | #elif defined (TARGET_LINUX) 28 | #define MSA_TARGET_LINUX 29 | 30 | #elif defined (TARGET_WIN32) 31 | #define MSA_TARGET_WIN32 32 | 33 | #elif defined (TARGET_IPHONE) 34 | #define MSA_TARGET_IPHONE) 35 | #endif 36 | 37 | #if defined (TARGET_OPENGLES) 38 | #define MSA_TARGET_OPENGLES 39 | #endif 40 | 41 | typedef ofVec2f Vec2f; 42 | typedef ofVec3f Vec3f; 43 | typedef ofVec4f Vec4f; 44 | typedef ofFloatColor Color; 45 | 46 | inline string dataPath(string path, bool absolute = false) { return ofToDataPath(path, absolute); } 47 | 48 | inline double getElapsedSeconds() { return ofGetElapsedTimef(); } 49 | inline long int getElapsedFrames() { return ofGetFrameNum(); } 50 | 51 | inline int getWindowWidth() { return ofGetWidth(); } 52 | inline int getWindowHeight() { return ofGetHeight(); } 53 | inline float getWindowAspectRatio() { return getWindowWidth() * 1.0f / getWindowHeight(); } 54 | inline Vec2f getWindowSize() { return ofGetWindowSize(); } 55 | inline Vec2f getWindowCenter() { return Vec2f(getWindowWidth() * 0.5f, getWindowHeight() * 0.5f ); } 56 | 57 | inline void drawString(string s, float x, float y) { ofDrawBitmapString(s, x, y); } 58 | 59 | 60 | inline float clamp(float a, float min, float max) { 61 | return ofClamp(a, min, max); 62 | } 63 | 64 | 65 | class Rand { 66 | public: 67 | 68 | static float randFloat() { return ofRandomf(); } 69 | static float randFloat(float f) { return ofRandom(0, f); } 70 | static float randFloat(float a, float b) { return ofRandom(a, b); } 71 | 72 | //! returns a random Vec3f that represents a point on the unit circle 73 | static Vec3f randVec3f() { 74 | float phi = randFloat( (float)M_PI * 2.0f ); 75 | float costheta = randFloat( -1.0f, 1.0f ); 76 | 77 | float rho = sqrt( 1.0f - costheta * costheta ); 78 | float x = rho * cos( phi ); 79 | float y = rho * sin( phi ); 80 | float z = costheta; 81 | 82 | return Vec3f( x, y, z ); 83 | } 84 | 85 | //! returns a random Vec2f that represents a point on the unit circle 86 | static Vec2f randVec2f() { 87 | float theta = randFloat( (float)M_PI * 2.0f ); 88 | return Vec2f( cos( theta ), sin( theta ) ); 89 | } 90 | }; 91 | 92 | 93 | } --------------------------------------------------------------------------------