How to let 3D objects overlap each other in physical sense

Hi, I have created these 3 rectangles one by one and I wish to achieve something like this:
image
but it turns out like this:



so the three objects, even though they actually are intersecting each other, don’t look like they are intersecting when I rotate them into other angles. They are just not following the normal rule for seeing.

Here is my code:

void ofApp::draw(){
    gui.draw();
    cam.begin();
    

    ofPushMatrix();
    rectangle2.draw();//Red
    ofPopMatrix();
    
    ofPushMatrix();
    rectangle1.draw();//Blue
    ofPopMatrix();
    
    ofPushMatrix();
    rectangle3.draw();//Green
    ofPopMatrix();
    


    cam.end();
}

and for most the code in each rectangle, they mostly look like this:

void Rect3::draw(){
    ofSetColor(0,255,0);
        ofFill();
    ofRotateYDeg(90);
    ofDrawRectangle(-100, -161.8, 0, w3, h3);
    
}

Could you please help me with this? :joy:

Looks like a depth testing issue. See a possible solution here

I don’t even remember writing that! :rofl:
But, @lilyxia99 that is definitely a depth test problem.

2 Likes

Thank you so much for referring to the answer! It immediately works!

1 Like

Thank you so much for writing the guidance! That helps a lot!

2 Likes