ofVec3f ofxMapamok::worldToScreen(ofVec3f WorldXYZ, ofRectangle viewport) { if (!calibrationReady) { return WorldXYZ; } if (viewport.isZero()) { viewport = ofGetCurrentViewport(); } begin(); ofMatrix4x4 modelViewMatrix = ofGetCurrentMatrix(OF_MATRIX_MODELVIEW); ofMatrix4x4 projectionMatrix = ofGetCurrentMatrix(OF_MATRIX_PROJECTION); end(); ofVec3f CameraXYZ = WorldXYZ * modelViewMatrix * projectionMatrix; ofVec3f ScreenXYZ; ScreenXYZ.x = (CameraXYZ.x + 1.0f) / 2.0f * viewport.width + viewport.x; ScreenXYZ.y = (1.0f - CameraXYZ.y) / 2.0f * viewport.height + viewport.y; ScreenXYZ.z = CameraXYZ.z; return ScreenXYZ; }