1 / 39

CS 425 Lecture 4

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

lowell
Download Presentation

CS 425 Lecture 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 425 Lecture 4 Jan Allbeck

  2. 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

  3. 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.

  4. Animating Articulated Figures Don’t have time to give a full course, but small introduction to Scene Graphs…

  5. 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

  6. 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…

  7. Scene Graph Elements Generic scene graph node: Each child points to another (lower) scene tree node or to stored geometry. Geometry primitives Geometry-1 Geometry-2 Transformation Matrix [.] Child [vector of tree or geometry pointers] Geometry-3 Geometry-4 …

  8. Sample Scene Graph Shown is a 2D shape built from simple geometric parts in a scene graph of transformations. T3 > > T5 > > T4 G3 I > T1 G1 T2 G2 G3:Unit circle: center (0,0); radius = 1 (1,1) (0,0) G1: (0,0) to (1,0) G2: Unit square

  9. T1 = Rotate by 90° y (0,1) x T2 G2 T4 G3 T1 G1 I > T5 > > T3 > >

  10. T2 = Translate by (-0.5, 0) y x T2 G2 T4 G3 T1 G1 I > T5 > > T3 > >

  11. T3 = Scale by 0.5 in both x and y y x T2 G2 T4 G3 T1 G1 I > T5 > > T3 > >

  12. T4 = Scale by 0.15 in x and y THEN Translate by (0, 0.25) y y x x T2 G2 T4 G3 T1 G1 I > T5 > > T3 > >

  13. T5 = Translate by (-0.6, 0.4) y x T2 G2 T4 G3 T1 G1 I > T5 > > T3 > > Think of this as a new object (group) instance that can itself be transformed.

  14. “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 Tto 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 ...

  15. Scene Graph Example Then transformation of G1 line segment is this matrix product: y I > T5 > > x T3 > > I T1 T3 T5 T4 G3 T2 G2 T1 G1

  16. Scene Graph Example I Then transformation of G2 square is this matrix product: (+ two more …) y I > T5 > > x T3 > > I T2 T3 T5 T4 G3 T2 G2 T1 G1

  17. Scene Graph Example Then transformation of G3 circle is this matrix product: (New radius = 0.15) y I > T5 > > x T3 > > I T4 T5 T4 G3 T2 G2 T1 G1

  18. Scene Graph Example y I x I > T5 > > T3 > > T4 G3 T2 G2 T1 G1 The transformation stack is empty so we are done.

  19. Scene Graph with “Internal” Geometry y I > T5 > > x T3 > > G2 T4 G3 T2 G2 T1 G1 • 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.

  20. 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

  21. Go to the code… Lecture 4.0

  22. 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.

  23. Loading and Placing Objects

  24. 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

  25. Go to the code… Lecture 4.1

  26. 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

  27. 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

  28. Go to the code… Lecture 4.2

  29. 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?

  30. 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.

  31. 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.

  32. 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

  33. 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.

  34. Simple Viewing Geometry V P=(sx,sy) (1,1) V M H φ B (0,0) C U θ A || H B || V Screen coordinates are NDC E A

  35. 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)

  36. Go to the code… Lecture 4.3

  37. Assignment 5 Use Object Picking to help with testing as desired.

  38. Assignments (All Good Object Oriented) • 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. • 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? • 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. • 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. • Use Object Picking to help with testing as desired.

  39. 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.

More Related