intro to computer graphics: just enough c++ › courses › fall2019 › tutorial_material ›...

13
Intro to Computer Graphics: Just enough C++ Updated: September 10 th , 2019 Slides by: Philmo Gu

Upload: others

Post on 25-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Intro to Computer Graphics:Just enough C++

Updated: September 10th, 2019

Slides by: Philmo Gu

Page 2: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Java vs C++

Source: https://www.educba.com/c-plus-plus-vs-java/

Page 3: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Java vs C++

Source: https://www.educba.com/c-plus-plus-vs-java/

Page 4: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Hello World!

For C++ For Java

Page 5: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Preprocessors

• Separate programs that manipulate the text in each code file

Page 6: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Namespace

• An area code for identifier to be unique

Source: https://www.learncpp.com/cpp-tutorial/4-3b-namespaces/

Page 7: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Namespace

• An area code for identifier to be unique

Source: https://www.learncpp.com/cpp-tutorial/4-3b-namespaces/

Page 8: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Overloading Operators

• Operation = mathematical calculation involving one or more inputs that produces a new value (output)• Operator = symbol(s) that specify an operation

Source: https://www.learncpp.com/cpp-tutorial/introduction-to-literals-and-operators/

Page 9: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Struct and Classes

• By Default:• Struct = Public members

• Class = Private members

Page 10: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Values and Pointers

• Pointer = memory address to a value• & = address-of operator

• * = dereference operator

Source: https://www.learncpp.com/cpp-tutorial/67-introduction-to-pointers/

Page 11: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Values and Pointers

• Pointer = memory address to a value• & = address-of operator

• * = dereference operator

Source: https://www.learncpp.com/cpp-tutorial/67-introduction-to-pointers/

Page 12: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Example Code

Page 13: Intro to Computer Graphics: Just enough C++ › courses › Fall2019 › Tutorial_Material › … · Intro to Computer Graphics: Just enough C++ Updated: September 10th, 2019 Slides

Exercises

• Create a pattern of nested squares and diamonds, and print out the vertices of each level

• Create the Sierpinski triangle using triangles, and print out the vertices of each iteration

Image Credit: CPSC 453 (Fall 2018) Assignment 1: Points, Lines and Triangles by Sonny Chan