CPUのみでテクスチャスライシングを実装する

本物のページはこちら→cpu

Included page "texture-slicing:cpu" does not exist (create it now)

どの頂点が手前にかによって変わるエッジリスト

intersectionAlgorithm.png
辺番号 始点 終点
0 0 1
1 1 2
2 2 3
3 3 0
4 0 4
5 1 5
6 2 6
7 3 7
8 4 5
9 5 6
10 6 7
11 7 4

手前頂点と辺の対応表

    const int m_pEdgeList[8][12] = {//1~12までの数字があるから、エッジのリスト
        { 0,1,5,6,   4,8,11,9,  3,7,2,10 }, // v0 is front v1,v4,v3つまり、 v0と隣接する頂点を中心としたエッジのリスト
        { 0,4,3,11,  1,2,6,7,   5,9,8,10 }, // v1 is front
        { 1,5,0,8,   2,3,7,4,   6,10,9,11}, // v2 is front
        { 7,11,10,8, 2,6,1,9,   3,0,4,5  }, // v3 is front
        { 8,5,9,1,   11,10,7,6, 4,3,0,2  }, // v4 is front
        { 9,6,10,2,  8,11,4,7,  5,0,1,3  }, // v5 is front
        { 9,8,5,4,   6,1,2,0,   10,7,11,3}, // v6 is front
        { 10,9,6,5,  7,2,3,1,   11,4,8,0 }  // v7 is front
    };

手前の頂点 red line blue line green line
v0 0 1 5 6 4 8 11 9 3 7 2 10
v1 0 4 3 11 1 2 6 7 5 9 8 10
v2 1 5 0 8 2 3 7 4 6 10 9 11
v3 7 11 10 8 2 6 1 9 3 0 4 5
v4 8 5 9 1 11 10 7 6 4 3 0 2
v5 9 6 10 2 8 11 4 7 5 0 1 3
v6 9 8 5 4 6 1 2 0 10 7 11 3
v7 10 9 6 5 7 2 3 1 11 4 8 0
void GLRender::DrawClipPlane(){
    vec3<float> viewVec(-mModelView.m[2],-mModelView.m[6],-mModelView.m[10]);
 
    float dMaxDist = viewVec.innerProduct( mBoundingBox.corner[0]);
    float dMinDist = dMaxDist;
    int nMaxIdx = 0;
    for(int i = 1; i < 8; ++i) {
        float dist = viewVec.innerProduct( mBoundingBox.corner[i]);
        if ( dist > dMaxDist) {
            dMaxDist = dist;
            nMaxIdx = i;
        }
        if ( dist < dMinDist) {
            dMinDist = dist;
        }
 
    }
    vec3<float> vecStart[12];
    vec3<float> vecDir[12];
    float lambda[12];
    float denom;
 
    dMinDist += FLT_EPSILON;
    dMaxDist -= FLT_EPSILON;
    float dPlaneDist    = -(mClipPlane-mEyeCam.z+mTranslationVec.z);// (dMinDist+dMaxDist)/2.0 ;   
    float dVertices[12*3];
    float dEdges[12*3];
 
    for(int i = 0; i < 12; i++) {
        vecStart[i] = mBoundingBox.corner[mBoundingBox.edges[edgeList[nMaxIdx][i]].nV1];
        vecDir[i]   = mBoundingBox.corner[mBoundingBox.edges[edgeList[nMaxIdx][i]].nV2] - mBoundingBox.corner[mBoundingBox.edges[edgeList[nMaxIdx][i]].nV1];
 
        denom = vecDir[i].innerProduct(viewVec);
 
        if (1.0 + denom != 1.0) {
            lambda[i]     = (dPlaneDist - vecStart[i].innerProduct(viewVec))/denom;
        } else {
            lambda[i]     = -1.0;
        }
 
        dVertices[3*i]   = vecStart[i].x;
        dVertices[3*i+1] = vecStart[i].y;
        dVertices[3*i+2] = vecStart[i].z;
        dEdges[3*i]      = vecDir[i].x;
        dEdges[3*i+1]    = vecDir[i].y;
        dEdges[3*i+2]    = vecDir[i].z;
    };
 
    vec3<float> intersection[6];
    bool visible=true;
    //lmb:辺のどのあたりに交点があるのかの、割合。
 
    if      ((lambda[0] >= 0.0) && (lambda[0] < 1.0)) intersection[0] = vecStart[0] + vecDir[0]*lambda[0] ;
    else if ((lambda[1] >= 0.0) && (lambda[1] < 1.0)) intersection[0] = vecStart[1] + vecDir[1]* lambda[1] ;
    else if ((lambda[3] >= 0.0) && (lambda[3] < 1.0)) intersection[0] = vecStart[3] + vecDir[3]* lambda[3] ;
    else {visible=false;}
 
    if        ((lambda[2] >= 0.0) && (lambda[2] < 1.0)) intersection[1] = vecStart[2] + vecDir[2]*lambda[2] ;
    else if ((lambda[0] >= 0.0) && (lambda[0] < 1.0)) intersection[1] = vecStart[0] + vecDir[0]*lambda[0] ;
    else if ((lambda[1] >= 0.0) && (lambda[1] < 1.0)) intersection[1] = vecStart[1] + vecDir[1]*lambda[1] ;
    else intersection[1] = vecStart[3] + vecDir[3] * lambda[3];
 
    if      ((lambda[4] >= 0.0) && (lambda[4] < 1.0)) intersection[2] = vecStart[4] +vecDir[4]* lambda[4] ;
    else if ((lambda[5] >= 0.0) && (lambda[5] < 1.0)) intersection[2] = vecStart[5] +  vecDir[5]*lambda[5] ;
    else intersection[2] = vecStart[7] + vecDir[7]*lambda[7]  ;
 
    if        ((lambda[6] >= 0.0) && (lambda[6] < 1.0)) intersection[3] = vecStart[6] + vecDir[6]*lambda[6]  ;
    else if ((lambda[4] >= 0.0) && (lambda[4] < 1.0)) intersection[3] = vecStart[4] +  vecDir[4]*lambda[4] ;
    else if ((lambda[5] >= 0.0) && (lambda[5] < 1.0)) intersection[3] = vecStart[5] +  vecDir[5]*lambda[5] ;
    else intersection[3] = vecStart[7] + vecDir[7]*lambda[7];
 
    if        ((lambda[8] >= 0.0) && (lambda[8] < 1.0)) intersection[4] = vecStart[8] +  vecDir[8]*lambda[8]  ;
    else if ((lambda[9] >= 0.0) && (lambda[9] < 1.0)) intersection[4] = vecStart[9] +  vecDir[9]*lambda[9]  ;
    else intersection[4] = vecStart[11]+ vecDir[11]*lambda[11];
 
    if        ((lambda[10]>= 0.0) && (lambda[10]< 1.0)) intersection[5] = vecStart[10]+ vecDir[10]*lambda[10]; 
    else if ((lambda[8] >= 0.0) && (lambda[8] < 1.0)) intersection[5] = vecStart[8] + vecDir[8]*lambda[8]  ;
    else if ((lambda[9] >= 0.0) && (lambda[9] < 1.0)) intersection[5] = vecStart[9] + vecDir[9]*lambda[9]   ;
    else intersection[5] = vecStart[11]+ vecDir[11]*lambda[11];
 
    mFontColor.glColor();
    if(visible){
        glBegin(GL_LINE_LOOP);
        for(int i = 0; i < 6; ++i) {
            intersection[i].glVertex();
        }
        glEnd();
    }
 
}

サポートサイト Wikidot.com