Select 2 edges of model and display X Dimension and Y Dimension...
Blitz3D Forums/Blitz3D Programming/Select 2 edges of model and display X Dimension and Y Dimension...
| ||
Has anyone developed any code that you can share that will allow a user to select any 2 edges of the model on the screen and display the X and Y dimensions between the 2 edges the user selected? I need to provide a way for the user to select any 2 edges. The 2 edges could be horizontal or vertical. After selecting these 2 edges, I need to have the X and Y distance between these two edges displayed as text on the screen. Currently, I have 2 cylinders that the user can move around on the screen until they touch the model. When they touch the model, I calculate the distance in X and Y the 2 cylinders are apart from one another. I was hoping for a better solution. Thanks, David |
| ||
something coded on the fly, probably contains a tons or errors ^^;@pCamera : camera used for picking ;@pX,pY : 2D coordinates of the picking ;@pMesh: mesh to check for edge detection. ;@pPixelRange : threshold (in pixel) to test the distance to the edge ;@pResult : array ; pResult[0] = picked Mesh ; pResult[1] = picked Surface ; pResult[2] = Picked Triangle Index ; pResult[2] = Picked Vertex index ; if vertex index is 0, the edge is 0->1 ; if vertex index is 1, the edge is 1->2 ; if vertex index is 2, the edge is 2->0 ;@Returns : True if an edge has been picked. Function PickEdge% (pCamera, pX,pY, pMesh, pPixelRange%, pResult%[3]) Local NearestD# = -1; ; for each surfaces For is = 1 To CountSurfaces(pMesh) l_Surf=GetSurface(pMesh, is) ; for each triangles For t = 0 to CountTriangles(l_Surf)-1 Local l_X#[3], l_Y#[3] ; store projected coords ; for each edges of the triangle For i= 0 to 2 v = TriangleVertex(l_Surf, t, i) ; transform coords of v to world TFormPoint (VertexX(l_Surf, v), VertexY(l_Surf, v), VertexZ(l_Surf, v), pMesh, 0) CameraProject(pCamera, TFormedX(),TFormedY(),TFormedZ()) l_X[i] = ProjectedX() l_Y[i] = ProjectedY() Next For i = 0 To 2 Local d# = DistancePL2D(X,Y, l_X[i],l_Y[i], l_X[(i+1)Mod(3)],l_Y[(i+1)Mod(3)]) If (d>=0) And (d<pPixelRange) if ((NearestD<0) Or (d<NearestD)) Result[0] = pMesh Result[1] = lSurf Result[2] = t Result[3] = i EndIf EndIf Next Next Return NearestD>=0 End Function Function DistancePL2D( px#,py#, ax#,ay#,bx#,by# ) Local ix# = bx-ax, iy#=by-ay Local d# = (bx-ax)*(bx-ax)+(by-ay)*(by-ay) Local u# = ( ( ( px-ax)*ix)+((py-ay)*iy) ) /( d ) If ((u<0.0) Or (u>1.0)) Then Return -1 ix=ax+u*ix iy=ay+u*iy Return Sqr((px-ix)*(px-ix)+(py-iy)*(py-iy)) End Function So, once you picked an edge, store the result pick a second edge -> distance between edges is : ;e1 = result of first pick ;e2 = result of second pick Function DistanceEdges#(e1%[3], e2%[3]) Local M0 = e1[0], M1 = e2[0] Local S0 = e1[1], S1 = e2[1] Local V00 = TriangleVertex(S0, e1[2], e1[3]); Local V01 = TriangleVertex(S0, e1[2], (e1[3]+1)Mod(3)); Local V10 = TriangleVertex(S1, e2[2], e2[3]); Local V11 = TriangleVertex(S1, e2[2], (e2[3]+1)Mod(3)); TFormPoint (VertexX(S0, V00), VertexY(S0, V00), VertexZ(S0, V00), M0, 0) Local x00# TFormedX(), y00# = TFormedY(), z00#=TFormedZ() TFormPoint (VertexX(S0, V01), VertexY(S0, V01), VertexZ(S0, V01), M0, 0) Local x01# TFormedX(), y01# = TFormedY(), z01#=TFormedZ() TFormPoint (VertexX(S1, V10), VertexY(S1, V10), VertexZ(S1, V10), M1, 0) Local x10# TFormedX(), y10# = TFormedY(), z10#=TFormedZ() TFormPoint (VertexX(S1, V11), VertexY(S1, V11), VertexZ(S1, V11), M1, 0) Local x11# TFormedX(), y11# = TFormedY(), z11#=TFormedZ() ; use any formula here to return the nearest point between the two edges Return YourFormula(x00,y00,z00, x01,y01,z01, x10,y10,z10, x11,y11,z11) End Function According to your needs, I let you find a formula that will match your requirements (if you want the shortest distance of edges, or distance between center of edges etc ...) |