Posted By

martinB on 02/06/09


Tagged

world viewpoint coordinate


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


Map world point to viewport coordinates


Published in: Maxscript 






Original code by Borislav 'Bobo' Petrov

Expand | Embed | Plain Text
  1. (
  2. fn mapWorldToScreen thePoint =
  3. (
  4. local thePos = thePoint * viewport.getTM()
  5. local screenSize = getViewSize()
  6. local screen_origin = mapScreenToView [0,0] (thePos.z) screenSize
  7. local end_screen = mapScreenToView screenSize (thePos.z) screenSize
  8. local world_size = screen_origin-end_screen
  9. local x_aspect = screenSize.x/(abs world_size.x)
  10. local y_aspect = screenSize.y/(abs world_size.y)
  11. point3 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y))) 0
  12. )
  13.  
  14. -- now iterate over each selected object and display it's viewport position
  15. for theObj in selection do
  16. (
  17. gw.setTransform (matrix3 1)
  18. gw.wText (mapWorldToScreen theObj.pos) theObj.name color:green
  19. )
  20. gw.enlargeUpdateRect #whole
  21. gw.updateScreen()
  22. )

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: martinB on February 16, 2009

An alternative method using the gw struct:

pos = object.pos gw.setTransform(Matrix3 1) screenpos = gw.wTranspoint pos

-- screenpos == [0,0] in the top-left corner

Posted By: trentf on February 7, 2010

how do you do the opposite?

You need to login to post a comment.

Download royalty free graphics