91
GUI using C++ and Qt YHL 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt Yung-Hsiang Lu [email protected]

ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

Embed Size (px)

Citation preview

Page 1: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 1

ECE 462 C++ and Java

Lab Exercise 03Graphical User Interface

using C++ and Qt

Yung-Hsiang [email protected]

Page 2: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 2

Install Qt in Your Computer

Page 3: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 3

Page 4: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 4

Page 5: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 5

Scroll Down

Page 6: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 6

Install Qt in Linux

Page 7: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 7

for Linux

Page 8: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 8

Install in Linux

Page 9: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 9

Page 10: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 10

Page 11: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 11

Page 12: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 12

Page 13: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 13

installation complete

Page 14: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 14

execute Qt designer

Page 15: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 15

Page 16: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 16

To compile a Qt program:1. qmake -project2. qmake3. make

Page 17: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 17

Page 18: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 18

Install Qt in Windows

Page 19: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 19

Install in Windows

Page 20: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 20

Page 21: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 21

Page 22: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 22

Page 23: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 23

Page 24: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 24

Page 25: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 25

Page 26: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 26

Page 27: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 27

Page 28: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 28

Page 29: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 29

Page 30: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 30

Page 31: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 31

Page 32: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 32

Page 33: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 33

Page 34: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 34

Page 35: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 35

Page 36: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 36

Page 37: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 37

Page 38: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 38

Page 39: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 39

Qt Documentation

Page 40: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 40

Page 41: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 41

Page 42: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 42

Page 43: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 43

Page 44: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 44

Page 45: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 45

Page 46: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 46

Sample Qt Program

Page 47: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 47

Page 48: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 48

Page 49: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 49

Page 50: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 50

Page 51: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 51

1. qmake –project2. qmake3. make

executable

Page 52: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 52

Page 53: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 53

Develop Qt Project in Netbeans

Page 54: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 54

Page 55: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 55

Page 56: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 56

Page 57: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 57

Page 58: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 58

Page 59: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 59

Page 60: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 60

Page 61: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 61

Page 62: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 62

Page 63: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 63

Add Buttons and Labels

Page 64: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 64

Page 65: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 65

Page 66: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 66

Page 67: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 67

Page 68: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 68

Page 69: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 69

Handle User Inputs (Signals)

Page 70: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 70

signal = event (in Java)slot = handler

Page 71: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 71

Page 72: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 72

Add Paddles and a Bouncing Ball

Page 73: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 73

Page 74: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 74

Page 75: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 75

Page 76: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 76

Page 77: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 77

Page 78: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 78

Page 79: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 79

Page 80: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 80

Page 81: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 81

Page 82: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 82

Move BallTrack Mouse

Detect Collision

Page 83: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 83

Law of Reflection

• S: surface of collision• N: normal vector, N ⊥ S• I: incident vector• R: reflection vector• a: angle between I and N• b: angle between R and N• law of reflection: a = b• If N, I, and R are unit vectors (|N| = |I| = |R| = 1),

R - I = 2 N ⋅ (-I), here ⋅ is the inner product.⇒ R = I - 2 N ⋅ I

ab

N

S

IR

Page 84: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 84

Ball Hits Paddle

• Both are circles. The normal vector is the vector connecting the center of the ball and the center of the paddle.

• Collision occurs when the distance between the two centers is smaller than the sum of the radii.

N

Page 85: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 85

Page 86: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 86

Page 87: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 87

Page 88: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 88

Page 89: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 89

Page 90: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 90

Exercise Requirements

1. Make the right paddle follow the ball's vertical coordinate.

2. Detect collision between the right paddle and the ball and make the ball bounce.

3. Update the ball's position and direction.

Page 91: ECE 462 C++ and Java Lab Exercise 03 Graphical User ...€¦ · YHL GUI using C++ and Qt 1 ECE 462 C++ and Java Lab Exercise 03 Graphical User Interface using C++ and Qt ... YHL GUI

GUI using C++ and QtYHL 91

Submission: A zip file of the CVS repository

Remember to commit all changes first.Submit this exercise only.

Do not submit any other exercise. Do not submit a wrong zip file.