Upgrade to Pro — share decks privately, control downloads, hide ads and more …

14. Arcball control

Tatsuya Yatagawa
June 04, 2021
380

14. Arcball control

Tatsuya Yatagawa

June 04, 2021
Tweet

Transcript

  1. What is arcball control? ◼ Intuitive control for object transformation

    ◼ Intuitively “rotate” objects by mouse dragging. ◼ It is often combined with translation and scaling controls. ◼ It is commonly used in CAD and DCC (digital content creation) software such as Maya. Computer Graphics Course @Waseda University Default Rotation Translation Scaling 2
  2. Arcball control algorithm ◼ How can mouse drag be converted

    to object translation? ◼ Mouse drag → motion in “screen space” ◼ Object translation → motion in “object space” → Inverse translation from screen space to object space Computer Graphics Course @Waseda University Object space coordinate World space coordinate Camera space coordinate Screen space coordinate Mouse drag Object translation Model matrix View matrix Projection matrix 3
  3. Rotation by arcball control ◼ Parameters required for rotation ◼

    Axis of rotation ◼ Angle of rotation → They can be computed from motion on “arcball sphere” ◼ Screen and arcball sphere Computer Graphics Course @Waseda University Required rotation translate red vector to blue vector 4
  4. Rotation by arcball control ◼ Get unit vector to arcball

    sphere (getVector) Computer Graphics Course @Waseda University 5
  5. Rotation by arcball control ◼ Compute axis and angle in

    object space Computer Graphics Course @Waseda University 6 * “4.0” is arbitrary scaling (for comfortable control)
  6. Remark ◼ Is arcball sphere in screen space? ◼ Inverse

    perspective projection distort sphere. → For intuitive control, assume arcball is in camera space. Computer Graphics Course @Waseda University 引用: コンピュータグラフィックス [改訂新版] (コンピュータグラフィックス編集委員会 著) P. 43 7
  7. Translation by arcball control ◼ Parameters for translation ◼ 3D

    vector for object translation in object space. → Translate two endpoints of mouse motion to object space. Then take their difference. ◼ Notice ◼ You shouldn’t take difference of screen space positions because depth information is lost! ◼ Alternatively, you should first transform two screen space positions back to world space, then take difference! Computer Graphics Course @Waseda University 8
  8. Translation by arcball control ◼ Get depth value at clicked

    pixels ◼ Depth information can be read with glReadPixels. ◼ For simplicity, gravity center of the object is used instead in sample program. ◼ Code snippet Computer Graphics Course @Waseda University 9
  9. Translation by arcball control ◼ Transformation from screen to object

    space Computer Graphics Course @Waseda University 10
  10. Scaling by arcball control ◼ Parameters for scaling ◼ Ratio

    of scaling → Calculate the ratio from amount of mouse motion. ◼ This time, it’ll be calculated by mouse wheel or mouse drag during middle button press. Computer Graphics Course @Waseda University 11
  11. Register mouse wheel event ◼ glfwSetScrollCallback ◼ Callback for mouse

    wheel ◼ Its parameters represent amount of wheel (not mouse position) ◼ Y coordinate corresponds to ordinary mouse wheel. Computer Graphics Course @Waseda University New 12
  12. Scaling by arcball control ◼ Scaling control by dragging with

    middle button press ◼ Calculate the ratio from horizontal mouse move. ◼ In sample program, scale up when mouse move to upward. ◼ Scaling update Computer Graphics Course @Waseda University 13
  13. Switch controlled parameters by mouse button ◼ Role for each

    button (changed arbitrarily) ◼ Left click → Rotation ◼ Right click → Translation ◼ Middle button / wheel → Scaling ◼ Code snippet Computer Graphics Course @Waseda University 14
  14. Switch controlled parameters by mouse button ◼ Process for mouse

    click ◼ Enable arcball control. ◼ Keep click position as a variable. Computer Graphics Course @Waseda University 15
  15. Switch controlled parameters by mouse button ◼ Process for mouse

    move ◼ Update mouse click position. ◼ Perform transformation by arcball control. Computer Graphics Course @Waseda University 16
  16. Switch controlled parameters by mouse button ◼ Call corresponding update

    method for each mode Computer Graphics Course @Waseda University 17
  17. Switch controlled parameters by mouse button ◼ Process for mouse

    release ◼ Initialize mouse click positions to avoid unexpected behavior. ◼ Disable arcball control. Computer Graphics Course @Waseda University 18
  18. Result ◼ Arcball control allow us intuitive object transformation! Computer

    Graphics Course @Waseda University Default Rotation Translation Scaling 19
  19. Exercise 14-1 ◼ Implement a program in which only the

    selected object can be controlled using arcball control. ◼ Prepare two simple cubes to be controlled. ◼ You should prepare an object class which manages translation parameters for each object. Computer Graphics Course @Waseda University 20