Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ofxDomemaster_modified
#include "ofxDomemaster.h"
ofxDomemaster::ofxDomemaster(){
meshScaleExt = 1.;
}
//--------------------------------------------------------------
void ofxDomemaster::setup(int _width, int _height){
width = _width;
height = _height;
for (int i=0; i<renderCount; i++){
ofCamera c;
// c.setNearClip(.01);
renderCamera.push_back(c);
ofFbo f;
renderFbo.push_back(f);
ofVboMesh m;
renderMesh.push_back(m);
}
resize(width, height);
renderMesh[bottom].load("domemaster/bottom.ply");
renderMesh[front].load("domemaster/front.ply");
renderMesh[left].load("domemaster/left.ply");
renderMesh[right].load("domemaster/right.ply");
renderMesh[top].load("domemaster/top.ply");
// mask
mask.loadImage("domemaster/mask.png");
mask.setUseTexture(true);
}
//--------------------------------------------------------------
void ofxDomemaster::begin(int i){
// renderCamera[i].begin(view);
// renderCamera[i].end();
// renderFbo[i].begin(false);
// glMatrixMode(GL_PROJECTION);
// glPushMatrix();
// glLoadMatrixf(renderCamera[i].getProjectionMatrix(ofRectangle(0, 0, width, height)).getPtr());
// glMatrixMode(GL_MODELVIEW);
// glPushMatrix();
// glLoadMatrixf(renderCamera[i].getModelViewMatrix().getPtr());
// // glViewport(0, 0, width, height);
// glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
// ofPushStyle();
// glPushAttrib(GL_ENABLE_BIT);
renderFbo[i].begin(false);
ofClear(0.0, 0.0, 0.0, 0.0);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderCamera[i].begin(view);
}
//--------------------------------------------------------------
void ofxDomemaster::end(int i){
// glPopAttrib();
// ofPopStyle();
// // glViewport(0, 0, width, height);
// glMatrixMode(GL_PROJECTION);
// glPopMatrix();
// glMatrixMode(GL_MODELVIEW);
// glPopMatrix();
// renderFbo[i].end();
renderCamera[i].end();
renderFbo[i].end();
}
void ofxDomemaster::beginAdded(int i){
renderFbo[i].begin(false);
renderCamera[i].begin(view);
}
void ofxDomemaster::endAdded(int i){
renderCamera[i].end();
renderFbo[i].end();
}
//--------------------------------------------------------------
// void ofxDomemaster::draw(){
// fisheyeCamera.enableOrtho();
// fisheyeCamera.begin(fisheyeView);
// ofEnableNormalizedTexCoords();
// for (int i=0; i<renderCount; i++){
// renderFbo[i].getTextureReference().bind();
// ofPushMatrix();
// ofRotate(90,1,0,0);
// ofRotate(180,0,0,1);
// ofRotate(180,0,1,0);
// ofScale(meshScale, meshScale, meshScale);
// renderMesh[i].drawFaces();
// ofPopMatrix();
// renderFbo[i].getTextureReference().unbind();
// }
// ofDisableNormalizedTexCoords();
// fisheyeCamera.end();
// fisheyeCamera.draw();
// mask.draw(0, 0, width, height);
// }
void ofxDomemaster::draw(){
fisheyeCamera.enableOrtho();
fisheyeCamera.begin(fisheyeView);
ofEnableNormalizedTexCoords();
for (int i=0; i<renderCount; i++){
renderFbo[i].getTextureReference().bind();
ofPushMatrix();
ofRotate(90,1,0,0);
ofRotate(180,0,0,1);
ofRotate(180,0,1,0);
ofScale(meshScale, meshScale, meshScale);
renderMesh[i].drawFaces();
ofPopMatrix();
renderFbo[i].getTextureReference().unbind();
}
ofDisableNormalizedTexCoords();
fisheyeCamera.end();
fisheyeCamera.draw();
}
void ofxDomemaster::drawDepth(){
fisheyeCamera.enableOrtho();
fisheyeCamera.begin(fisheyeView);
ofEnableNormalizedTexCoords();
for (int i=0; i<renderCount; i++){
renderFbo[i].getDepthTexture().bind();
ofPushMatrix();
ofRotate(90,1,0,0);
ofRotate(180,0,0,1);
ofRotate(180,0,1,0);
ofScale(meshScale, meshScale, meshScale);
renderMesh[i].drawFaces();
ofPopMatrix();
renderFbo[i].getDepthTexture().unbind();
}
ofDisableNormalizedTexCoords();
fisheyeCamera.end();
fisheyeCamera.draw();
}
void ofxDomemaster::drawMask(){
mask.draw(0, 0, width, height);
}
//--------------------------------------------------------------
void ofxDomemaster::resize(int w, int h){
width = w;
height = h;
// set view for cube cameras
view.setWidth(width);
view.setHeight(height);
// cube camera
renderCamera[bottom].setOrientation(ofVec3f(-90,0,0));
renderCamera[bottom].setFov(90);
renderCamera[front].setOrientation(ofVec3f(0,0,0));
renderCamera[front].setFov(90);
renderCamera[left].setOrientation(ofVec3f(0,90,0));
renderCamera[left].setFov(90);
renderCamera[right].setOrientation(ofVec3f(0,-90,0));
renderCamera[right].setFov(90);
renderCamera[top].setOrientation(ofVec3f(90,0,0));
renderCamera[top].setFov(90);
ofFbo::Settings s;
s.width = ofNextPow2(width);
s.height = ofNextPow2(height);
s.internalformat=GL_RGBA;
s.textureTarget = GL_TEXTURE_2D;
s.useDepth = true;
// s.useStencil = true;
s.depthStencilInternalFormat = GL_DEPTH_COMPONENT32;
s.depthStencilAsTexture = true;
// cube camera fbos
for (int i=0; i<renderCount; i++){
// renderFbo[i].setUseTexture(true);
// renderFbo[i].allocate(width, height);
renderFbo[i].allocate(s);
// renderFbo[i].begin();
// ofClear(0);
// renderFbo[i].end();
}
// fisheye domemaster
fisheyeView.setWidth(width);
fisheyeView.setHeight(height);
// fisheyeCamera.setPosition(-width/2, -height/2, 10); // for 0.8.4 on C::B
fisheyeCamera.setPosition(0, 0, 10); // for 0.9.0 RC2 on VS2015
meshScale = width*meshScaleExt;
}
void ofxDomemaster::setCameraPosition(float x, float y, float z){
for (int i=0; i<renderCount; i++){
renderCamera[i].setPosition(x,y,z);
}
}
void ofxDomemaster::setCameraPosRot(float x, float y, float z, float pitch, float yaw, float roll){
for (int i=0; i<renderCount; i++){
renderCamera[i].resetTransform();
renderCamera[i].setPosition(x,y,z);
renderCamera[i].setOrientation(ofVec3f(pitch, yaw, roll));
}
renderCamera[bottom].tilt(-90);
renderCamera[top].tilt(90);
renderCamera[left].pan(90);
renderCamera[right].pan(-90);
}
void ofxDomemaster::lookAt(ofVec3f pov){
renderCamera[front].lookAt(pov);
renderCamera[bottom].lookAt(pov);
renderCamera[bottom].tilt(-90);
renderCamera[top].lookAt(pov);
renderCamera[top].tilt(90);
renderCamera[left].lookAt(pov);
renderCamera[left].pan(90);
renderCamera[right].lookAt(pov);
renderCamera[right].pan(-90);
}
void ofxDomemaster::rotateCamera(float pitch, float yaw, float roll){
ofQuaternion q(pitch, ofVec3f(1,0,0), yaw, ofVec3f(0,1,0), roll, ofVec3f(0,0,1));
renderCamera[front].resetTransform();
renderCamera[front].rotate(q);
renderCamera[bottom].resetTransform();
renderCamera[bottom].rotate(q);
renderCamera[bottom].tilt(90);
renderCamera[top].resetTransform();
renderCamera[top].rotate(q);
renderCamera[top].tilt(-90);
renderCamera[left].resetTransform();
renderCamera[left].rotate(q);
renderCamera[left].pan(90);
renderCamera[right].resetTransform();
renderCamera[right].rotate(q);
renderCamera[right].pan(-90);
// renderCamera[front].tilt(pitch);
// renderCamera[front].pan(yaw);
// renderCamera[front].roll(roll);
// renderCamera[bottom].tilt(pitch-90);
// renderCamera[bottom].pan(yaw);
// renderCamera[bottom].roll(roll);
// renderCamera[top].tilt(pitch+90);
// renderCamera[top].pan(yaw);
// renderCamera[top].roll(roll);
// renderCamera[left].tilt(pitch);
// renderCamera[left].pan(yaw+90);
// renderCamera[left].roll(roll);
// renderCamera[right].tilt(pitch);
// renderCamera[right].pan(yaw-90);
// renderCamera[right].roll(roll);
// renderCamera[front].rotate(pitch, yaw, roll);
// renderCamera[bottom].rotate(pitch-90, yaw, roll);
// renderCamera[top].rotate(pitch+90, yaw, roll);
// renderCamera[left].rotate(pitch, yaw+90, roll);
// renderCamera[right].rotate(pitch, yaw-90, roll);
}
void ofxDomemaster::setMeshScale(float s){
meshScaleExt = s;
meshScale = width*meshScaleExt;
}
void ofxDomemaster::setFlip(bool flip){
fisheyeCamera.setVFlip(true);
}
#pragma once
#include "ofMain.h"
class ofxDomemaster{
public:
ofxDomemaster();
void setup(int _width, int _height);
/* void draw(); */
void begin(int i);
void end(int i);
void beginAdded(int i);
void endAdded(int i);
void resize(int w, int h);
void setCameraPosition(float x, float y, float z);
void setCameraPosRot(float x, float y, float z, float pitch, float yaw, float roll);
void lookAt(ofVec3f pov);
void setMeshScale(float s);
void rotateCamera(float pitch, float yaw, float roll);
void draw();
void drawDepth();
void drawMask();
void setFlip(bool flip);
ofCamera& getCamera(int i){return renderCamera[i];}
ofCamera& getFisheyeCamera(){return fisheyeCamera;}
ofFbo& getCameraFbo(int i){return renderFbo[i];}
static const int renderCount = 5;
private:
ofRectangle view;
vector<ofCamera> renderCamera;
vector<ofFbo> renderFbo;
vector<ofVboMesh> renderMesh;
ofRectangle fisheyeView;
ofCamera fisheyeCamera;
ofImage mask;
int width;
int height;
float meshScale;
float meshScaleExt;
ofNode cameraNode;
enum positions{
bottom,
front,
left,
right,
top
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment