void CGizmoTransformScale::Draw() { if (m_pMatrix) { ComputeScreenFactor(); tvector3 orig(m_pMatrix->m16[12],m_pMatrix->m16[13],m_pMatrix->m16[14]); // axis tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1); if (mLocation == LOCATE_LOCAL) { axeX.TransformVector(*m_pMatrix); axeY.TransformVector(*m_pMatrix); axeZ.TransformVector(*m_pMatrix); axeX.Normalize(); axeY.Normalize(); axeZ.Normalize(); } DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeZ); DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XY)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeY); DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_YZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeY, axeZ); axeX*=GetScreenFactor(); axeY*=GetScreenFactor(); axeZ*=GetScreenFactor(); // plan1 if (m_ScaleTypePredict != SCALE_X) DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1)); else DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,1,1,1)); //plan2 if (m_ScaleTypePredict != SCALE_Y) DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(0,1,0,1)); else DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(1,1,1,1)); //plan3 if (m_ScaleTypePredict != SCALE_Z) DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(0,0,1,1)); else DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(1,1,1,1)); } }
// plot the enclosure polygon void EncQuadBezier::plot_enc_patch(int nordir) { int i,j; REAL* p1, *p2, *p3, *p4; int cr; if(!enc_computed) compute_enclosure(); //return; //set_color(1); //glEnable(GL_AUTO_NORMAL); glEnable(GL_LIGHTING); //glShadeModel(GL_FLAT); for (i=0; i<segu; i++) { for (j=0; j<segv; j++) { //per bilinear facet p1 = get_enc(nordir, i,j); p2 = get_enc(nordir, i,j+1); p3 = get_enc(nordir, i+1,j+1); p4 = get_enc(nordir, i+1,j); cr = (cralong[i*(segv)+j]+nordir)%2; // opposite creases in/out if(cr==0) { DrawTri(p1, p3, p2); DrawTri(p3, p1, p4); }else if(cr ==1) { DrawTri(p1, p4, p2); DrawTri(p2, p4, p3); } } } //glShadeModel(GL_SMOOTH); }
void CGizmoTransformScale::Draw() { if (m_pMatrix) { ComputeScreenFactor(); //glDisable(GL_DEPTH_TEST); tvector3 orig(m_pMatrix->m16[12],m_pMatrix->m16[13],m_pMatrix->m16[14]); // axis tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1); if (mLocation == LOCATE_LOCAL) { axeX.TransformVector(*m_pMatrix); axeY.TransformVector(*m_pMatrix); axeZ.TransformVector(*m_pMatrix); axeX.Normalize(); axeY.Normalize(); axeZ.Normalize(); } DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeZ); DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XY)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeY); DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_YZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeY, axeZ); axeX*=GetScreenFactor(); axeY*=GetScreenFactor(); axeZ*=GetScreenFactor(); // plan1 if (m_ScaleTypePredict != SCALE_X) DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1)); else DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,1,1,1)); //plan2 if (m_ScaleTypePredict != SCALE_Y) DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(0,1,0,1)); else DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(1,1,1,1)); //plan3 if (m_ScaleTypePredict != SCALE_Z) DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(0,0,1,1)); else DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(1,1,1,1)); /* // debug glPointSize(20); glBegin(GL_POINTS); glVertex3fv(&ptd.x); glEnd(); glEnable(GL_DEPTH_TEST); */ #if 0 #ifdef WIN32 GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); GDD->GetD3D9Device()->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE ); GDD->GetD3D9Device()->SetRenderState(D3DRS_ZENABLE , D3DZB_TRUE); GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHATESTENABLE , FALSE); GDD->GetD3D9Device()->SetRenderState(D3DRS_ZWRITEENABLE , TRUE); #endif extern RenderingState_t GRenderingState; GRenderingState.mAlphaTestEnable = 0; GRenderingState.mZWriteEnable = 1; GRenderingState.mBlending = 0; GRenderingState.mCulling = 0; GRenderingState.mZTestType = 1; #endif } }
// return 1 if this patch needs to be subdivided // ( triangles intersect the normal to the opposite direction) // return 0 if ok int EncQuadBezier::make_lam() { VEC nor, bend, hv0, hv1; // bend = bdir double lam, h; int i,j, m, sm,sp,s2, idx[4][2], sd, ii,jj, nsgn, nnsgn, cr,ncr; // booleans VEC env[2][4]; // env[1]=(upper)=outer int need_subdiv = 0; // return value for (i=0; i<d1; i++) for (j=0; j<d1; j++) lambda[i][j][0]= lambda[i][j][1]= 0; for (i=0; i<segu; i++) { for (j=0; j<segv; j++) { // normal at center determines which bilinear // to choose, eg +++ in all components means // ubd ubd ubd = outer // lbd lbd lbd = inner // determine diagonal: // curvature - + // + - VEC mid[2][2]; for(m=0;m<DIM;m++) { mid[0][0][m] =(get_enc(1,i,j)[m] + get_enc(0,i,j)[m])/2; mid[0][1][m] =(get_enc(1,i,j+1)[m] + get_enc(0,i,j+1)[m])/2; mid[1][0][m] =(get_enc(1,i+1,j)[m] + get_enc(0,i+1,j)[m])/2; mid[1][1][m] =(get_enc(1,i+1,j+1)[m] + get_enc(0,i+1,j+1)[m])/2; } for (m=0; m<DIM; m++) bend[m] = mid[0][0][m]+mid[1][1][m]-mid[0][1][m]-mid[1][0][m]; VVminus(mid[1][1],mid[0][0],hv0); VVminus(mid[0][1],mid[1][0],hv1); VVcross(hv0,hv1, nor); // if (crease >= 0) // triangles |/| or flat h = VVmult(sup_nor[i][j],nor); if (h < 0) printf("h %lf\n",h); h = VVmult(bend,nor); cr = (h >= 0); // convex up in normal direction == cr=1 cralong[i*(segv)+j] = cr; // record crease of bilinear // translation table // 3 2 // 0 1 idx[0][0] = i; idx[0][1] = j; idx[1][0] = i+1; idx[1][1] = j; idx[2][0] = i+1; idx[2][1] = j+1; idx[3][0] = i; idx[3][1] = j+1; // quadrant of the normal decides on choice of bilinear // depends on whether the normal is "outward" pointing // bd[1]...[x]: x component larger for (m=0; m<DIM; m++) { nsgn = (nor[m] >= 0); // if 1 then want bd[1] -- except when // normal is inward pointing (cube) nnsgn = (nsgn+1)%2; for (sd=0; sd<4; sd++) { // (nsgn=1) want upper bd in normal dir (env[1]..) ii = idx[sd][0]; jj = idx[sd][1]; env[1][sd][m] = get_enc(nsgn,ii,jj)[m]; env[0][sd][m] = get_enc(nnsgn,ii,jj)[m]; } } if(0) // draw the nor (put it in the center of the quad) { VEC center, sum; for(m=0;m<DIM;m++) { // center of all four up-enclosure corners center[m] = (env[1][0][m] + env[1][1][m] + env[1][2][m] + env[1][3][m])/4; } Normalize(nor); VVadd(1.0, center, 20, nor, sum); glDisable(GL_LIGHTING); glColor3f(0.3,0.0, 1.0); glBegin(GL_LINES); glVertex4dv(center); glVertex4dv(sum); glEnd(); glEnable(GL_LIGHTING); } // compute lambdas based on crease orientation // cr==1 for ridge 02 in normal direction // isect with 2 env[1] and 1 env[0] for (sd=0; sd<4; sd++) { // intersect with 3 total! ii = idx[sd][0]; jj = idx[sd][1]; sp = (sd+1)%4; s2 = (sd+2)%4; sm = (sd+3)%4; ncr = (cr+1)%2; // sm---s2 // | | // sd---sp lam = plane_intersect(sup_pt[ii][jj], sup_nor[ii][jj], env[cr][sd], env[cr][sp], env[cr][s2]); // Why (cr) selection? if cr then q=nor same dir as bend, as // supnor -- so compare with the two planes of the // triangles (cr) and then with the other (ncr) // if (cr) { if (lam > lambda[ii][jj][1]) lambda[ii][jj][1] = lam; } else { if (lam < lambda[ii][jj][0]) { lambda[ii][jj][0] = lam; } } if ((cr && (lam < -tol) ) || (ncr && (lam > tol))) { printf("not ok 1 cr %d lam %lf iijj %d %d \n",cr,lam,ii,jj); need_subdiv = 1; // need to be subdivied } if(debugchoice & EXTTRI) { set_color(ncr); if(!ncr) // only outter enclosure DrawTri(env[cr][sd], env[cr][sp], env[cr][s2]); } //else printf(" ok 1 \n"); lam = plane_intersect(sup_pt[ii][jj], sup_nor[ii][jj], env[cr][sd], env[cr][s2], env[cr][sm]); if (cr) { if (lam > lambda[ii][jj][1]) lambda[ii][jj][1] = lam; } else { if (lam < lambda[ii][jj][0]){ lambda[ii][jj][0] = lam; } } if ((cr && (lam < -tol) ) || (ncr && (lam > tol))) { printf("not ok 2 cr %d lam %lf iijj %d %d \n",cr,lam,ii,jj); need_subdiv = 1; // need to be subdivied } if(debugchoice & EXTTRI) { set_color(ncr); if(!ncr) // only outter enclosure DrawTri(env[cr][sd], env[cr][s2], env[cr][sm]); } //else printf(" ok 2 \n"); lam = plane_intersect(sup_pt[ii][jj], sup_nor[ii][jj], env[ncr][sd], env[ncr][sp], env[ncr][sm]); if (ncr) { if (lam > lambda[ii][jj][1]) lambda[ii][jj][1] = lam; } else { if (lam < lambda[ii][jj][0]) { lambda[ii][jj][0] = lam; } } if ((cr && (lam > tol) ) || (ncr && (lam < -tol))) { printf("not ok 3 cr %d lam %lf iijj %d %d \n",cr,lam,ii,jj); need_subdiv = 1; // need to be subdivied } if(debugchoice & EXTTRI) { set_color(cr); if(!cr) // only outter enclosure DrawTri(env[ncr][sd], env[ncr][sp], env[ncr][sm]); } //else printf(" ok 3 \n"); cr = ncr; // crease opposite at next point } // w...[1] has pos (in normal dir) values } } // subdivide the patch if needed return need_subdiv; }