Slide 1

Slide 1 text

14. Arcball control Tatsuya Yatagawa

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Rotation by arcball control ◼ Get unit vector to arcball sphere (getVector) Computer Graphics Course @Waseda University 5

Slide 6

Slide 6 text

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)

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Translation by arcball control ◼ Transformation from screen to object space Computer Graphics Course @Waseda University 10

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Switch controlled parameters by mouse button ◼ Call corresponding update method for each mode Computer Graphics Course @Waseda University 17

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Result ◼ Arcball control allow us intuitive object transformation! Computer Graphics Course @Waseda University Default Rotation Translation Scaling 19

Slide 20

Slide 20 text

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