Skip to content

Commit

Permalink
Merge pull request #3300 from procedural/ofnode-fix
Browse files Browse the repository at this point in the history
Updating axis on matrix change
  • Loading branch information
arturoc committed Oct 11, 2014
2 parents 30860ba + f75e575 commit 4daba8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions libs/openFrameworks/3d/ofNode.cpp
Expand Up @@ -44,6 +44,7 @@ void ofNode::setTransformMatrix(const ofMatrix4x4 &m44) {

ofQuaternion so;
localTransformMatrix.decompose(position, orientation, scale, so);
updateAxis();

onPositionChanged();
onOrientationChanged();
Expand All @@ -59,6 +60,7 @@ void ofNode::setPosition(float px, float py, float pz) {
void ofNode::setPosition(const ofVec3f& p) {
position = p;
localTransformMatrix.setTranslation(position);
updateAxis();
onPositionChanged();
}

Expand Down Expand Up @@ -250,6 +252,13 @@ void ofNode::lookAt(const ofNode& lookAtNode, const ofVec3f& upVector) {
lookAt(lookAtNode.getGlobalPosition(), upVector);
}

//----------------------------------------
void ofNode::updateAxis() {
if(scale[0]>0) axis[0] = getLocalTransformMatrix().getRowAsVec3f(0)/scale[0];
if(scale[1]>0) axis[1] = getLocalTransformMatrix().getRowAsVec3f(1)/scale[1];
if(scale[2]>0) axis[2] = getLocalTransformMatrix().getRowAsVec3f(2)/scale[2];
}

//----------------------------------------
ofVec3f ofNode::getXAxis() const {
return axis[0];
Expand Down Expand Up @@ -380,9 +389,7 @@ void ofNode::createMatrix() {
localTransformMatrix.rotate(orientation);
localTransformMatrix.setTranslation(position);

if(scale[0]>0) axis[0] = getLocalTransformMatrix().getRowAsVec3f(0)/scale[0];
if(scale[1]>0) axis[1] = getLocalTransformMatrix().getRowAsVec3f(1)/scale[1];
if(scale[2]>0) axis[2] = getLocalTransformMatrix().getRowAsVec3f(2)/scale[2];
updateAxis();
}


2 changes: 1 addition & 1 deletion libs/openFrameworks/3d/ofNode.h
Expand Up @@ -149,7 +149,7 @@ class ofNode {
ofNode *parent;

void createMatrix();

void updateAxis();

// classes extending ofNode can override these methods to get notified
virtual void onPositionChanged() {}
Expand Down

0 comments on commit 4daba8b

Please sign in to comment.