ModelRenderer::ModelRenderer(QQuickItem *parent) : QQuickItem(parent) , m_window( nullptr ) , m_useProgram2( false ) , m_shaderProgram( nullptr ) , m_shaderProgram2( nullptr ) , m_rotateX(0.0) , m_rotateY(0.0) , m_rotateZ(0.0) , m_eyeDistance(4.0) , m_eyeAngleX(0.0) , m_eyeAngleY(0.0) , m_lightDistance(8.0) , m_lightAngleX(0.0) , m_lightAngleY(0.0) , m_ambientBrightness(0.5) , m_diffuseBrightness(0.75) , m_specularBrightness(1.0) , m_ambientReflection(0.5) , m_diffuseReflection(0.5) , m_specularReflection(0.5) , m_shininess(100.0) , m_spotExponent(1.0) , m_cutoffAngle(180.0) { LOG_ENTER(); QVector4D lineColor( 0.0, 0.0, 0.0, 1.0 ); // QVector4D lineColor( 1.0, 1.0, 1.0, 1.0 ); for( int i = 0; i < NUM_VERTICE * NUM_FACES; i++ ){ m_lineColorArray[i] = lineColor; } for( int i = 0; i < NUM_FACES; i ++ ){ QVector3D normal = createPolygonNormal( m_positionArray[NUM_VERTICE * i].toVector3D(), m_positionArray[NUM_VERTICE * i + 1].toVector3D(), m_positionArray[NUM_VERTICE * i + 2].toVector3D() ); for( int j = 0; j < NUM_VERTICE; j++ ){ m_normalArray[NUM_VERTICE * i + j] = normal; } } updateEyePosition(); updateLightPosition(); connect( this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(windowChanged(QQuickWindow *)), Qt::DirectConnection ); LOG_LEAVE(); }
void ShadowScene::drawPlaneRect(int angle, int interval){ if (angle > 360) angle = 360; int max_num = 360 / interval; int cur_num = angle / interval; //頂点情報を定義する。 float positions[4][3] ={ {-1.0f, -0.5f, 0.0f}, { 1.0f, -0.5f, 0.0f}, {-1.0f, 0.5f, 0.0f}, { 1.0f, 0.5f, 0.0f}, }; float radius = 0.0f; //開始点 radius= DEGREE_TO_RADIAN(angle); positions[2][0] = positions[0][0] = 1 * cos(radius); positions[2][2] = positions[0][2] = 1 * sin(radius); //終了点 radius = DEGREE_TO_RADIAN(angle + interval); positions[3][0] = positions[1][0] = 1 * cos(radius); positions[3][2] = positions[1][2] = 1 * sin(radius); Vector3<float> normal = createPolygonNormal( Vector3<float>(positions[2][0],positions[2][1],positions[2][2]), Vector3<float>(positions[1][0],positions[1][1],positions[1][2]), Vector3<float>(positions[0][0],positions[0][1],positions[0][2])); //座標変換等の開始 glPushMatrix(); glBegin(GL_TRIANGLES); //描画の開始 glNormal3fv(normal.v); //法線の定義 glTexCoord2d(1.0/max_num*cur_num , 1.0); glVertex3fv(positions[2]); //頂点3個目 glTexCoord2d(1.0/max_num*(cur_num+1), 0.0); glVertex3fv(positions[1]); //頂点2個目 glTexCoord2d(1.0/max_num*cur_num , 0.0); glVertex3fv(positions[0]); //頂点1個目 //2枚目の三角形 glNormal3fv(normal.v); //法線の定義 glTexCoord2d(1.0/max_num*cur_num , 1.0); glVertex3fv(positions[2]); //頂点3個目 glTexCoord2d(1.0/max_num*(cur_num+1), 1.0); glVertex3fv(positions[3]); //頂点2個目 glTexCoord2d(1.0/max_num*(cur_num+1), 0.0); glVertex3fv(positions[1]); //頂点1個目 //描画の終了 glEnd(); //座標変換の終了 glPopMatrix(); }