|GLC_lib & GLC_Player Forums
|3D coordinates projection to snapshot image
|Page 1 of 1|
|Author:||aurelien [ Mon Jun 29, 2015 2:26 am ]|
|Post subject:||3D coordinates projection to snapshot image|
I am rendering a model and taking a snapshot (image) of that scene (pretty much like GLC_Player takes snapshots), so that I can see the whole scene in the image.
What I would like to do now, is to match the world bounding box corners (3D coordinates) to the corresponding 2D coordinates in the generated image.
I saw APIs to get projection matrices from GLC_Context, GLC_Camera or GLC_Viewport, but I'm not too sure which one to use.
So far, I did a simple test setting the camera's target to the world bounding box center (so that it matches the center of my generated snapshot) and trying to project the bounding box center 3D coordinates using projection matrices from those API and expecting to find the 2D coordinates of the center of my image, however I didn't get relevant results.
Hoping to find some help here, how would you do this?
|Author:||aurelien [ Mon Jun 29, 2015 8:29 am ]|
|Post subject:||Re: 3D coordinates projection to snapshot image|
We only need the snapshot dimensions as well as the combination of the camera's view matrix with the projection matrix. GLC_lib actually gives this combination directly with GLC_Viewport::compositionMatrix(). This will allow to project the point from the world to the clipping space of [-1, 1] range. We finally convert that to the image coordinate system, where (0, 0) is the top left corner.
So, to transform a point P(x, y, z) from the world to a 2D point P'(x', y') on the snapshot image :
We first compute the point Pc(xc, yc, zc) as Pc = GLC_Viewport::compositionMatrix() * P(x, y, z)
Then, for a snapshot image of width W and height H :
x' = (( xc + 1 ) / 2.0) * W
y' = (( 1 - yc ) / 2.0) * H
(zc value is dropped as we get flat image)
Source : http://webglfactory.blogspot.com.au/201 ... creen.html
|Page 1 of 1||All times are UTC|
|Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group