Kino Posted February 20, 2016 Share Posted February 20, 2016 How can I get the word position of a point I'm seeing through a camera and on the camera's screen plane. Let's say the camera resolution is 1280x720 pixels ( 0,0 at top left and 1280,720 at bottom right), I want to know the world position of a point which will be at the pixel position of 300,200 at render output. Will this differ if I have Orthographic or Perspective camera? I think fromNDC / ptransform functions are the saviors here but I can't quite figure out how exactly.In general I'd appreciate if anyone can explain the world space, object space and camera space in Houdini in comparison which conventions that OpenGL has for instance. I read here and there that in H world space is actually camera space (or is it only in Mantra and not SOPs?). Also in OpenGL NDC is [-1,1] in all three dimensions, how is this in H?Cheers Quote Link to comment Share on other sites More sharing options...
Shinjipierre Posted February 20, 2016 Share Posted February 20, 2016 Here's an example, if that's what you're looking for. just change the W,H and pixels parms (w = x position, h = y pos, pixels = how many pixels around the area you'll see) screenspace.hipnc 1 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted February 20, 2016 Share Posted February 20, 2016 Use fromNDC(camera, position). Position consist of x and y in 0..1 range and z as depth in units. Tests for Detail wrangle: // Create point at the center of the camera view in 3 meters away. addpoint(0, fromNDC("/obj/cam1", set(0.5, 0.5, -3))); // Camera frustum. Set reasonable clipping distances like 0.2 to 10. string cam = "/obj/cam1"; float near = -chf("/obj/cam1/near"); float far = -chf("/obj/cam1/far"); addpoint(0, fromNDC(cam, set(0.0, 0.0, near))); addpoint(0, fromNDC(cam, set(1.0, 0.0, near))); addpoint(0, fromNDC(cam, set(1.0, 1.0, near))); addpoint(0, fromNDC(cam, set(0.0, 1.0, near))); addpoint(0, fromNDC(cam, set(0.0, 0.0, far))); addpoint(0, fromNDC(cam, set(1.0, 0.0, far))); addpoint(0, fromNDC(cam, set(1.0, 1.0, far))); addpoint(0, fromNDC(cam, set(0.0, 1.0, far))); // Create quadrangle using points. void quad(int pt1, pt2, pt3, pt4) { int geo = geoself(); int num = addprim(geo, "poly"); addvertex(geo, num, pt1); addvertex(geo, num, pt2); addvertex(geo, num, pt3); addvertex(geo, num, pt4); } quad(3, 2, 1, 0); quad(4, 5, 6, 7); quad(1, 5, 4, 0); quad(0, 4, 7, 3); quad(3, 7, 6, 2); quad(2, 6, 5, 1); Quote Link to comment Share on other sites More sharing options...
Kino Posted February 21, 2016 Author Share Posted February 21, 2016 Thanks a lot for the suggestion Shinjipierre but it really didn't work out for me. The use of the hi-rez grid and using its points' uv seemed to do the job in some cases but it's not a generic solution and it's an overkill IMO. What f1480187 suggested was more what I was after.Thanks again f1480187 for helping me out, your solution did the job beautifully. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.