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. Problem with Items coordinate system

Problem with Items coordinate system

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 270 Views
  • 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.
  • G Offline
    G Offline
    Giuseppe97
    wrote on last edited by Giuseppe97
    #1

    While making a videogame I have had a problem due to the fact that probably I misunderstood how items coordinates system works. In particular in order to know the position in the scene of the mushroom(goomba) in the picture posted below, which is a gridded screenshot of my game, I wrote this line of code:

    std::cout << goomba->scenePos().toPoint().x() << " " << goomba->scenePos().toPoint().y() ;
    

    bea658c2-4aa8-4aa2-8e80-daccf6d3b43a-image.png
    Now every box in the grid is a square of 16*16 pixels and I set scene's origin so that it's in the top-left corner of that grid in particular it's the top-left corner of the square with number 0.
    As I have read in Qt Documentation and according to this picture of Summerfiled's book on Qt
    b66b41ea-834d-4030-a6d8-b826cb5f9431-image.png

    I have learned that an item's position is the coordinate of the item's center point in its parent's coordinate system but since the mushroom is a top level item its position is in scene coordinates .
    The code I wrote prints the top-left corner of the item in scene coordinates as if it is the position of the item but according to what I know it should print the center point of the item ,in scene coordinates, which I know to be its position.
    So what is the position of a top level item? Is it the top-left corner or the center point of the item?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you point where in the documentation you saw that center coordinate ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Giuseppe97
        wrote on last edited by Giuseppe97
        #3

        Hi. Here

        7e8f4a0b-d16f-438a-a3db-51dea0f3ef68-image.png

        I am making confusion between an item's position and its center point probably beacuse I misunderstood this statement in documentation

        beb8ce3b-6d5b-48be-b425-3d20aee0cb73-image.png

        In particular if the scene is the parent of the item what is the item's position?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          This just means that every item has it's own coordinate system with 0,0 as it's center point used for transformations. So If you want to rotate an item in it's , you should put it's center at 0,0 - otherwise rotate() will not do what you expect.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • G Offline
            G Offline
            Giuseppe97
            wrote on last edited by
            #5

            Ok , I understood that. But if the item is a top level one its position in the scene is identified by its top-left point expressed in scene coordinates, am I right?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Yes, that's correct.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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