PickedVertex()

Blitz3D Forums/Blitz3D Programming/PickedVertex()

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This will be better, as it returns the closet vertex to the pick, rather than you having to click on one exactly.

function pickedVertex()
local sd#=999999,srf
local vert,v,tri
    srf=pickedSurface()
    tri=pickedTriangle()
    for v=0 to 2
        vert=triangleVertex(srf,tri)
        xd#=vertexX(srf,vert)-pickedX()
        yd#=vertexY(srf,vetr)-pickedY()
        zd#=vertexZ(srf,vert)-pickedZ()
        td#=sqr(xd*xd+yd*yd+zd*zd)
        if td<sd
            sd=td
            rVert=vert
        endif
    next
    return rVert
end function


Another cheaper way for mouse click, would be to project each vert into screen space(cameraproject) and then just do a quick distance check from screen coords to mouse coords...no idea if it'll be any quicker.