The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

Similar documents
Ambient and Diffuse Light

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

The Critical-Path Algorithm

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Minimal Spanning Trees

The Projection Matrix

The Projection Matrix

The Graphics Pipeline

Implementing Linked Lists

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

List Iterator Implementation

Recursive Descent Parsers

Stacks and their Applications

Density Curves Sections

Rotations and Translations

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

The Decreasing-Time Algorithm

Solving Recursive Sequences by Iteration

The Graphics Pipeline

The Pairwise-Comparison Method

Function Definition Syntax Tree

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Programming Languages

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Sampling Distribution Examples Sections 15.4, 15.5

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

Binary Tree Applications

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

The x86 Instruction Set

Street-Routing Problems

Scope and Parameter Passing

Scheduling and Digraphs

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

Programming Languages

The Class Construct Part 1

The Mesh Class. Lecture 26. Robb T. Koether. Wed, Oct 28, Hampden-Sydney College

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

Dynamic Allocation of Memory

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

The Traveling Salesman Problem Brute Force Method

The x87 Floating-Point Unit

Scope and Parameter Passing

Dynamic Allocation of Memory

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Friends and Unary Operators

Building the Abstract Syntax Trees

The Plurality-with-Elimination Method

LR Parsing - Conflicts

List Iterators. Lecture 34 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 24, 2013

Recursive Linked Lists

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

The Coefficient of Determination

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

Displaying Distributions - Quantitative Variables

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Inheritance: The Fundamental Functions

The Traveling Salesman Problem Nearest-Neighbor Algorithm

The x86 Architecture

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

LR Parsing - The Items

The Normal Distribution

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Mon, Feb 22, 2016

Magnification and Minification

The Mesh Class. Lecture 23. Robb T. Koether. Hampden-Sydney College. Wed, Oct 18, 2017

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

The Class Construct Part 2

Introduction to Compiler Design

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Computer Graphics Hands-on

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

Fundamental Data Types

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

The Standard Template Library Classes

XQuery FLOWR Expressions Lecture 35

PHP Queries and HTML Forms Lecture 23

Recognition of Tokens

Binary Tree Implementation

Inheritance: The Fundamental Functions

The CYK Parsing Algorithm

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Binary Tree Implementation

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

The Traveling Salesman Problem Cheapest-Link Algorithm

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

Lecture 29 Section Wed, Apr 1, 2009

Nondeterministic Programming in C++

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

JFlex Regular Expressions

Introduction to Databases

Insertions, Deletions, and Updates

Transcription:

The Model Stack Lecture 8 Robb T. Koether Hampden-Sydney College Wed, Sep 6, 2017 Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 1 / 19

Outline 1 Drawing Rectangle Man 2 The ModelStack Class 3 Manipulating the Stack 4 Assignment Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 2 / 19

Outline 1 Drawing Rectangle Man 2 The ModelStack Class 3 Manipulating the Stack 4 Assignment Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 3 / 19

Drawing Rectangle Man We will draw an object (Rectangle Man) that is created entirely from our basic rectangle (unit square), using transformations. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 4 / 19

Drawing Rectangle Man 72 66 60 54 48 42 36 30 24 18 12 6 0-36 -30-24 -18-12 -6 0 6 12 18 24 30 36 Rectangle Man Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 5 / 19

Drawing Rectangle Man 72 66 60 HEAD_HGT HEAD_WID HEAD_ANGLE 54 48 42 36 ARM_HGT TORSO_HGT TORSO_WID ARM_ANGLE ARM_WID 30 24 18 HAND_HGT LEG_HGT HAND_ANGLE LEG_WID HAND_WID 12 6 FOOT_HGT FOOT_WID 0-36 -30-24 -18-12 -6 0 6 12 18 24 30 36 Rectangle Man's Dimensions Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 5 / 19

The Rectangle Man Parameters The Rectangle Man Parameters // The foot const float FOOT_WID = 12.0f; const float FOOT_HGT = 4.0f; // The leg const float LEG_WID = 6.0f; const float LEG_HGT = 22.0f; const float LEG_GAP = 4.0f;. Assign a symbolic name to every parameter. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 6 / 19

The Rectangle Man Parameters The Rectangle Man Parameters // The foot const float FOOT_WID = 12.0f; const float FOOT_HGT = 4.0f; // The leg const float LEG_WID = 6.0f; const float LEG_HGT = 22.0f; const float LEG_GAP = 4.0f;. Assign a symbolic name to every parameter. Don t argue. Just do it. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 6 / 19

Outline 1 Drawing Rectangle Man 2 The ModelStack Class 3 Manipulating the Stack 4 Assignment Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 7 / 19

The ModelStack Class I have created a class named ModelStack. As an object, it is a stack of 4 4 matrices. The matrix on top of the stack is the current matrix. The function push() will push a copy of the current matrix onto the stack, thereby duplicating it. The function pop() will pop the top matrix off the stack. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 8 / 19

The ModelStack Class The ModelStack Class ModelStack(); ModelStack() Constructs an ModelStack object with an empty stack. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 9 / 19

The ModelStack Class The ModelStack Class void init(); void push(); void pop(); init() Initializes the stack to the identity matrix. push() Pushes a copy of the top matrix onto the stack, thereby duplicating it. pop() Pops the top matrix off the stack. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 10 / 19

The ModelStack Class The ModelStack Class void setmodelloc(gluint m_loc); void setnormalloc(gluint n_loc); setmodelloc() Stores the shader location of the model matrix in the ModelStack object. setnormalloc() Stores the location of the normal matrix in the ModelStack object. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 11 / 19

The ModelStack Class The ModelStack Class void mult(mat4 m); void toshader(gluint loc); mult(mat4 m) Replaces top matrix with itself right multiplied by m. toshader() Copies the model matrix and, if normals is true, the normal matrix to the shaders. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 12 / 19

The Modelview Stack Pushing and popping are used to remember previous transformations. The basic pattern is Push the current matrix onto the stack (to remember it). Perform a series of geometric transformations and draw an object. Pop the current matrix off the stack, thereby restoring the former current matrix. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 13 / 19

Outline 1 Drawing Rectangle Man 2 The ModelStack Class 3 Manipulating the Stack 4 Assignment Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 14 / 19

Manipulating the Stack Initialize the stack ModelStack model_stack(...); // Global model_stack.setmodelloc(model_loc); // In init(); model_stack.init(); // In display() Declare the stack globally. After defining the variable model_loc in the init() function, store its value in the ModelStack object. Initialize it in the display() function before any drawing is done. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 15 / 19

Manipulating the Stack Drawing an Object model_stack.push(); { model_stack.mult(translate(2.0f, 0.0f, 0.0f)); model_stack.mult(rotate(90.0f, 0.0f, 0.0f, 1.0f)); model_stack.mult(scale(1.0f, 4.0f, 1.0f)); model_stack.toshader(); drawrectangle(); } model_stack.pop(); Transform and draw an object without losing the previous transformation. The effect is v = CM T R S v, where CM is the current model matrix. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 16 / 19

Use the ModelStack class to create Rectangle Man. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 17 / 19

Outline 1 Drawing Rectangle Man 2 The ModelStack Class 3 Manipulating the Stack 4 Assignment Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 18 / 19

Assignment Assignment Assignment 8. Robb T. Koether (Hampden-Sydney College) The Model Stack Wed, Sep 6, 2017 19 / 19