PDA

View Full Version : Print Particle Screen positions to file.

 JHN01-05-2009, 12:29 PMThat shouldn't be too hard, just calculate back to a float value (0...1) that way you can multiply it with every size you want. This below code I use to transport 3d positions to 2d screenspace for use in fusion. 3Dto2D tracker data sort of speech. pX = stringStream "" pY = stringStream "" sX = gw.getWinSizeX() as float -- Get WinSize X sY = gw.getWinSizeY() as float -- Get WinSize X rPA = renderPixelAspect -- Get Render Pixel Aspect rX = RenderWidth as float -- Get Render Pixels X rY = RenderHeight as float -- Get Render Pixels Y rY = rY * ( 1 / rPA ) -- Correct for aspect ratio rratio = ( sX / rX ) / (sY / rY) -- Get Ratio if rratio >= 1. then ( -- If Ratio is bigger than 1 then ratio = sY / rY -- Use Y ratio for calculations ) else ( ratio = sX / rX -- Else use X ratio for calculations ) -- end if xMin = ( sX - ( rX * ratio ) ) / 2 -- Get x minimum value yMin = ( sY - ( rY * ratio ) ) / 2 -- Get y minimum value ct = animationRange.end as integer / TicksPerFrame -- Animation range end as integer gw.setTransform (matrix3 1) -- Set gw View transform to zero for i = 0 to ct do ( --p = gw.TransPoint ( at time i obj.position ) -- Get 3D point in 2D screenspace slidertime = i -- Move viewport cause of moving cams p = gw.TransPoint ( obj.position ) -- Get 3D point in 2D screenspace x = ( p.x - xMin ) / ( sX - ( xMin * 2) ) -- Convert View space to Render space for X y = 1 - ( p.y - yMin ) / ( sY - ( yMin * 2 ) ) -- idem for Y format "% %\n" ( i as float ) x to:pX format "% %\n" ( i as float ) y to:pY ) -- end for Be aware this assume topleft as [0,0]. At least I hope this gets you on your way if I understood the question right and you want to convert 3D position to 2D screen data. -Johan
ZeBoxx2
01-05-2009, 12:43 PM
o_O
There are time-travellers among us

DaveWortley
01-05-2009, 01:32 PM
I'm working on a still image with a few thousand particles in. I need to keep a log of the positions of the particles on the render.

My particles are all on one plane. and the bottom left corner of the plane is at 0,0

I can print the x.pos and y.pos and multiply this to get a fairly accurate position as am rendering with an isometric camera, but have to deal with bleed.

Is there a way to print the screen position relative to the render size...

Dave

DaveWortley
01-05-2009, 02:55 PM
Cheers for that.

Something appears to be wrong with cgtalk at the mo...

ZeBoxx2
01-05-2009, 03:35 PM
just to add.. beware of using the floats if you're going to be printing to file... format "%" <float> only gives you so much precision. Compound that with the already-quirky float from the 3D->2D function and odds are that on larger plates you will run into precision issues.

DaveWortley
01-05-2009, 04:00 PM
My image will be about 8000x6000 pixels, so yes I guess I might run into precision problems.

I think I might be able to do it without doing any complex 3d-2d vector work as the camera is isometric and all the particles are on one plane. I just need to do some multiplication and add some numbers onto their X and Y co-ords. Doesn't have to be pixel perfect and is only for one frame.

Interesting to see how one could calculate it's 3d-2d position though.

I thought there might have been a way using screen co-ords system to get an X and Y pos.

CGTalk Moderation
01-05-2009, 04:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.