|
Post by tobiasmarciszko on Nov 19, 2019 16:13:13 GMT
Hi!
I'm investigating Qt3D to add a realtime "preview" layer before rendering the scene at hand. I already have a "wireframe" mode that shows the bounding boxes of the objects. For the wireframe mode I am projecting the world coordinates to the 2D plane like so:
I am now looking at adding another preview layer using OpenGL or (as of now) Qt3D since I am using a QML UI. However, what I am missing is the description of the projection we're using. I understand we have a view transform in the Camera we've implemented but I don't really see that mapping between the Camera and a projection matrix that is mentioned elsewhere.
But what is the projection matrix that we end up using? I'm struggling to get a perfect match between the rendered image and the OpenGL view I am trying to use
Regards,
Tobias
|
|
|
Post by tobiasmarciszko on Nov 20, 2019 12:00:57 GMT
I managed to define a OpenGL projection matrix that I'm using for the projection. The only thing I still don't get is that it doesn't match. I ended up "tweaking" the scale factor with a magic number to make it look decent...
The code I ended up with looks as follows (QML and Javascript :
projectionType: Render.CameraLens.CustomProjection fieldOfView: 45 nearPlane : 0.1 farPlane : 100.0
position: Qt.vector3d(raytracer.fromX, raytracer.fromY, -raytracer.fromZ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) viewCenter: Qt.vector3d(0, 0, 0)
property var n: nearPlane property var f: farPlane
property var scale: Math.tan(fieldOfView * 0.5 * Math.PI/180) * n / 1.3
property var t: scale property var r: liveImageItem.width/liveImageItem.height * scale property var l: -r property var b: -t
projectionMatrix: Qt.matrix4x4( (2*n)/(r-l), 0, (r+l)/(r-l), 0, 0, (2*n)/(t-b), (t+b)/(t-b), 0, 0, 0, -(f+n)/(f-n), -(2*f*n)/(f-n), 0, 0, -1, 0 )
The "1.3" on the scale variable is the magic number that kind of does the trick... See this tweet for a gif of the visuals:
|
|
|
Post by Jamis on Nov 22, 2019 22:32:27 GMT
Cool! Sadly, I don't know the answer to the projection matrix question. I wrestled with that briefly at one point, too, but didn't spend enough time on it to figure it out. The ray tracer's projection matrix is implicit in the way screen is configured for the rays to be shot through.
|
|