[Interest] Strange flicker when moving a camera with the mouse in Qt Quick 3D
joao morgado
joaodeusmorgado at yahoo.com
Fri Oct 22 03:01:59 CEST 2021
Hi
I have a View3D with MouseArea on top, I'm moving a camera when pressing and moving the mouse. It works but I get a strange flicker because of mapTo3DScene() strange results.
A small example project is here
CameraMove.zip
|
|
| |
CameraMove.zip
|
|
|
Relevant code of moving the camera is here:
property vector3d mousePosition
property vector3d worldPos3D_old: worldPos3D
property vector3d worldPos3D
property vector3d cameraPos
//! [mouse area]
MouseArea {
id: ma
anchors.fill: view
//! [mouse area]
onPressed: {
cameraPos = mainCamera.position
mousePosition = Qt.vector3d(mouseX, mouseY, 0)
worldPos3D_old = worldPos3D = view.mapTo3DScene(mousePosition)
}
onMouseYChanged: {
updateCamera(mouseX, mouseY)
}
function updateCamera( mouseX_, mouseY_){
mousePosition = Qt.vector3d(mouseX_, mouseY_, 0)
worldPos3D = view.mapTo3DScene(mousePosition)
console.log("worldPos3D: "+worldPos3D + " ; mousePosition: "+mousePosition )
mainCamera.position.x = cameraPos.x - worldPos3D.x + worldPos3D_old.x
mainCamera.position.y = cameraPos.y - worldPos3D.y + worldPos3D_old.y
//mainCamera.position = cameraPos - worldPos3D + worldPos3D_old
}
}//MouseArea
-----------------------
The lines
mousePosition = Qt.vector3d(mouseX_, mouseY_, 0)
console.log("worldPos3D: "+worldPos3D + " ; mousePosition: "+mousePosition )
shows me strange values, when moving the mouse, in worldPos3D returned by mapTo3DScene(), see below
qml: worldPos3D: QVector3D(152.83, 7.24083, 190) ; mousePosition: QVector3D(568.372, 216.524, 0)
qml: worldPos3D: QVector3D(141.141, 1.82567, 190) ; mousePosition: QVector3D(568.372, 216.88, 0)
qml: worldPos3D: QVector3D(152.474, 7.24082, 190) ; mousePosition: QVector3D(568.016, 216.88, 0)
qml: worldPos3D: QVector3D(140.785, 1.46959, 190) ; mousePosition: QVector3D(567.66, 217.237, 0)
qml: worldPos3D: QVector3D(152.117, 6.88474, 190) ; mousePosition: QVector3D(567.304, 217.593, 0)
qml: worldPos3D: QVector3D(140.428, 1.46959, 190) ; mousePosition: QVector3D(566.948, 217.593, 0)
qml: worldPos3D: QVector3D(151.761, 6.17257, 190) ; mousePosition: QVector3D(566.592, 218.305, 0)
qml: worldPos3D: QVector3D(140.072, 1.1135, 190) ; mousePosition: QVector3D(566.236, 218.661, 0)
See the last 3 values of mousePosition for example, the x value, they show coerent mouse move:
566.948 -> 566.592 -> 566.236But the equivalent world coordinates stored in worldPos3D by mapTo3DScene() make no sense to me:140.428 -> 151.761 ->140.072
The values are leaping wich explain the huge flicker. Any ideias why I get these strange values ?
ThanksJoão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20211022/30b8e3c0/attachment.html>
More information about the Interest
mailing list