Download - CS 425 Lecture 4
![Page 1: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/1.jpg)
CS 425 Lecture 4
Jan Allbeck
![Page 2: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/2.jpg)
Outline Navigation? Animate the characters Load and place objects Glue/sticky objects/constraints/carrying stuff
Different types: position, orientation, offsets, cameras, limbs
Containers and locations Actions: PickUp Object, Drop Object, Move Picking Assignments
![Page 3: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/3.jpg)
Navigation How did it go? Issues?
Make sure that your code is in the repository. I need to make sure everyone is making good
progress. I need to look it over and see how good/bad it
is. I’ll try to give some feedback.
![Page 4: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/4.jpg)
Animating Articulated Figures
Don’t have time to give a full course, but small introduction to Scene Graphs…
![Page 5: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/5.jpg)
Grouping Transformations in a Scene Graph Motivation:
Often an object has a part or sub-structure.
Repeated instances of an object need not be separately constructed.
Organize transformations. Organize geometry (shapes).
http://en.wikipedia.org/wiki/Scene_graph http://www.openscenegraph.org/projects/osg
![Page 6: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/6.jpg)
Grouping Transformations in a Scene Graph
Create a directed tree of transformations: Geometry at terminal nodes. Non-terminal nodes become transformed
instances. The same geometry primitive be referenced by
leaf nodes and transformed several times resulting in a scene graph.
Pictorially…
![Page 7: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/7.jpg)
Scene Graph ElementsGeneric scene graph node:
Each child points to another (lower) scene tree node or to stored geometry.
TransformationMatrix [.]
Child [vector oftree or geometry
pointers]
Geometry-1
Geometry-2
Geometry-3
Geometry-4
…
Geometry primitives
![Page 8: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/8.jpg)
Sample Scene GraphShown is a 2D shape built from simple geometric parts in a
scene graph of transformations.
G1: (0,0) to (1,0) G2: Unit square
G3:Unit circle: center (0,0); radius = 1
(1,1)
(0,0)
T3> >
T5> >
T4G3
I>
T1G1
T2G2
![Page 9: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/9.jpg)
T1 = Rotate by 90°
x
y
(0,1)T3
> >
T5> >
T4G3
I>
T1G1
T2G2
![Page 10: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/10.jpg)
T2 = Translate by (-0.5, 0)
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
![Page 11: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/11.jpg)
T3 = Scale by 0.5 in both x and y
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
![Page 12: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/12.jpg)
T4 = Scale by 0.15 in x and y THEN Translate by (0, 0.25)
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
x
y
![Page 13: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/13.jpg)
T5 = Translate by (-0.6, 0.4)
x
y
Think of this as a new object (group) instance that can itself be transformed.
T3> >
T5> >
T4G3
I>
T1G1
T2G2
![Page 14: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/14.jpg)
“Executing” the Scene Graph:INORDER Traversal of the Transformation Tree
Traverse (root.child, I);Traverse (N, T):
T= T•N.transformation; //push (multiply) transformation on right
for (i=0; i<N.child()–1; i++) If N.child[i] points to geometry
then apply T to N.child[i] and draw it else Traverse(N.child[i], T)
Recursion works for you: Go up implicit POP transformation from right: [.] T [.]
For our example, we just created all the transformation matrices.
Watch ...
![Page 15: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/15.jpg)
Scene Graph Example
Then transformation of G1 line segment is this matrix product:
x
y
IT3
> >
T5> >
T4G3
I>
T1G1
T2G2
T5 T3 T1
![Page 16: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/16.jpg)
I
Scene Graph Example
Then transformation of G2 square is this matrix product:
(+ two more …)
x
y
IT3
> >
T5> >
T4G3
I>
T1G1
T2G2
T5 T3 T2
![Page 17: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/17.jpg)
Scene Graph Example
Then transformation of G3 circle is this matrix product:
(New radius = 0.15)
x
y
IT3
> >
T5> >
T4G3
I>
T1G1
T2G2
T5 T4
![Page 18: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/18.jpg)
I
Scene Graph Example
The transformation stack is empty so we are done.
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
![Page 19: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/19.jpg)
Scene Graph with “Internal” Geometry
T3> > G2
T5> >
T4G3
I>
T1G1
T2G2
• We added a third child to the node with T3, pointing to geometry G2 (the unit square). The result is that this instance of G2 is only transformed by (T5 T3): scaled by 0.5 in x and y and then translated by (-0.6,0.4).• This feature can be used to create articulated parts (such as character arms and legs), or objects such as tables with supported (sub-)objects.
x
y
![Page 20: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/20.jpg)
Articulated figures in DarkGDK Everything is done for you…
dbLoadObject: already using dbAppendObject: add more animations dbTotalObjectFrames: how many frame so far dbPlayObject dbLoopObject dbStopObject dbSetObjectSpeed
Should scale to other movement
Do not go in the loop
![Page 21: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/21.jpg)
Go to the code…
Lecture 4.0
![Page 22: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/22.jpg)
Assignment 1
Create classes for loading, storing, replaying, and stopping actions. Keep in mind that some actions loop and some do not. Load all actions for all characters.
![Page 23: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/23.jpg)
Loading and Placing Objects
![Page 24: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/24.jpg)
Loading and Placing Objects Note: characters/agents/NPCs vs. objects In spite of documentation, they must be .x
files In our game, weapons and possibly furniture Already have some examples
![Page 25: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/25.jpg)
Go to the code…
Lecture 4.1
![Page 26: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/26.jpg)
Assignment 2
Add additional symbols (numbers?) for objects to the environment set up (at least 3 types). Consider how to represent these objects. Add another class for non-user, non-NPC objects?C:\Program Files\The Game Creators\Dark GDK\Media\Dark Matter Models\Weapons
![Page 27: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/27.jpg)
Object Constraints (sticky objects) Glue Defines transformational relationships between
objects (Scene Graphs) Position and/or Orientation
All dimensions Just some dimensions
Can include limits Can have offsets Can be turned on and off Limbs Show and hide objects (e.g. PickUp) Sticky cameras
![Page 28: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/28.jpg)
Go to the code…
Lecture 4.2
![Page 29: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/29.jpg)
More about objects Locations and contents can be helpful
Collision detection Picking AI
Types too Actions for our game
PickUp Object Drop Object Face or look at or watch Follow/walk with?
![Page 30: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/30.jpg)
Assignment 3
Write the necessary code/classes to load objects and enable gluing/constraining any object to any other object. Think in terms of the needs of our game and games actions.
![Page 31: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/31.jpg)
Assignment 4
Start building a camera class that takes advantage of the built in camera functions and allows for different perspectives and inputs. Allow for multiple cameras and switching between them. Allow user camera interaction. Allow for first person perspective. Enable the camera to follow a selected character. Allow for an overhead camera. Camera collisions on/off.
![Page 32: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/32.jpg)
Picking Using a mouse to choose an object in the
scene. How does the 2D position relate to your 3D
environment? Involves:
Ray intersection Screen vs. world coordinates Camera transforms Depth buffers
![Page 33: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/33.jpg)
Geometry for Ray-Polygon Intersection Test
Converts NDC screen coordinate to world point to determine 3D ray from view center of projection.
(Thanks to Andrew Glassner) Geometric Situation: Know:
Eye world coordinates: E Viewing vector direction: C (implies viewing
distance is |C| ) Up vector: U Field of view half angles: θ and φ
Output is a screen midpoint and two vectors used to find ray in world coordinate space.
![Page 34: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/34.jpg)
Simple Viewing Geometry
UB
A
V
HM
(0,0)
(1,1)
θ
φ
EA || HB || VScreen coordinates are NDC
P=(sx,sy)
C
![Page 35: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/35.jpg)
Algorithm for Needed Vectors and P A C U (be sure this is well defined) B A C (B is now in the correct plane) M E C (now have midpoint of screen) H (A |C| tan θ) / |A| (rescale A to H) V (B |C| tan φ) / |B| (rescale B to V)
Given the origin as shown, any point in NDC is (sx, sy) [0 sx 1; 0 sy 1)]
E.g., if frame buffer is 320 pixels wide by 240 pixels high, then (50, 75) would map to (50/329, 75/239).
P M (2sx 1) H (2sy 1) V The ray equation is thus:
R E t(P E) / |P E| (ray direction D is normalized P E)
![Page 36: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/36.jpg)
Go to the code…
Lecture 4.3
![Page 37: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/37.jpg)
Assignment 5
Use Object Picking to help with testing as desired.
![Page 38: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/38.jpg)
Assignments (All Good Object Oriented)1. Create classes for loading, storing, replaying, and stopping
actions. Keep in mind that some actions loop and some do not. Load all actions for all characters.
2. Add additional symbols (numbers?) for objects to the environment set up (at least 3 types). Consider how to represent these objects. Add another class for non-user, non-NPC objects?
3. Write the necessary code/classes to load objects and enable gluing/constraining any object to any other object. Think in terms of the needs of our game and games actions.
4. Start building a camera class that takes advantage of the built in camera functions and allows for different perspectives and inputs. Allow for multiple camera and switching between them. Allow user camera interaction. Allow for first person perspective. Enable the camera to follow a selected character. Allow for an overhead camera. Camera collisions on/off.
5. Use Object Picking to help with testing as desired.
![Page 39: CS 425 Lecture 4](https://reader035.vdocuments.net/reader035/viewer/2022062500/568151ff550346895dc03dde/html5/thumbnails/39.jpg)
Next? More on interfaces Multiple windows NPC AI Animating objects
Drop object Read in environments Need good character models Clean up animations Exchange code to check interface and find
problems.