static YSRESULT YsClipInfiniteLine3_FindFirstIntersection (YsVec3 &itsc,const YsVec3 &org,const YsVec3 &vec,const YsVec3 range[2]) { int i,j,k; for(i=0; i<3; i++) { for(j=0; j<2; j++) { if(YsClip3DLine(itsc,org,vec,range[j].GetValue()[i],i)==YSOK) { for(k=0; k<3; k++) { if(i!=k && (itsc.GetValue()[k]<range[0].GetValue()[k]-YsTolerance || range[1].GetValue()[k]+YsTolerance<itsc.GetValue()[k])) { goto NEXTPLANE; } } return YSOK; } NEXTPLANE: ; } } return YSERR; }
static YSRESULT YsClipInfiniteLine3_FindSecondIntersection (YsVec3 &itsc,const YsVec3 &first,const YsVec3 &vec,const YsVec3 range[2]) { int i,j,k; double dist,d; YSRESULT found; YsVec3 candidate; found=YSERR; dist=-1.0; candidate.Set(0.0,0.0,0.0); for(i=0; i<3; i++) { for(j=0; j<2; j++) { if(YsClip3DLine(candidate,first,vec,range[j].GetValue()[i],i)==YSOK) { for(k=0; k<3; k++) { if(i!=k && (candidate.GetValue()[k]<range[0].GetValue()[k]-YsTolerance || range[1].GetValue()[k]+YsTolerance<candidate.GetValue()[k])) { goto NEXTPLANE; } } found=YSOK; d=(first-candidate).GetSquareLength(); if(d>dist) { itsc=candidate; dist=d; } } NEXTPLANE: ; } } return found; }
static YSRESULT YsClip3DLine (YsVec3 &clip,const YsVec3 &org,const YsVec3 &vec,const double &clipPoint,int component) { int c1,c2; double buf[3],slope[3]; if(component==0) { c1=1; c2=2; } else if(component==1) { c1=0; c2=2; } else { c1=0; c2=1; } if(YsAbs(vec.GetValue()[component])>=YsTolerance) { slope[c1]=vec.GetValue()[c1]/vec.GetValue()[component]; slope[c2]=vec.GetValue()[c2]/vec.GetValue()[component]; buf[component]=clipPoint; buf[c1]=org.GetValue()[c1]+slope[c1]*(clipPoint-org.GetValue()[component]); buf[c2]=org.GetValue()[c2]+slope[c2]*(clipPoint-org.GetValue()[component]); clip.Set(buf[0],buf[1],buf[2]); return YSOK; } else { return YSERR; } }
YSRESULT YsClipLineSeg3 (YsVec3 &newP1,YsVec3 &newP2,const YsVec3 &p1,const YsVec3 &p2,const YsVec3 &range1,const YsVec3 &range2) { int j,nInComp; YsVec3 min,max; YsBoundingBoxMaker3 bbx; bbx.Begin(range1); bbx.Add(range2); bbx.Get(min,max); nInComp=0; for(j=0; j<3; j++) { if(min.GetValue()[j]<=p1.GetValue()[j] && p1.GetValue()[j]<=max.GetValue()[j] && min.GetValue()[j]<=p2.GetValue()[j] && p2.GetValue()[j]<=max.GetValue()[j]) { nInComp++; } if(p1.GetValue()[j]<min.GetValue()[j] && p2.GetValue()[j]<min.GetValue()[j]) { return YSERR; } if(p1.GetValue()[j]>max.GetValue()[j] && p2.GetValue()[j]>max.GetValue()[j]) { return YSERR; } } if(nInComp==3) { newP1=p1; newP2=p2; return YSOK; } YsVec3 c1,c2; if(YsClipInfiniteLine3(c1,c2,p1,p2-p1,min,max)==YSOK) { if(YsCheckInBetween3(c1,p1,p2)==YSTRUE && YsCheckInBetween3(c2,p1,p2)==YSTRUE) { newP1=c1; newP2=c2; return YSOK; } else if(YsCheckInBetween3(c1,p1,p2)==YSTRUE) { // p1-c1 or c1-p2 if(YsCheckInBetween3(p1,c1,c2)==YSTRUE) { newP1=p1; newP2=c1; } else { newP1=c1; newP2=p2; } return YSOK; } else if(YsCheckInBetween3(c2,p1,p2)==YSTRUE) { // p1-c2 or c2-p2 if(YsCheckInBetween3(p1,c1,c2)==YSTRUE) { newP1=p1; newP2=c2; } else { newP1=c2; newP2=p2; } return YSOK; } else { return YSERR; } } else { return YSERR; } }
static YSRESULT YsClipPolygon3_ByOnePlane (int &newNp,YsVec3 newp[],int bufLen, int np,const YsVec3 p[],const YsVec3 &threshold,int component,YSBOOL removeGreater) { const double *v1,*v2,*thr; double v[3]; YSBOOL in; thr=threshold.GetValue(); if(bufLen>0) { newNp=0; v1=p[0].GetValue(); if(removeGreater==YSTRUE) { if(v1[component]<=thr[component]) { in=YSTRUE; newp[newNp]=p[0]; newNp++; } else { in=YSFALSE; } } else { if(v1[component]>=thr[component]) { in=YSTRUE; newp[newNp]=p[0]; newNp++; } else { in=YSFALSE; } } int i; YSBOOL prevIn; for(i=0; i<np; i++) { v1=p[i].GetValue(); v2=p[(i+1)%np].GetValue(); prevIn=in; if(removeGreater==YSTRUE) { if(v2[component]<=thr[component]) { in=YSTRUE; } else { in=YSFALSE; } } else { if(v2[component]>=thr[component]) { in=YSTRUE; } else { in=YSFALSE; } } if(prevIn!=in && YsEqual(v1[component],v2[component])!=YSTRUE) { if(newNp<bufLen) { int e; for(e=0; e<3; e++) { if(e==component) { v[e]=thr[component]; } else { double x1,y1,x2,y2,x,y; x1=v1[component]; y1=v1[e]; x2=v2[component]; y2=v2[e]; x=thr[component]; y=(y2-y1)/(x2-x1)*(x-x1)+y1; v[e]=y; } } newp[newNp].Set(v[0],v[1],v[2]); newNp++; } else { return YSERR; } } if(in==YSTRUE) { if(newNp<bufLen) { newp[newNp].Set(v2[0],v2[1],v2[2]); newNp++; } else { return YSERR; } } } return YSOK; } return YSERR; }
void FsGui3DInterface::Draw(void) const { needRedraw=YSFALSE; if(type==IFTYPE_BOX) { YsVec3 cen,o; glColor3d(0.0,1.0,0.0); glEnable(GL_LINE_STIPPLE); glLineStipple(1,0xf0f0); glBegin(GL_LINES); glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[0].z()); glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[0].z()); glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[0].z()); glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[0].z()); glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[0].z()); glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[0].z()); glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[0].z()); glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[0].z()); glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[1].z()); glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[1].z()); glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[1].z()); glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[1].z()); glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[1].z()); glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[1].z()); glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[1].z()); glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[1].z()); glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[0].z()); glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[1].z()); glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[0].z()); glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[1].z()); glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[0].z()); glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[1].z()); glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[0].z()); glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[1].z()); glEnd(); glDisable(GL_LINE_STIPPLE); cen=(box_pos[0]+box_pos[1])/2.0; glPointSize(float(markerSize)); glLineWidth(float(linePickingTolerance)); o.Set(box_pos[0].x(),cen.y(),cen.z()); glBegin(GL_POINTS); glVertex3dv(o.GetValue()); glEnd(); DrawLineByPixelLength(o,YsVec3( 1.0,0.0,0.0),pickerLength); DrawLineByPixelLength(o,YsVec3(-1.0,0.0,0.0),pickerLength); o.Set(box_pos[1].x(),cen.y(),cen.z()); glBegin(GL_POINTS); glVertex3dv(o.GetValue()); glEnd(); DrawLineByPixelLength(o,YsVec3( 1.0,0.0,0.0),pickerLength); DrawLineByPixelLength(o,YsVec3(-1.0,0.0,0.0),pickerLength); o.Set(cen.x(),box_pos[0].y(),cen.z()); glBegin(GL_POINTS); glVertex3dv(o.GetValue()); glEnd(); DrawLineByPixelLength(o,YsVec3(0.0, 1.0,0.0),pickerLength); DrawLineByPixelLength(o,YsVec3(0.0,-1.0,0.0),pickerLength); o.Set(cen.x(),box_pos[1].y(),cen.z()); glBegin(GL_POINTS); glVertex3dv(o.GetValue()); glEnd(); DrawLineByPixelLength(o,YsVec3(0.0, 1.0,0.0),pickerLength); DrawLineByPixelLength(o,YsVec3(0.0,-1.0,0.0),pickerLength); o.Set(cen.x(),cen.y(),box_pos[0].z()); glBegin(GL_POINTS); glVertex3dv(o.GetValue()); glEnd(); DrawLineByPixelLength(o,YsVec3(0.0,0.0, 1.0),pickerLength); DrawLineByPixelLength(o,YsVec3(0.0,0.0,-1.0),pickerLength); o.Set(cen.x(),cen.y(),box_pos[1].z()); glBegin(GL_POINTS); glVertex3dv(o.GetValue()); glEnd(); DrawLineByPixelLength(o,YsVec3(0.0,0.0, 1.0),pickerLength); DrawLineByPixelLength(o,YsVec3(0.0,0.0,-1.0),pickerLength); glPointSize(1); glLineWidth(1); if(dragging==YSTRUE) { switch(box_dragging) { case BOX_XMIN: glBegin(GL_LINES); glVertex3d(box_pos[0].x()-infiniteLongLine,cen.y(),cen.z()); glVertex3d(box_pos[0].x()+infiniteLongLine,cen.y(),cen.z()); glEnd(); break; case BOX_XMAX: glBegin(GL_LINES); glVertex3d(box_pos[1].x()-infiniteLongLine,cen.y(),cen.z()); glVertex3d(box_pos[1].x()+infiniteLongLine,cen.y(),cen.z()); glEnd(); break; case BOX_YMIN: glBegin(GL_LINES); glVertex3d(cen.x(),box_pos[0].y()-infiniteLongLine,cen.z()); glVertex3d(cen.x(),box_pos[0].y()+infiniteLongLine,cen.z()); glEnd(); break; case BOX_YMAX: glBegin(GL_LINES); glVertex3d(cen.x(),box_pos[1].y()-infiniteLongLine,cen.z()); glVertex3d(cen.x(),box_pos[1].y()+infiniteLongLine,cen.z()); glEnd(); break; case BOX_ZMIN: glBegin(GL_LINES); glVertex3d(cen.x(),cen.y(),box_pos[0].z()-infiniteLongLine); glVertex3d(cen.x(),cen.y(),box_pos[0].z()+infiniteLongLine); glEnd(); break; case BOX_ZMAX: glBegin(GL_LINES); glVertex3d(cen.x(),cen.y(),box_pos[1].z()-infiniteLongLine); glVertex3d(cen.x(),cen.y(),box_pos[1].z()+infiniteLongLine); glEnd(); break; } } } else if(type==IFTYPE_POINT) { glColor3d(0.0,1.0,0.0); glBegin(GL_LINE_STRIP); switch(point_dlg1->GetBasePlane()) { case 0: glVertex3d(point_pos.x(),point_pos.y(),point_pos.z()); glVertex3d(point_pos.x(),point_pos.y(),0.0); glVertex3d(point_pos.x(),0.0 ,0.0); glVertex3d(0.0 ,0.0 ,0.0); glVertex3d(0.0 ,point_pos.y(),0.0); glVertex3d(point_pos.x(),point_pos.y(),0.0); break; case 1: glVertex3d(point_pos.x(),point_pos.y(),point_pos.z()); glVertex3d(point_pos.x(),0.0 ,point_pos.z()); glVertex3d(0.0 ,0.0 ,point_pos.z()); glVertex3d(0.0 ,0.0 ,0.0); glVertex3d(point_pos.x(),0.0 ,0.0); glVertex3d(point_pos.x(),0.0 ,point_pos.z()); break; case 2: glVertex3d(point_pos.x(),point_pos.y(),point_pos.z()); glVertex3d(0.0 ,point_pos.y(),point_pos.z()); glVertex3d(0.0 ,0.0 ,point_pos.z()); glVertex3d(0.0 ,0.0 ,0.0); glVertex3d(0.0 ,point_pos.y(),0.0); glVertex3d(0.0 ,point_pos.y(),point_pos.z()); break; } glEnd(); auto nom=point_dlg1->GetNormalDirection(); if(POINT_Y==point_dragging) { glPushAttrib(GL_ENABLE_BIT); glLineWidth(1); glEnable(GL_LINE_STIPPLE); glLineStipple(1,0x0003); glBegin(GL_LINES); glVertex3dv((point_pos-nom*infiniteLongLine).GetValue()); glVertex3dv((point_pos+nom*infiniteLongLine).GetValue()); glEnd(); glPopAttrib(); } glLineWidth(float(linePickingTolerance)); DrawLineByPixelLength(point_pos, nom,pickerLength); DrawLineByPixelLength(point_pos,-nom,pickerLength); glLineWidth(float(1)); DrawRectMarker(point_pos,markerSize); } else if(type==IFTYPE_DRAGPOINT) { glColor3d(0.0,1.0,0.0); glPointSize(float(markerSize)); glBegin(GL_POINTS); glVertex3dv(point_pos.GetValue()); glEnd(); glPointSize(1); YsVec3 dragDir[3]; if(YSTRUE==point_dlg2->UseCustomOrientation()) { dragDir[0]=point_dragDir[0]; dragDir[1]=point_dragDir[1]; dragDir[2]=point_dragDir[2]; } else { dragDir[0]=YsXVec(); dragDir[1]=YsYVec(); dragDir[2]=YsZVec(); } const DRAGTARGET pointDragTarget[3]= { POINT_X, POINT_Y, POINT_Z }; int i; for(i=0; i<3; i++) { if(point_dragDirSwitch[i]==YSTRUE) { glLineWidth(float(linePickingTolerance)); DrawLineByPixelLength(point_pos, dragDir[i],pickerLength); DrawLineByPixelLength(point_pos,-dragDir[i],pickerLength); } if(dragging==YSTRUE && point_dragging==pointDragTarget[i]) { glPushAttrib(GL_ENABLE_BIT); glLineWidth(1); glEnable(GL_LINE_STIPPLE); glLineStipple(1,0x0003); glBegin(GL_LINES); glVertex3dv((point_pos-dragDir[i]*infiniteLongLine).GetValue()); glVertex3dv((point_pos+dragDir[i]*infiniteLongLine).GetValue()); glEnd(); glPopAttrib(); } } glLineWidth(1); } else if(type==IFTYPE_SLIDER) { } else if(type==IFTYPE_ROTATION) { if(dragging==YSTRUE) { glColor3d(1.0,0.0,5.0); } else { glColor3d(0.0,1.0,0.0); } glLineWidth(3); glBegin(GL_LINES); glVertex3dv((rot_center+rot_axis*infiniteLongLine).GetValue()); glVertex3dv((rot_center-rot_axis*infiniteLongLine).GetValue()); glEnd(); glLineWidth(1); YsVec3 iVec=rot_iVec; YsVec3 jVec=rot_jVec; YsVec3 kVec=rot_kVec; YsMatrix4x4 mat,axisMat; YsAtt3 att; att.SetForwardVector(rot_axis); att.GetMatrix4x4(axisMat); mat.Initialize(); mat.Rotate(rot_axis.x(),rot_axis.y(),rot_axis.z(),rot_angle); mat=mat*axisMat; mat.Scale(1.0,1.0,rot_mirror); mat.Scale(rot_ref_size,rot_ref_size,rot_ref_size); axisMat.Invert(); mat=mat*axisMat; iVec=mat*iVec; jVec=mat*jVec; kVec=mat*kVec; glBegin(GL_LINES); for(int i=0; i<360; i+=30) { YsVec3 p[2]; double a; a=YsPi*2.0*double(i)/360.0; p[0]=rot_center+iVec*cos(a)+jVec*1.0+kVec*sin(a); p[1]=rot_center+iVec*cos(a)-jVec*1.0+kVec*sin(a); glVertex3dv(p[0].GetValue()); glVertex3dv(p[1].GetValue()); } glEnd(); glBegin(GL_LINE_LOOP); for(int i=0; i<360; i+=10) { double a; YsVec3 p; a=YsPi*2.0*double(i)/360.0; p=rot_center+iVec*cos(a)+jVec*1.0+kVec*sin(a); glVertex3dv(p.GetValue()); } glEnd(); glBegin(GL_LINE_LOOP); for(int i=0; i<360; i+=10) { double a; YsVec3 p; a=YsPi*2.0*double(i)/360.0; p=rot_center+iVec*cos(a)-jVec*1.0+kVec*sin(a); glVertex3dv(p.GetValue()); } glEnd(); // Side drag marker const YsVec3 sideX=rot_drag_dir*rot_ref_size*1.1; const YsVec3 sideY=(rot_drag_dir^rot_axis)*rot_ref_size*1.1; glLineWidth(3); glBegin(GL_LINE_LOOP); for(int i=0; i<360; i+=10) { const double a=YsPi*2.0*double(i)/360.0; YsVec3 p; p=rot_center+sideX*cos(a)+sideY*sin(a); glVertex3dv(p); } glEnd(); if(ROTATION_HANDLE==rot_dragging) { glBegin(GL_LINES); glVertex3dv(rot_center); const YsVec3 radial=rot_ref_size*1.1*(rot_iVec*cos(rot_drag_angle)-rot_kVec*sin(rot_drag_angle)); glVertex3dv(rot_center+radial); glEnd(); } glLineWidth(1); } }