Week 7: SceneNodes and SceneTrees
Link to source code (zipped)
- Example 1: Allowing arbitrary
tree depth
- SceneNode:
- Now define a name, so
we can identify them
- A ArmSegment
that can be place anywhere (no rotation support)
- How to
create/instantiate this to create something strange looking?
- Lesson:
- Draw out your object
in a convenient coordinate space (Modeling Coordinate Space)
- Define user
transformable parts (these are the SceneNode pxf)
- Construct the scene
tree, and that is that!
- Talk about instancing, (e.g., pre-fab in Unity3D may be
implemented this way
- How can we have
multiple complex geometries and yet ensure not consume too much memory?
- Example 2:
Simple animated objects
- Simplest way: update
transform continuously
- ArmSegment:
- Define a update
function: rotate the center square and pulsing the top rectangle
- Notice: how to “pulse”
- We must remember the
original size of renderables
- Center blue circle:
pulsing between 0.7 and 0.4
- ClassExample object, new update
function
- Calls all of the
update of ArmSegment (all three of them!)
- That’s why all
three are updating J
- Hardcoded some other
cheesy animations
- Lesson:
- Animation is nothing
but calling the update() function during timer
handler from the MainController!
- Each object in the
world, if they want to animate, they should define an update function.
- Example
3: Object position
- Notice debugging (learn
this trick for your MP5): Draw Control Points
- Check on/off to see: 4
squares (Gray, Redish, Blue-ish, and Green-ish)
- Gray: always follow
the mouse
- Redish: top of TopChild, controls left arm pulsing and top spinning
- Blueish: mid of LeftChild, controls ArmSegment
update
- Greenish: mid of
Parent head, controls head spinning
- Notice:
- If you adjust the
slider bars, the squares will be “out of place” (this is on
purpose)
- If you move your
mouse into the main view, the square “snap” to their proper
locations
- Point: show that we
can compute ALL of the positions in WC
- ClassExamxple:
- toggleHeadSpin, toggleArmRotate,
toggleChildUpdate
- Define functions and
allow toggling of these
- update()
function: only animate with
toggle is on
- ClassExample_MouseOver:
- withInBound() function check for
position distance with kBoundTol (in WC)
- dectectMouseOver:
- HeadPos: is (0,0) after Head
Translation
- Note: scale/rotate
will not change this, so, simply compare!
- leftArm’s blue circle:
- center position sees
two transforms:
- 1. leftArm xfrom
- 2. parent xform
- Note: the order of matrix
multiplication (what happens if we switch this)?
- topArm’s red rotated rect:
- center position sees
three transforms:
- 1. topArm xform
- 2. leftArm xform
- 3. parent xform
- Again, note the
order!
- Stop head spin: click
on the center of head
- Stop all children:
click on center of the blue circle on left arm
- Stop left arm
rotation/pulsing: click on center of top arm red rotated rect
- Lesson:
- We need to know what
are the transforms our shapes go through
- We need to know how to
composite these transforms together