Possible to draw portion of projection matrix?

Hello all,

Does anybody know if it’s possible to draw only a portion of the projection matrix? I’m trying to divide a project among 4 Raspberry Pis, and I need to make sure the perspective is the same in all four (a 2x2 grid). So, the goal is to full screen the top left quadrant on one Pi, the top right on another Pi, etc.

Also, sorry if this does not belong in the advanced category; I wasn’t sure if it was beginner or advanced!

Thank you!

Aaron

Hi,
you can use the ofCamera lensOffset for such.
I’ll post an example in a while
best

Sorry for the delay,
you can use the following.

ofApp.h

#pragma once

#include "ofMain.h"
class ofApp : public ofBaseApp{

	public:
		void setup();
		void draw();
	void drawScene();
	
	ofEasyCam cam;
	vector<ofPoint> points;
	vector<ofColor> colors;
	enum sectionName{
		UP_RIGHT=0,
		UP_LEFT,
		DOWN_RIGHT,
		DOWN_LEFT
	};
	
	string sectionNameToString(sectionName s);
	void drawSection(sectionName section, ofRectangle viewport);
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	int numPoints = 1000;
	
	for (int i = 0; i < numPoints; i++){
		points.push_back(ofPoint(ofRandom(-500, 500),ofRandom(-500, 500),ofRandom(-500, 500)));
		colors.push_back(ofColor(ofRandom(255),ofRandom(255),ofRandom(255)));
	}
}

//--------------------------------------------------------------
void ofApp::draw(){
	ofRectangle vp = ofGetCurrentViewport();
	if(ofGetKeyPressed('1')){
		drawSection(UP_LEFT, vp);
	}else if(ofGetKeyPressed('2')){
		drawSection(UP_RIGHT,vp);
	}else if(ofGetKeyPressed('3')){
		drawSection(DOWN_LEFT,vp);
	}else if(ofGetKeyPressed('4')){
		drawSection(DOWN_RIGHT,vp);
	}
	else{
		cam.begin();
		drawScene();
		cam.end();
	}
}
//--------------------------------------------------------------
void ofApp::drawScene(){

	for (int i =0; i < points.size(); i++) {
		ofSetColor(colors[i]);
		ofDrawSphere(points[i], 10);
	}
	ofDrawGrid(100,10);
}
//--------------------------------------------------------------
void ofApp::drawSection(sectionName section, ofRectangle viewport){

	ofCamera c = cam;
	
	ofVec2f offset;
	switch (section) {
		case UP_RIGHT:
			offset.set(1, 1);
			break;
		case UP_LEFT:
			offset.set(-1, 1);
			break;
		case DOWN_RIGHT:
			offset.set(1, -1);
			break;
		case DOWN_LEFT:
			offset.set(-1, -1);
			break;
	}

	c.setFov(atan(tan(cam.getFov()*DEG_TO_RAD*0.5)*0.5)*RAD_TO_DEG*2);//this is the picky part
	c.setLensOffset(offset);
	c.begin();
	drawScene();
	c.end();
	ofDrawBitmapStringHighlight(sectionNameToString(section), 30,30);
}
//--------------------------------------------------------------
string ofApp::sectionNameToString(sectionName s){
	switch (s) {
		case UP_RIGHT:
			return "UP_RIGHT";
		case UP_LEFT:
			return "UP_LEFT";
		case DOWN_RIGHT:
			return "DOWN_RIGHT";
		case DOWN_LEFT:
			return "DOWN_LEFT";
	}
	return "";
}

in this example if you press keys from 1 to 4 you will see just one section of the camera . The important code is in the drawSection function.
hope it helps.
best

@roymacdonald,

This seems to do the trick! Thank you for your fast response, hopefully I can repay the favor one day!

Best,

Aaron

@Aaron_Anderson ha! no worries!
Cheers!