'Slice' 3D Object using near & far clipping & view result other other angle

Hi all,

I want to create a slice of an object similar to what one can achieve by setting the near and far-clipping planes for the camera (e.g. image cam 1).
Now, the problem is that I want to view the resulting ‘slice’ from camera 2.
How would I go about to get such result?
(Basically this would be a boolean intersection)

I may have been to eager to post this question… :blush:

I’m looking into ofxCarveCSG and ofxCSG add-ons. Other tips are welcome, especially since I only need to create the visual illusion of this (hence my initial look into near/far clipping), I don’t need an actual mesh.

For the sake of those that come after me: these type of boolean construction operations (union / intersect / subtract) are called Constructive Solid Rendering (CSG))

1 Like

For future reference I’ve achieved what I needed by using user-defined clip planes

ofApp.h

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

public:
	void setup();
	void update();
	void draw();

ofSpherePrimitive sphere, sphere1;
ofLight light;
double eqn0[4] = {0., -0.1, 0.1, 5.};
double eqn1[4] = {0., 0.1, -0.1, 5.};
double eqn2[4] = {0.1, -0.1, 0.1, 5.};
double eqn3[4] = {-0.1, 0.1, -0.1, 5.};
float rot;

};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

sphere.set(200,20);
sphere1.set(150,20);
ofBackground(0, 0, 0);
ofEnableDepthTest();
light.setPosition(500, 100, 100);
light.enable();
}

//--------------------------------------------------------------
void ofApp::update(){

//updating the plane equations for fun

eqn0[0] = sin(ofGetElapsedTimef());
eqn1[0] = -1*sin(ofGetElapsedTimef());
eqn2[1] = cos(ofGetElapsedTimef());
eqn3[1] = -1*cos(ofGetElapsedTimef());

//for some reason the clip plane equations need to be set every frame
//seetting them in setup() alone does not work; even when not updating them. 
glClipPlane(GL_CLIP_PLANE0, eqn0);
glClipPlane(GL_CLIP_PLANE1, eqn1);
glClipPlane(GL_CLIP_PLANE2, eqn2);
glClipPlane(GL_CLIP_PLANE3, eqn3);

}
//--------------------------------------------------------------
void ofApp::draw(){ 

ofColor(255);
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

ofPushView();
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
sphere.draw();
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
ofPopView();


ofPushView();
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
sphere1.draw();
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
ofPopView();    
}
2 Likes