Skip to content

[Idea] - Remove legacy math from Core #8178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 8 additions & 7 deletions addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
#include "ofPixels.h"
#include "ofGraphics.h"
#include "ofConstants.h"
#include "ofMatrix4x4.h"
#include "ofUtils.h" // ofGetElapsedTimef

#include <assimp/cimport.h>
@@ -587,10 +586,12 @@ void ofxAssimpModelLoader::updateMeshes(aiNode * node, glm::mat4 parentMatrix) {

aiMatrix4x4 m = node->mTransformation;
m.Transpose();
ofMatrix4x4 matrix(m.a1, m.a2, m.a3, m.a4,
m.b1, m.b2, m.b3, m.b4,
m.c1, m.c2, m.c3, m.c4,
m.d1, m.d2, m.d3, m.d4);
glm::mat4 matrix(
m.a1, m.a2, m.a3, m.a4,
m.b1, m.b2, m.b3, m.b4,
m.c1, m.c2, m.c3, m.c4,
m.d1, m.d2, m.d3, m.d4
);
matrix *= parentMatrix;

for(unsigned int i = 0; i < node->mNumMeshes; i++) {
@@ -685,7 +686,7 @@ void ofxAssimpModelLoader::updateGLResources(){

void ofxAssimpModelLoader::updateModelMatrix() {
modelMatrix = glm::identity<glm::mat4>();
modelMatrix = glm::translate(modelMatrix, toGlm(pos));
modelMatrix = glm::translate(modelMatrix, pos);
modelMatrix = glm::rotate(modelMatrix, ofDegToRad(180), glm::vec3(0,0,1));

if(normalizeScale) {
@@ -696,7 +697,7 @@ void ofxAssimpModelLoader::updateModelMatrix() {
modelMatrix = glm::rotate(modelMatrix, ofDegToRad(rotAngle[i]), glm::vec3(rotAxis[i].x, rotAxis[i].y, rotAxis[i].z));
}

modelMatrix = glm::scale(modelMatrix, toGlm(scale));
modelMatrix = glm::scale(modelMatrix, scale);
}

//------------------------------------------- animations.
4 changes: 2 additions & 2 deletions addons/ofxGui/src/ofxButton.cpp
Original file line number Diff line number Diff line change
@@ -55,14 +55,14 @@ void ofxButton::generateDraw(){
fg.setFilled(false);
fg.setStrokeWidth(1);
fg.setStrokeColor(thisFillColor);
fg.rectRounded(b.getPosition()+checkboxRect.getTopLeft()+glm::vec2{1,1},checkboxRect.width-2,checkboxRect.height-2, 5);
fg.rectRounded(b.getPosition()+checkboxRect.getTopLeft()+glm::vec3{1,1,0},checkboxRect.width-2,checkboxRect.height-2, 5);

cross.clear();
cross.setStrokeColor(thisTextColor);
cross.setFillColor(thisFillColor);
cross.setStrokeWidth(2);
cross.setFilled(true);
cross.rectRounded(b.getPosition()+checkboxRect.getTopLeft()+glm::vec2{1,1},checkboxRect.width-2,checkboxRect.height-2, 5);
cross.rectRounded(b.getPosition()+checkboxRect.getTopLeft()+glm::vec3{1,1,0},checkboxRect.width-2,checkboxRect.height-2, 5);

std::string name;
auto textX = b.x + textPadding + checkboxRect.width;
8 changes: 7 additions & 1 deletion addons/ofxGui/src/ofxGuiGroup.cpp
Original file line number Diff line number Diff line change
@@ -83,6 +83,8 @@ ofxGuiGroup * ofxGuiGroup::setup(const ofParameterGroup & _parameters, const of:
}else if(type == typeid(ofParameter <void> ).name()){
auto p = _parameters.getVoid(i);
add(p);
#ifdef OF_USE_LEGACY_MATH

}else if(type == typeid(ofParameter <ofVec2f> ).name()){
auto p = _parameters.get<ofVec2f>(i);
add(p);
@@ -92,6 +94,8 @@ ofxGuiGroup * ofxGuiGroup::setup(const ofParameterGroup & _parameters, const of:
}else if(type == typeid(ofParameter <ofVec4f> ).name()){
auto p = _parameters.get<ofVec4f>(i);
add(p);

#endif
}else if(type == typeid(ofParameter <glm::vec2> ).name()){
auto p = _parameters.get<glm::vec2>(i);
add(p);
@@ -173,6 +177,7 @@ void ofxGuiGroup::add(ofParameter <string> & parameter){
add(createGuiElement<ofxInputField<string> >(parameter));
}

#ifdef OF_USE_LEGACY_MATH
void ofxGuiGroup::add(ofParameter <ofVec2f> & parameter){
add(createGuiElement<ofxVecSlider_ <ofVec2f> >(parameter));
}
@@ -184,6 +189,7 @@ void ofxGuiGroup::add(ofParameter <ofVec3f> & parameter){
void ofxGuiGroup::add(ofParameter <ofVec4f> & parameter){
add(createGuiElement<ofxVecSlider_ <ofVec4f> >(parameter));
}
#endif

void ofxGuiGroup::add(ofParameter <glm::vec2> & parameter){
add(createGuiElement<ofxVecSlider_ <glm::vec2> >(parameter));
@@ -279,7 +285,7 @@ bool ofxGuiGroup::mouseReleased(ofMouseEventArgs & args){
return true;
}
}
if(b.inside(ofPoint(args.x, args.y))){
if(b.inside({args.x, args.y})){
return true;
}else{
return false;
2 changes: 2 additions & 0 deletions addons/ofxGui/src/ofxGuiGroup.h
Original file line number Diff line number Diff line change
@@ -32,9 +32,11 @@ class ofxGuiGroup : public ofxBaseGui {
ownedCollection.emplace_back(std::make_unique<ofxLabel>(parameter));
add(ownedCollection.back().get());
}
#ifdef OF_USE_LEGACY_MATH
void add(ofParameter<ofVec2f> & parameter);
void add(ofParameter<ofVec3f> & parameter);
void add(ofParameter<ofVec4f> & parameter);
#endif
void add(ofParameter<glm::vec2> & parameter);
void add(ofParameter<glm::vec3> & parameter);
void add(ofParameter<glm::vec4> & parameter);
5 changes: 5 additions & 0 deletions addons/ofxGui/src/ofxSliderGroup.cpp
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ size_t ofxVecSlider_<glm::vec4>::dim(){
return 4;
}

#ifdef OF_USE_LEGACY_MATH
template<>
size_t ofxVecSlider_<ofVec2f>::dim(){
return 2;
@@ -88,6 +89,7 @@ template<>
size_t ofxVecSlider_<ofVec4f>::dim(){
return 4;
}
#endif

template<class VecType>
ofAbstractParameter & ofxVecSlider_<VecType>::getParameter(){
@@ -110,9 +112,12 @@ const VecType * ofxVecSlider_<VecType>::operator->(){
return &value.get();
}

#ifdef OF_USE_LEGACY_MATH
template class ofxVecSlider_<ofVec2f>;
template class ofxVecSlider_<ofVec3f>;
template class ofxVecSlider_<ofVec4f>;
#endif

template class ofxVecSlider_<glm::vec2>;
template class ofxVecSlider_<glm::vec3>;
template class ofxVecSlider_<glm::vec4>;
22 changes: 11 additions & 11 deletions addons/ofxKinect/src/ofxKinect.cpp
Original file line number Diff line number Diff line change
@@ -423,20 +423,20 @@ float ofxKinect::getDistanceAt(int x, int y) const{
}

//------------------------------------
float ofxKinect::getDistanceAt(const ofPoint & p) const{
float ofxKinect::getDistanceAt(const glm::vec2 & p) const{
return getDistanceAt(p.x, p.y);
}

//------------------------------------
ofVec3f ofxKinect::getWorldCoordinateAt(int x, int y) const{
glm::vec3 ofxKinect::getWorldCoordinateAt(int x, int y) const{
return getWorldCoordinateAt(x, y, getDistanceAt(x, y));
}

//------------------------------------
ofVec3f ofxKinect::getWorldCoordinateAt(float cx, float cy, float wz) const{
glm::vec3 ofxKinect::getWorldCoordinateAt(float cx, float cy, float wz) const{
double wx, wy;
freenect_camera_to_world(kinectDevice, cx, cy, wz, &wx, &wy);
return ofVec3f(wx, wy, wz);
return glm::vec3(wx, wy, wz);
}

//------------------------------------
@@ -472,7 +472,7 @@ ofColor ofxKinect::getColorAt(int x, int y) const{
}

//------------------------------------
ofColor ofxKinect::getColorAt(const ofPoint & p) const{
ofColor ofxKinect::getColorAt(const glm::vec2 & p) const{
return getColorAt(p.x, p.y);
}

@@ -602,12 +602,12 @@ bool ofxKinect::hasLedControl() const{
}

//---------------------------------------------------------------------------
ofPoint ofxKinect::getRawAccel() const{
glm::vec3 ofxKinect::getRawAccel() const{
return rawAccel;
}

//---------------------------------------------------------------------------
ofPoint ofxKinect::getMksAccel() const{
glm::vec3 ofxKinect::getMksAccel() const{
return mksAccel;
}

@@ -677,7 +677,7 @@ void ofxKinect::draw(float _x, float _y) const{
}

//----------------------------------------------------------
void ofxKinect::draw(const ofPoint & point) const{
void ofxKinect::draw(const glm::vec2 & point) const{
draw(point.x, point.y);
}

@@ -699,7 +699,7 @@ void ofxKinect::drawDepth(float _x, float _y) const{
}

//----------------------------------------------------------
void ofxKinect::drawDepth(const ofPoint & point) const{
void ofxKinect::drawDepth(const glm::vec2 & point) const{
drawDepth(point.x, point.y);
}

@@ -866,11 +866,11 @@ void ofxKinect::threadedFunction(){
freenect_raw_tilt_state * tilt = freenect_get_tilt_state(kinectDevice);
currentTiltAngleDeg = freenect_get_tilt_degs(tilt);

rawAccel.set(tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z);
rawAccel = {tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z};

double dx,dy,dz;
freenect_get_mks_accel(tilt, &dx, &dy, &dz);
mksAccel.set(dx, dy, dz);
mksAccel = {dx, dy, dz};
}

// finish up a tilt on exit
20 changes: 10 additions & 10 deletions addons/ofxKinect/src/ofxKinect.h
Original file line number Diff line number Diff line change
@@ -121,13 +121,13 @@ class ofxKinect : public ofxBase3DVideo, protected ofThread {

/// get the calulated distance for a depth point
float getDistanceAt(int x, int y) const;
float getDistanceAt(const ofPoint & p) const;
float getDistanceAt(const glm::vec2 & p) const;

/// calculates the coordinate in the world for the depth point (perspective calculation)
///
/// center of image is (0.0)
ofVec3f getWorldCoordinateAt(int cx, int cy) const;
ofVec3f getWorldCoordinateAt(float cx, float cy, float wz) const;
glm::vec3 getWorldCoordinateAt(int cx, int cy) const;
glm::vec3 getWorldCoordinateAt(float cx, float cy, float wz) const;

/// \section Intrinsic IR Sensor Parameters

@@ -154,7 +154,7 @@ class ofxKinect : public ofxBase3DVideo, protected ofThread {
///
/// see setRegistration() for calibrated depth->RGB points
ofColor getColorAt(int x, int y) const;
ofColor getColorAt(const ofPoint & p) const;
ofColor getColorAt(const glm::vec2 & p) const;

/// \section Pixel Data

@@ -226,7 +226,7 @@ class ofxKinect : public ofxBase3DVideo, protected ofThread {
/// ... yes, the kinect has an accelerometer

/// raw axis values
ofPoint getRawAccel() const;
glm::vec3 getRawAccel() const;

/// axis-based gravity adjusted accelerometer values
///
@@ -236,7 +236,7 @@ class ofxKinect : public ofxBase3DVideo, protected ofThread {
///
/// http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf
///
ofPoint getMksAccel() const;
glm::vec3 getMksAccel() const;

/// get the current pitch (x axis) & roll (z axis) of the kinect in degrees
///
@@ -282,13 +282,13 @@ class ofxKinect : public ofxBase3DVideo, protected ofThread {
/// draw the video texture
void draw(float x, float y, float w, float h) const;
void draw(float x, float y) const;
void draw(const ofPoint& point) const;
void draw(const glm::vec2& point) const;
void draw(const ofRectangle& rect) const;

/// draw the grayscale depth texture
void drawDepth(float x, float y, float w, float h) const;
void drawDepth(float x, float y) const;
void drawDepth(const ofPoint& point) const;
void drawDepth(const glm::vec2& point) const;
void drawDepth(const ofRectangle& rect) const;

/// \section Util
@@ -354,8 +354,8 @@ class ofxKinect : public ofxBase3DVideo, protected ofThread {
ofShortPixels depthPixelsRaw;
ofFloatPixels distancePixels;

ofPoint rawAccel;
ofPoint mksAccel;
glm::vec3 rawAccel;
glm::vec3 mksAccel;

float targetTiltAngleDeg;
float currentTiltAngleDeg;
14 changes: 8 additions & 6 deletions addons/ofxOpenCv/src/ofxCvBlob.h
Original file line number Diff line number Diff line change
@@ -13,18 +13,17 @@

#include "ofxCvConstants.h"


class ofxCvBlob {

public:

float area;
float length;
ofRectangle boundingRect;
ofDefaultVec3 centroid;
ofDefaultVec2 centroid;
bool hole;

std::vector<ofDefaultVec3> pts; // the contour of the blob
std::vector<ofDefaultVec2> pts; // the contour of the blob
int nPts; // number of pts;

//----------------------------------------
@@ -40,13 +39,16 @@ class ofxCvBlob {
ofPushStyle();
ofNoFill();
ofSetHexColor(0x00FFFF);
ofPushMatrix();
ofTranslate(x, y);
ofBeginShape();
for (int i = 0; i < nPts; i++){
ofVertex(x + pts[i].x, y + pts[i].y);
for (const auto & p : pts) {
ofVertex(p);
}
ofEndShape(true);
ofSetHexColor(0xff0099);
ofDrawRectangle(x + boundingRect.x, y + boundingRect.y, boundingRect.width, boundingRect.height);
ofDrawRectangle(boundingRect);
ofPopMatrix();
ofPopStyle();
}
};
6 changes: 3 additions & 3 deletions addons/ofxOpenCv/src/ofxCvColorImage.h
Original file line number Diff line number Diff line change
@@ -116,10 +116,10 @@ class ofxCvColorImage : public ofxCvImage {
// float focalX, float focalY,
// float centerX, float centerY ); //in base class
// virtual void remap( IplImage* mapX, IplImage* mapY ); //in base class
// virtual void warpPerspective( ofPoint& A, ofPoint& B,
// ofPoint& C, ofPoint& D ); //in base class
// virtual void warpPerspective( glm::vec2 & A, glm::vec2 & B,
// glm::vec2 & C, glm::vec2 & D ); //in base class
// virtual void warpIntoMe( ofxCvImage& mom,
// ofPoint src[4], ofPoint dst[4] ); //in base class
// glm::vec2 src[4], glm::vec2 dst[4] ); //in base class


// Other Image Operations
4 changes: 2 additions & 2 deletions addons/ofxOpenCv/src/ofxCvContourFinder.cpp
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ int ofxCvContourFinder::findContours( ofxCvGrayscaleImage& input,

for( int j=0; j < cvSeqBlobs[i]->total; j++ ) {
CV_READ_SEQ_ELEM( pt, reader );
blobs[i].pts.push_back( ofPoint((float)pt.x, (float)pt.y) );
blobs[i].pts.push_back( glm::vec3{(float)pt.x, (float)pt.y, 0.0f} );
}
blobs[i].nPts = blobs[i].pts.size();

@@ -219,7 +219,7 @@ void ofxCvContourFinder::setAnchorPoint( float x, float y ){

//--------------------------------------------------------------------------------
void ofxCvContourFinder::resetAnchor(){
anchor.set(0,0);
anchor = { 0, 0 };
bAnchorIsPct = false;
}

2 changes: 1 addition & 1 deletion addons/ofxOpenCv/src/ofxCvContourFinder.h
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ class ofxCvContourFinder : public ofBaseDraws {
CvMoments* myMoments;
std::vector<CvSeq*> cvSeqBlobs; //these will become blobs

ofPoint anchor;
glm::vec2 anchor;
bool bAnchorIsPct;

virtual void reset();
6 changes: 3 additions & 3 deletions addons/ofxOpenCv/src/ofxCvFloatImage.h
Original file line number Diff line number Diff line change
@@ -128,10 +128,10 @@ class ofxCvFloatImage : public ofxCvImage {
// float focalX, float focalY,
// float centerX, float centerY ); //in base class
// virtual void remap( IplImage* mapX, IplImage* mapY ); //in base class
// virtual void warpPerspective( ofPoint& A, ofPoint& B,
// ofPoint& C, ofPoint& D ); //in base class
// virtual void warpPerspective( glm::vec2& A, glm::vec2& B,
// glm::vec2& C, glm::vec2& D ); //in base class
// virtual void warpIntoMe( ofxCvImage& mom,
// ofPoint src[4], ofPoint dst[4] ); //in base class
// glm::vec2 src[4], glm::vec2 dst[4] ); //in base class


// Other Image Operations
Loading