ライトの視点からシーンをレンダリング

seen-from-light.png
void display(){
        //描画
        glClearColor(0,0,0,0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
 
        glPushMatrix();
 
            glLoadIdentity();
            static bool state=glfwGetKey('L');
            if(glfwGetKey('L')){
                if(state==false){
                    state=true;
                }else{
                    state=false;
                }
            }
            //光源の位置はオブジェクトについてくるようにしたいので、行列を掛け算する
            m_target_quaternion.toMat4(const_cast<float*>(m_rotation_matrix.m));
            m_modelview.gluLookAt(m_world_eye_pos.x, m_world_eye_pos.y, m_zoom,0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
            m_modelview.glTranslate(m_translate.x,m_translate.y,0.0);
            m_modelview=m_modelview*m_rotation_matrix;
 
            vec3<float> light_pos(1.5,1.5,2.4);
            light_pos=m_modelview*light_pos;
            if(state){
                gluLookAt(light_pos.x, light_pos.y,light_pos.z,0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
            }else{
                gluLookAt(m_world_eye_pos.x, m_world_eye_pos.y, m_zoom,0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
            }
            GLfloat ambient[]={76.0/255.0,78.0/255.0,213.0/255.0,1.0};//{0.2,0.2,0.2,1.0};
            GLfloat mat_ambient[]={76.0/255.0,78.0/255.0,213.0/255.0,1.0};
            GLfloat light_position[]={light_pos.x,light_pos.y,light_pos.z,1.0};
            GLfloat mat_diffuse[]={106.0/255.0,121.0/255.0,1.0};//{0.6,0.8,0.0,1.0};
            GLfloat mat_specular[]={75.0/255.0,77.0/255.0,231.0/255.0,1.0};//{1.0,1.0,1.0,1.0};
            GLfloat mat_shiness[]={5.0};
            glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
            //glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
            glLightfv(GL_LIGHT0,GL_POSITION,light_position);
            glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
            glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
            glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
            glMaterialfv(GL_FRONT,GL_SHININESS,mat_shiness);
 
            glTranslated(m_translate.x,m_translate.y,0.0);/* 平行移動(奥行き方向)   */
 
            glMultMatrixf(m_rotation_matrix.m);//クォータニオンによる回転
 
            glEnable(GL_LINE_SMOOTH);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
            glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
 
            //glLineWidth(2.0);
            //glColor4ub(0,255,255,255);
            //glColor4ub(153,204,0,200);
            //glColor4f(0.0,0.0,0.0,1.0);
            //glutWireSphere(1.0,20,20);
            glUseProgram(m_glsl);
            glutSolidTeapot(1.0);
 
            glUseProgram(0);
            glDisable(GL_LIGHTING);
            glDisable(GL_LIGHT0);
        glPopMatrix();
 
        if(state){
            glColor4ub(255,255,255,255);
            glRasterPos3d(0,0,-m_near);//0,0,0位置をスタート位置にする
            glutBitmapString(GLUT_BITMAP_HELVETICA_18,(const unsigned char*)("seen from light position"));
 
            }
        glDisable(GL_BLEND);
        glDisable(GL_LINE_SMOOTH);
 
    }//for display

サポートサイト Wikidot.com