When I'm testing my code tend to be a mess,
but may be this can help.
What you see here is basically the relation the
vertexes of a mesh should have between them to move
as in cloth simulation,
use arrows to move the system
but may be this can help.
What you see here is basically the relation the
vertexes of a mesh should have between them to move
as in cloth simulation,
use arrows to move the system
Graphics3D 640,480,16,2 Function interpolate#(v#,a#,b#,c#,d#) Return c+(((v-a)*(d-c))/(b-a)) End Function c1=CreateSphere() PositionEntity c1,-10,-7.5,15 Dim c1f#(3) c2=CreateSphere() PositionEntity c2,-5,-7.5,15 EntityColor c2,255,0,0 Dim c2f#(3) c3=CreateSphere() PositionEntity c3,0,-7.5,15 EntityColor c3,0,255,0 Dim c3f#(3) c4=CreateSphere() PositionEntity c4,5,-7.5,15 EntityColor c4,0,0,255 Dim c4f#(3) c5=CreateSphere() PositionEntity c5,10,-7.5,15 Dim c5f#(3) cam=CreateCamera() PositionEntity cam,0,0,-20 fps=CreateTimer(30) mesh=CreateMesh() s=CreateSurface(mesh) AddVertex(s,EntityX(c1,1),EntityY(c1,1),EntityZ(c1,1)) ;0 AddVertex(s,EntityX(c1,1),EntityY(c1,1)+1,EntityZ(c1,1)) ;1 AddVertex(s,EntityX(c2,1),EntityY(c2,1),EntityZ(c2,1)) ;2 AddVertex(s,EntityX(c2,1),EntityY(c2,1)+1,EntityZ(c2,1)) ;3 AddTriangle(s,0,1,2) AddTriangle(s,3,2,1) EntityFX mesh,16 WireFrame 1 While Not KeyDown(1) WaitTimer(fps) If KeyHit(28) vert=vert+1 EndIf If KeyDown(200) c1f(1)=c1f(1)+.1 c5f(1)=c5f(1)+.1 EndIf If KeyDown(208) c1f(1)=c1f(1)-.1 c5f(1)=c5f(1)-.1 EndIf If KeyDown(203) c1f(0)=c1f(0)-.1 c5f(0)=c5f(0)-.1 EndIf If KeyDown(205) c1f(0)=c1f(0)+.1 c5f(0)=c5f(0)+.1 EndIf ; TranslateEntity c2,(((EntityX(c1)+5)-EntityX(c2))/20),((EntityY(c1)-EntityY(c2))/20)-.05,0 ; TranslateEntity c3,(((EntityX(c2)+5)-EntityX(c3))/20),((EntityY(c2)-EntityY(c3))/20)-.05,0 ;Provocar fuerza en C2: ; dist#=1/EntityDistance(c2,c1) ; vectorX#=EntityX(c2)-EntityX(c1) ; vectorY#=EntityY(c2)-EntityY(c1) ; vectorZ#=EntityZ(c2)-EntityZ(c1) ; vectorX_U#=vectorX/dist ; vectorY_U#=vectorY/dist ; vectorZ_U#=vectorZ/dist ; c2f(0)=c2f(0)-(c1f(0)*vectorX_U*.05) ; c2f(1)=c2f(1)-(c1f(1)*vectorY_U*.05) ; c2f(2)=c2f(2)-(c1f(2)*vectorZ_U*.05) attract#=.2 dist#=EntityDistance(c1,c2) force#=interpolate(dist,0,10,attract,-attract) vectorX#=EntityX(c2)-EntityX(c1) vectorY#=EntityY(c2)-EntityY(c1) vectorZ#=EntityZ(c2)-EntityZ(c1) vectorX_U#=vectorX/dist vectorY_U#=vectorY/dist vectorZ_U#=vectorZ/dist c2f(0)=c2f(0)+(force*vectorX_U) c2f(1)=c2f(1)+(force*vectorY_U) c2f(2)=c2f(2)+(force*vectorZ_U) ;------------------------- dist#=EntityDistance(c3,c2) force#=interpolate(dist,0,10,attract,-attract) vectorX#=EntityX(c3)-EntityX(c2) vectorY#=EntityY(c3)-EntityY(c2) vectorZ#=EntityZ(c3)-EntityZ(c2) vectorX_U#=vectorX/dist vectorY_U#=vectorY/dist vectorZ_U#=vectorZ/dist c3f(0)=c3f(0)+(force*vectorX_U) c3f(1)=c3f(1)+(force*vectorY_U) c3f(2)=c3f(2)+(force*vectorZ_U) ;------------------------- ;------------------------- dist#=EntityDistance(c3,c2) force#=interpolate(dist,0,10,attract,-attract) vectorX#=EntityX(c2)-EntityX(c3) vectorY#=EntityY(c2)-EntityY(c3) vectorZ#=EntityZ(c2)-EntityZ(c3) vectorX_U#=vectorX/dist vectorY_U#=vectorY/dist vectorZ_U#=vectorZ/dist c2f(0)=c2f(0)+(force*vectorX_U) c2f(1)=c2f(1)+(force*vectorY_U) c2f(2)=c2f(2)+(force*vectorZ_U) ;------------------------- ;------------------------- dist#=EntityDistance(c3,c4) force#=interpolate(dist,0,10,attract,-attract) vectorX#=EntityX(c4)-EntityX(c3) vectorY#=EntityY(c4)-EntityY(c3) vectorZ#=EntityZ(c4)-EntityZ(c3) vectorX_U#=vectorX/dist vectorY_U#=vectorY/dist vectorZ_U#=vectorZ/dist c4f(0)=c4f(0)+(force*vectorX_U) c4f(1)=c4f(1)+(force*vectorY_U) c4f(2)=c4f(2)+(force*vectorZ_U) ;------------------------- ;------------------------- dist#=EntityDistance(c3,c4) force#=interpolate(dist,0,10,attract,-attract) vectorX#=EntityX(c3)-EntityX(c4) vectorY#=EntityY(c3)-EntityY(c4) vectorZ#=EntityZ(c3)-EntityZ(c4) vectorX_U#=vectorX/dist vectorY_U#=vectorY/dist vectorZ_U#=vectorZ/dist c3f(0)=c3f(0)+(force*vectorX_U) c3f(1)=c3f(1)+(force*vectorY_U) c3f(2)=c3f(2)+(force*vectorZ_U) ;------------------------- ;------------------------- dist#=EntityDistance(c5,c4) force#=interpolate(dist,0,10,attract,-attract) vectorX#=EntityX(c4)-EntityX(c5) vectorY#=EntityY(c4)-EntityY(c5) vectorZ#=EntityZ(c4)-EntityZ(c5) vectorX_U#=vectorX/dist vectorY_U#=vectorY/dist vectorZ_U#=vectorZ/dist c4f(0)=c4f(0)+(force*vectorX_U) c4f(1)=c4f(1)+(force*vectorY_U) c4f(2)=c4f(2)+(force*vectorZ_U) ;------------------------- smooth=40 gravity#=.1 c1f(0)=c1f(0)+(-c1f(0)/smooth) c1f(1)=c1f(1)+(-c1f(1)/smooth) ; c1f(1)=c1f(1)-gravity c1f(2)=c1f(2)+(-c1f(2)/smooth) TranslateEntity c1,c1f(0),c1f(1),c1f(2) c2f(0)=c2f(0)+(-c2f(0)/smooth) c2f(1)=c2f(1)+(-c2f(1)/smooth) c2f(1)=c2f(1)-gravity c2f(2)=c2f(2)+(-c2f(2)/smooth) TranslateEntity c2,c2f(0),c2f(1),c2f(2) c3f(0)=c3f(0)+(-c3f(0)/smooth) c3f(1)=c3f(1)+(-c3f(1)/smooth) c3f(1)=c3f(1)-gravity c3f(2)=c3f(2)+(-c3f(2)/smooth) TranslateEntity c3,c3f(0),c3f(1),c3f(2) c4f(0)=c4f(0)+(-c4f(0)/smooth) c4f(1)=c4f(1)+(-c4f(1)/smooth) c4f(1)=c4f(1)-gravity c4f(2)=c4f(2)+(-c4f(2)/smooth) TranslateEntity c4,c4f(0),c4f(1),c4f(2) c5f(0)=c5f(0)+(-c5f(0)/smooth) c5f(1)=c5f(1)+(-c5f(1)/smooth) ; c5f(1)=c5f(1)-gravity c5f(2)=c5f(2)+(-c5f(2)/smooth) TranslateEntity c5,c5f(0),c5f(1),c5f(2) VertexCoords s,0,EntityX(c1,1),EntityY(c1,1),EntityZ(c1,1) VertexCoords s,1,EntityX(c1,1),EntityY(c1,1)+1,EntityZ(c1,1) VertexCoords s,2,EntityX(c2,1),EntityY(c2,1),EntityZ(c2,1) VertexCoords s,3,EntityX(c2,1),EntityY(c2,1)+1,EntityZ(c2,1) UpdateWorld RenderWorld Text 40,40,vectorX_U+" , "+vectorY_U+" , "+vectorZ_U Text 40,60,EntityDistance(c1,c2) Flip Wend MoveMouse 400,300 End