I need to make my own "vertex select" routine for a new plugin. So, I create some functions based on those already existent in Wings. The find_vertex converts the 3D coordinate into 2D (viewport coordinates).
The problem is that I'm always getting the Y coordinated with an offset of 75px. This is exactly the height used by title bar+menu bar+button bar by using only the default Geom window.
I couldn't find the "magic" at Wings3d code. Can someone help me?
The problem is that I'm always getting the Y coordinated with an offset of 75px. This is exactly the height used by title bar+menu bar+button bar by using only the default Geom window.
I couldn't find the "magic" at Wings3d code. Can someone help me?
Code:
...
{GX,GY} = wings_wm:local2global(X, Y),
Mode = case raw_pick(GX,GY,Vs) of
...
raw_pick(X0, Y0, Vs0) ->
Trans = wings_u:get_matrices(0, original), % fake call for ID=0 as we force original for MM parameter
Vs = lists:sort(find_vertex(Vs0, X0, Y0, Trans)),
[{Vdist0,{_Xva,_Yva},_V},{_,{_Xvb,_Yvb},_}|_] = Vs,
Vdist = math:sqrt(Vdist0),
(Vdist =< 2.0).
find_vertex(Vs, X, Y, {_,_,{_,_,W,H}}=Trans) ->
lists:map(fun(#vl{v=V}) ->
{Xs,Ys} = Pos = project_vertex(V, Trans),
io:format(" Xs,Ys (~p,~p)\n",[Xs,H-Ys]),
Dx = X-Xs,
Dy = Y-Ys,
{Dx*Dx+Dy*Dy,Pos,V}
end, Vs).