cs 425 lecture 4
DESCRIPTION
CS 425 Lecture 4. Jan Allbeck. 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 - PowerPoint PPT PresentationTRANSCRIPT
CS 425 Lecture 4
Jan Allbeck
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
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.
Animating Articulated Figures
Don’t have time to give a full course, but small introduction to Scene Graphs…
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
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…
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
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
T1 = Rotate by 90°
x
y
(0,1)T3
> >
T5> >
T4G3
I>
T1G1
T2G2
T2 = Translate by (-0.5, 0)
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
T3 = Scale by 0.5 in both x and y
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
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
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
“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 ...
Scene Graph Example
Then transformation of G1 line segment is this matrix product:
x
y
IT3
> >
T5> >
T4G3
I>
T1G1
T2G2
T5 T3 T1
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
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
I
Scene Graph Example
The transformation stack is empty so we are done.
x
y
T3> >
T5> >
T4G3
I>
T1G1
T2G2
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
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
Go to the code…
Lecture 4.0
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.
Loading and Placing Objects
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
Go to the code…
Lecture 4.1
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
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
Go to the code…
Lecture 4.2
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?
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.
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.
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
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.
Simple Viewing Geometry
UB
A
V
HM
(0,0)
(1,1)
θ
φ
EA || HB || VScreen coordinates are NDC
P=(sx,sy)
C
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)
Go to the code…
Lecture 4.3
Assignment 5
Use Object Picking to help with testing as desired.
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.
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.