Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3D picking Point on plane

Qt3D picking Point on plane

Scheduled Pinned Locked Moved Solved General and Desktop
1 Posts 1 Posters 236 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by Pl45m4
    #1

    I have a custom 3D scene with a planeEntity (QPlainMesh) as ground plate. To add more objects, I thought of selecting points (by RayCasting?!) and construct the new object there.

    I've tried QScreenRayCaster and QRayCaster, but no one seems to work as expected.
    I trigger my rayCast on Qt3DWindow::mousePressEvent.

    How can I check if the ray has hit the plane or not? Currently I'm getting rayCast hits as soon as I click somewhere (doesnt matter where)

    Do I really need to set a QLayer on every entity I want to hit with my ray?

    I followed this (https://stackoverflow.com/questions/52666741/qscreenraycaster-not-finding-entity-what-am-i-doiong-wrong)

    It's my first project in Qt3D, so dont blame me if I made beginner's mistakes :-)

    Custom3DScene::Custom3DScene()
        : Qt3DExtras::Qt3DWindow()
    {
    
        // Root entity
        m_rootEntity = new Qt3DCore::QEntity();
    
        m_rayCaster = new Qt3DRender::QRayCaster(m_rootEntity);
        m_rayCaster->setRunMode(Qt3DRender::QAbstractRayCaster::SingleShot);
    
    
        Qt3DRender::QLayer *pickableLayer = new Qt3DRender::QLayer(m_rootEntity);
        m_rayCaster->addLayer(pickableLayer);
    
    
        // Camera and Light
        // [ ... ]
    
    
        setRootEntity(m_rootEntity);
    
    
        // Plane data, transform and mesh
        // [ ... ]
    
        // Plane
        m_planeEntity = new Qt3DCore::QEntity(m_rootEntity);
        m_planeEntity->addComponent(planeMesh);
        m_planeEntity->addComponent(planeMaterial);
        m_planeEntity->addComponent(planeTransform);
        m_planeEntity->addComponent(pickableLayer);
    
        // Add rayCaster to rootEntity
        m_rootEntity->addComponent(m_rayCaster);
    
        connect(m_rayCaster, &Qt3DRender::QRayCaster::hitsChanged, this, &Custom3DScene::printCast); // just to see if ray was fired
    
    }
    

    TIA


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved