7
CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

Embed Size (px)

Citation preview

Page 1: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

CSC 480 / 580

Computer Graphics

K. Kirby

Scene Graphsand Slerping Quaternions

NKU CSC 480 KIRBY

Page 2: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

class Widget{public: void dump() const ; virtual void spin(); virtual void toss() =0 ; void flip() { toss() ; } // ... } ;

Remembering OO

Widget

FastWidgetSlowWidget

SlowWidget sw ;FastWidget fw ;

play( sw ) ;play( fw ) ;

void play( Widget* p ){ p->toss() ; // ...}

void play( Widget* p ){ p->toss() ; // ...}

class SlowWidget : public Widget{public: void toss() { /*...*/ } ; void spin() { /*...*/ } ; // ...} ;

class FastWidget : public Widget{public: void toss() { /*...*/ } ;// ...} ;

NKU CSC 480 KIRBY

Page 3: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

sphere: GlutSphere

center: TransformNode west: TransformNode east: TransformNode east: TransformNode

redMat: MaterialNodegreenMat: MaterialNode blueMat: MaterialNode

light: LightNodelight2: LightNode

scene: Node

A simple scene graph instance

This is a DAG(directed acyclic graph)

NKU CSC 480 KIRBY

Page 4: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

NodeNode

TransformNodeTransformNode EnvironmentNodeEnvironmentNode AppearanceNodeAppearanceNode

LightNodeLightNode MaterialNodeMaterialNode

ArtifactNodeArtifactNode

MeshMesh GlutSphereGlutSphere GlutTeapotGlutTeapot

A Simple Scene Graph Class Hierarchy

NKU CSC 480 KIRBY

Page 5: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

Implementation Issues for Discussion

How do we implement a DAG ?

What does a TransformNode do?

How to we handle rendering of sub-scenes?

How do clients assemble a scene graph in an OpenGL program?

NKU CSC 480 KIRBY

See SceneGraph.h, SceneGraph.cpp, DemoSceneGraph.cpp

Page 6: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

R(0) R(1)

Frame 442 Frame 482

Frame 462 R(0.5) = 0.5 R(0) + 0.5 R(1) ????

Bad. Why?

Rotation matrices and Tweening

NKU CSC 480 KIRBY

Page 7: CSC 480 / 580 Computer Graphics K. Kirby Scene Graphs and Slerping Quaternions NKU CSC 480 KIRBY

Points – as pure quaternionsp = xi + yj + zk

Rotations (u^, ) – as unit quaternionsr = cos ½ + (sin ½) u1i + u2j + u3k

Implementing rotations: p´ = r p r*

SLERPing quaternions (“spherical linear interpolation”)

r(t) = [ sin(1-t) r(0) + sin t r(1) ] / sin

where cos = r(0) r(1).NKU CSC 480 KIRBY