diff --git a/funcext/tvclib/utvclgraphics.tsf b/funcext/tvclib/utvclgraphics.tsf index 858b2e8..a02ea8c 100644 --- a/funcext/tvclib/utvclgraphics.tsf +++ b/funcext/tvclib/utvclgraphics.tsf @@ -2764,6 +2764,342 @@ type tg_const = class() ////////////// end implementation +type tg_3d_box = class() + function create(); + begin + ftheta := 0; + falpha := 0; + f_changed := 0; + flinesindex := array( + (0,1), + (1,2), + (2,3), + (3,0), + + (4,5), + (5,6), + (6,7), + (7,4), + + + (0,4), + (1,5), + (2,6), + (3,7) + + + ); + fvectorsindex := array( + (0,1,2,3), + (0,4,7,3), + (0,1,5,4), + (1,5,6,2), + (2,6,7,3)//, + //(4,5,6,7), + + ); + fbounds := array(0,0,200,200); + fsizes := array(200,200,200); + frotemt := eye(3); + fvcenter := array(100,100,100); + fzoombounds := array((0,200),(0,200),(0,200)); + //fvectors :=init_vecs(200,200,200) ; + faces := array(); + FRates := array(1,1,1); + frevers := array(1,1,0); + end + + function set_trans(t,a); //设置转换角度 + begin + if (t=ftheta) and (falpha=a) then return ; + ftheta := t; + falpha := a; + c := cos(a); + s := sin(a); + c1 := cos(t); + s1 := sin(t); + frotemt := array((0,1,0),(1,0,0),(0,0,1)):*array((c,s,0),(-s,c,0),(0,0,1)):*array((1,0,0),(0,c1,s1),(0,-s1,c1)); + //frotemt := array((1,0,0),(0,c1,s1),(0,-s1,c1)):*array((c,s,0),(-s,c,0),(0,0,1)):*array((0,1,0),(1,0,0),(0,0,1)); + f_changed := true; + end + function refresh_box();//重算坐标框架 + begin + if f_changed then + begin + f_changed := 0; + recalc_size(); + end + end + function transxyz(x,y,z,_x,_y,_z); //旋转数据 + begin + r := array((x,y,z)):*frotemt; + _x := r[0,0]; + _y := r[0,1]; + _z := r[0,2]; + end + function untransxyz(x,y,z,_x,_y,_z); + begin + r := array((x,y,0)):/frotemt; + _x := r[0,0]; + _y := r[0,1]; + _z := r[0,2]; + end + function zoom_to_xy(x,y,z,_x,_y,_z); //---------- + begin + if frevers[0] then x0 := fsizes[0]/2-(x-fzoombounds[0,0])/FRates[0]; + else + x0 := (x-fzoombounds[0,0])/FRates[0] -fsizes[0]/2; + if frevers[1] then y0 := fsizes[1]/2-(y-fzoombounds[1,0])/FRates[1]; + else y0 := (y-fzoombounds[1,0])/FRates[1] -fsizes[1]/2; + if frevers[2] then z0 := fsizes[2]/2-(z-fzoombounds[2,0])/FRates[2]; + else z0 := (z-fzoombounds[2,0])/FRates[2] -fsizes[2]/2; + transxyz(x0,y0,z0,x1,y1,_z); + x1 +=fvcenter[0]; + y1 +=fvcenter[1]; + _x := x1; + _y := y1; + end + property theta read ftheta; + property alpha read falpha; + property bounds read fbounds write set_bounds; + property zoombounds read gs_zoombounds write gs_zoombounds; + property size read get_size; + + function paint_box(cvs); + begin + r := array(); + cvs.pen.color := 0xff0000; + lines := array(); + ps2 := array(); + inpoints := array(); + echo "\r\n>>>",(abs(ftheta/pi()) mod 2); + if (abs(ftheta/pi()) mod 2)=0 then + begin + for i:= 0 to 3 do + begin + if point_in_rgn(fvectors[4:7],fvectors[i]) then + begin + inpoints[length(inpoints)] := i; + end + end + end else + begin + for i:= 4 to 7 do + begin + if point_in_rgn(fvectors[0:3],fvectors[i]) then + begin + inpoints[length(inpoints)] := i; + end + end + end + hd := array(); + for i,v in flinesindex do + begin + + ps := fvectors[v]; + if (inpoints intersect v) then hd[i] := true; + for j,vj in ps do + lines[i,j] := vj[0:1]+fvcenter; + //cvs.draw_polyline().points(ps1).draw(); + end + + + for i,v in lines do + begin + ps1 := v; + if hd[i] then cvs.pen.style := 1; + else cvs.pen.style := 0; + cvs.draw_polyline().points(ps1).draw(); + end + + return ; + for i,v in fvectorsindex do + begin + ps := fvectors[v,0:1]; + ps1 := array(); + for j,vj in ps do + ps1[j] := vj+fvcenter; + ps1[j+1] := ps1[0]; + cvs.draw_polyline().points(ps1).draw(); + //break; + end + end + private + //////////长宽高//////////////////// + fvcenter; //中心 + ////////////////////// + fvectorsindex; //定点次序 + flinesindex;// + ftheta; + falpha; + frotemt; + fbounds; + f_changed; + fzoombounds; + fvectors; + FRates; + fsizes; + frevers; + private + function gs_zoombounds(idx,v); //小刻度线 + begin + if ifarray(idx) then + begin + if ifarray(v) then + begin + for i,vi in idx do + begin + gs_zoombounds(vi,v[vi]); + end + end else + begin + r := array(); + for i,vi in idx do + begin + return gs_zoombounds(vi); + end + end + end + if ifarray(v) and ifnumber(v[0]) and (v[0]v then + begin + fbounds := v; + f_changed := true; + end + end + function get_size(); + begin + return fsizes; + end + function get_new_w_h(w1,h1,w,h,z); + begin + z1 := (w1+h1)/2; + z := z1; + w := w1; + h := h1; + while true do + begin + ps := init_vecs(h,w,z); + bd := zeros(2,2); + for i,v in ps do + begin + transxyz(v[0],v[1],v[2],_x,_y,_z); + bd[0,0] := min(_x,bd[0,0]); + bd[0,1] := max(_x,bd[0,1]); + bd[1,0] := min(_y,bd[1,0]); + bd[1,1] := max(_y,bd[1,1]); + end + bw := bd[0,1]-bd[0,0]; + bh := bd[1,1]-bd[1,0]; + if bw