I have some problem with converting 3d pos to rendered pixel 2d coord... Vertex render..

Hi everyone.. I have looked at many tutorials and mainly the vertex renderer example from Bobo in the maxscript help. I have created a function that I thought worked in the beginning but I have a odd error... all values in the Y direction is wrong

I use the following function to do this... but get the wrong y coord.. and it feels a bit scaled since the closer to 0 I get the better the result...

fn PixelPos inputPoint3D =
(
local screen_width, screen_height
!REG3XP1!>screen_width=RenderWidth as float
screen_height=RenderHeight as float 

thePos = inputPoint3D * viewport.getTM()
screen_origin = mapScreenToView [0,0] (thePos.z) [screen_width,screen_height]
end_screen = mapScreenToView [screen_width,screen_height] (thePos.z) [screen_width,screen_height]
world_size = screen_origin-end_screen
x_aspect = screen_width/(abs world_size.x)
y_aspect = screen_height/(abs world_size.y)
screen_coords = point2 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y)))
 
return screen_coords	
)

Any suggestions why it behaves like this would be very appreciated. The sceenshot is from a little wpf util that adds markers at specific x,y positions... (and yes I have also checked the values in max they are wrong there too;-)

If or when you look at the screenshot... it is a plane in max and the red dots should align with the verts.. but does not do that in the Y direction

AttachmentSize
3d-to-2d-problem.png164.18 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anton Berg's picture

Found the problem... was incorrect pixel aspect...

I found the problem I had by pure coincidence choosen a preset in 3dsmax which had a pixel aspect of 0.9 which scaled the values...

When set this to 1.0 everything works fine!

OgmaSoul3D
Anton Berg
anton[at]os3d.se

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.