I have a situtation where I’ll be implementing certain things using ofPushMatrix(), ofTranslate() … etc. Now my need is to get the global coordinates after all these transformations. The only way I can think of (and it works, tested already, code below) is to store each transformation as a separate matrix as well and then I can use them (for each step) for transforming to the local points… but as you can imagine that can get real hairy real fast - so is there a better way of doing this? Getting global coordinates after using pushMatrix, ofTranslate, etc?
ofMatrix4x4 transform, transform2; ofPoint pointX(0, 0); ofPushMatrix(); ofTranslate(ofGetWidth()/2, ofGetHeight()/2); transform.setTranslation(ofGetWidth()/2, ofGetHeight()/2, 0); ofRotateZ(45); ofTranslate(100, 0); transform2 = transform; ofMatrix4x4 localRotate, localTranslate; auto rotate = ofQuaternion(45, ofVec3f(0, 0, 1)); localRotate.setRotate(rotate); localTranslate.setTranslation(100, 0, 0); transform2 = localTranslate * localRotate * transform2; ofSetColor(ofColor::red); ofDrawCircle(0, 0, 8); ofPopMatrix(); transform = ofMatrix4x4::getTransposedOf(transform); transform2 = ofMatrix4x4::getTransposedOf(transform2); ofSetColor(ofColor::yellow); ofDrawCircle(transform2 * pointX, 4);