Notifications
Clear all

[Closed] Calculate vertex 2d position?

 xcx

How I can calculate vertex 2d position or any 3d point 2d position?

3 Replies
 xcx

I found something like this in manuals and I modify that code. This should be return me objects postion in 2d space. Seen any bugs or errors?


  (
  	local screen_width = 0
  	local screen_height = 0
  	
  	screen_width=RenderWidth
  	screen_height=RenderHeight
  	
  	
  	theMesh = selection[1]
  	thePos = (theMesh.pos)* viewport.getTM()
  	
  	screen_origin = mapScreenToView [0,0] (thePos.z) [screen_width,screen_height]
  	format "Screen origin %
" screen_origin
  	
  	end_screen = mapScreenToView [screen_width,screen_height] (thePos.z) [screen_width,screen_height]
  	format "Screen end %
" end_screen
  	
  	world_size = screen_origin-end_screen
  	format "World size %
" world_size
  	
  	x_aspect = screen_width/(abs world_size.x)
  	format "X aspect %
" x_aspect
  	
  	y_aspect = screen_height/(abs world_size.y)
  	format "Y aspect %
" y_aspect	
  	
  	screen_coords = point2 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y))) 
  	format "Screen coord %
" screen_coords
  )
  

hey xcx, that’s a bit too complicated. This should do it:

gw.setTransform(Matrix3 1) 

gw.wTranspoint (polyop.getVert $.baseobject aVertex node:$)

cheers,
CML

 xcx

So simple! Darn
Thanks man. My code works too, but that is way more simpler.