카테고리 없음

[C ++] Openframeworks 전역 조명

행복을전해요 2021. 2. 7. 06:55

모든 조명이 원점에서 만들어 졌기 때문이라고 생각합니다.

을 사용하면 ofTranslate해당 조명을 렌더링 할 때 더 이상 큐브 내부에 있지 않습니다 ( "원래 원점"에 있음).

큐브의 위치 멤버를 사용하고 변환을 큐브로 이동하여 그에 따라 광원을 변환 할 수있는 이유는 무엇입니까?

-------------------

나는 같은 문제가 있었고, 물체를 그리기 직전에 평행 이동과 회전 후 빛의 위치를 ​​적용하여 그것을 해결했습니다.

// ofLight light  
float la = ofGetElapsedTimef()*.1 * RAD_TO_DEG;
light_pos.set( 0,0,0 );
light_pos.x += sin( la ) * rad;
ofPushMatrix();
    ofTranslate( ofGetWidth() * 0.5f, ofgetHeight() * 0.5f, 0 );
        ofRotate( ofGetElapsedTimef()*.06 * RAD_TO_DEG, 0, 1, 0 );
        
            // when applied here and not before the pushMatrix
                // the light position is influence by 
                    // the current transformation matrix
                        light.setPosition( light_pos );
                        
                            glColor4f( 1,1,1,1 );
                                ofFill();
                                    ofDrawBox( -300,0,0, 50,50,200 );
                                        ofDrawBox( 0,-300,0, 50,50,200 );
                                            ofDrawBox( 300,0,0, 50,50,200 );
                                                ofDrawBox( 0,300,0, 50,50,200 );
                                                    ofDrawBox( 0,0,0, 200,200,200 );
                                                        glColor4f( 0,0,0,1 );
                                                        ofPopMatrix();
                                                        

결과는 큐브 공간에서 수평으로 움직이는 빛의 포인트입니다.



출처
https://stackoverflow.com/questions/22050234