Hi!
I'm not sure of the source of problem so first quick introduction:
1. I want to set Camera properly to show object in Scene3d which is smaller
then QWindow.
2. I want to make proper mapping between qml view 2d coordinates and scene
3d coordinates (for example place some 3d object at location pointed by
mouse click).
I've solved those two issue in example qml code attached to the message.
This example lead to my actual question:
It looks like Scene3d frame buffer is somehow bound to dimension of
QWindow. So If I set Scene3d to be smaller it shows only fragment of
framebuffer. More precisely its part cut from left-bottom corner of buffer
matching scene size. Does it expected behaviour for this class? It leads to
few "funny", additional computations in order to set camera properly.
If I making some mistake by mentioning frame bufffer in this context then I
apologize. Still hope that my example explains what is a problem. I guess
it is worth discussing with someone involved in development and maybe its
not a bug, so I've raised topic here.
Regards,
*Łukasz Korbel *
Senior Software Developer
Email: [email protected]
Skype: lukasz_korbel
*Milo Solutions*
www.milosolutions.com | Facebook <https://www.facebook.com/theMiloSolutions>
| Twitter <https://twitter.com/milosolutions>
Disclaimer: This e-mail and any attachments contain information that may be
privileged or confidential and is the property of Milo Solutions. If you
are not the intended recipient, please notify me immediately by replying to
this e-mail, and then delete it. Any unauthorised
dissemination, distribution, copying or use of this communication is
strictly prohibited. The contents of an attachment to this e-mail may
contain software viruses, which could damage your own computer system.
Although this e-mail and any files attached to it may have been checked
with virus detection software before transmission you should carry out your
own virus checks before opening the attachment. No liability can be
accepted for any damage which you may sustain as a result of software
viruses.
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Scene3D 2.0
import Qt3D 2.0
import Qt3D.Renderer 2.0
Rectangle {
id: win
width: 1280; height: 800
visible: true
color: "black"
property real alpha: 50
property real ratio: width/height
//area to be full shown in scene
property real area_width: 326
property real area_height: 176
//scene central point
property real center_x: area_width / 2 + (height-scene.height)*dx/height
property real center_y: area_height / 2 - (width-scene.width)*dy/width
property real center_z: 0.5 * (win.height/scene.height) * area_width / Math.tan(alpha*Math.PI/360) + position_z
//distance from center to border of visible range
property real dx: (center_z-position_z) * Math.tan(alpha*Math.PI/360)
property real dy: ratio*dx
//scene offset on view y-axis
property real off_y: height > scene.height ? height-scene.height : 0;
//position of sphere
property real position_x: center_x+dx-off_y*2*dx/win.height
property real position_y: center_y+dy
property real position_z: 0
Scene3D {
x: 425; y: 175
width: 300; height: 500
focus: true
aspects: "input"
id: scene
Entity {
id: root
components: FrameGraph {
activeFrameGraph: Viewport {
id: viewport
rect: Qt.rect(0, 0, 1, 1)
clearColor: "white"
CameraSelector {
id : cameraSelector
camera: camera
ClearBuffer {
buffers : ClearBuffer.ColorDepthBuffer
}
}
}
}
Camera {
id : camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: alpha
aspectRatio: ratio
nearPlane : center_z-position_z - 100
farPlane : center_z-position_z
position: Qt.vector3d(center_x,center_y,center_z)
upVector: Qt.vector3d(1.0, 0.0, 0.0)
viewCenter: Qt.vector3d(center_x,center_y,0)
}
PhongMaterial {
id: material
}
SphereMesh {
id: sphereMesh
radius: 10
}
Transform {
id: sphereTransformation
Translate{ translation: Qt.vector3d(position_x,position_y,position_z)}
}
Entity {
components: [sphereMesh, sphereTransformation, material]
}
CuboidMesh{
id: ground
xExtent: area_width
yExtent: area_height
zExtent: 1
xyMeshResolution: Qt.size(2,2)
xzMeshResolution: Qt.size(2,2)
yzMeshResolution: Qt.size(2,2)
}
Transform {
id: groundTransformation
Translate{ translation: Qt.vector3d(area_width/2,area_height/2,0)}
}
Entity {
components: [ground, groundTransformation, material]
}
}
}
MouseArea {
anchors.fill: parent
onClicked: {
position_x = center_x+dx - (mouse.y-scene.y+off_y)*2*dx/win.height
position_y = center_y+dy - (mouse.x-scene.x)*2*dy/win.width
console.log("click ("+mouse.x+","+mouse.y+")")
}
}
}
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development