Scene Chart Information Structures.


117 views
Uploaded on:
Description
Scene Diagram Information Structures . Demonstrating/Rendering C++ Classes. Displaying/Rendering. Graphical Model. Rendering Parameters. Rendering. Yield Gadget. Does OpenGL Bolster Demonstrating. NO! OpenGL just renders You can skirt the model, however… Hard to manage variable articles
Transcripts
Slide 1

Scene Graph Data Structures Modeling/Rendering C++ Classes

Slide 2

Modeling/Rendering Graphical Model Rendering Parameters Rendering Output Device

Slide 3

Does OpenGL Support Modeling NO! OpenGL just renders You can skirt the model, but… Difficult to manage variable articles Loaded items? It is frequently expected you will use some displaying API Open Inventor from SGI is a sample Video amusements, High end demonstrating, and so forth

Slide 4

Why Modeling is Important All of the model is in a uniform configuration Alternative rendering can be upheld Advanced systems can be bolstered Shadows, Transparency, Fog, and so forth. Helper capacities can be upheld Level of point of interest, route, impact identification Store static substance Textures, knock maps

Slide 5

Project 1 You should, I rehash, must execute the whole room as a graphical model that is then rendered.â  Do not just draw your buoy utilizing OpenGL calls!â 

Slide 6

Standards for Modeling There are shockingly couple of principles for demonstrating Models have a tendency to be VERY application particular Games have distinctive prerequisites from CAD, which has diverse necessities from movement, and so forth. Models have a tendency to be exceptionally “programmer visible”

Slide 7

What a Model Is… Fundamentally: A Data Structure Typically an arrangement of items that speak to the components of a “scene graph” Scene chart: Hierarchical representation of a graphical scene

Slide 8

A Simple Polygon Model… class CPolygon { open: CPolygon(); virtual ~CPolygon(); void glRender(); void AddVertex(double x, twofold y, twofold z); private:/A polygon is a rundown of vertices std::list< CGrPoint > m_vertices; }; Note: Too Simple, don’t use

Slide 9

That CGrPoint class… class CGrPoint { open: CGrPoint() {} CGrPoint(double x, twofold y, twofold z=0, twofold w=1.) {m[0] = x; m[1] = y; m[2] = z; m[3] = w;} CGrPoint(const CGrPoint &p) {m[0]=p.m[0]; m[1]=p.m[1]; m[2]=p.m[2]; m[3]=p.m[3];} CGrPoint &operator=(const CGrPoint &p) {m[0]=p.m[0]; m[1]=p.m[1]; m[2]=p.m[2]; m[3]=p.m[3]; return *this;} twofold X() const {return m[0];} double X(double p) {return m[0] = p;} twofold Y() const {return m[1];} double Y(double p) {return m[1] = p;} twofold Z() const {return m[2];} double Z(double p) {return m[2] = p;} twofold W() const {return m[3];} twofold W(double p) {return m[3] = p;} void Set(double x, twofold y, twofold z, twofold w=1.) {m[0] = x; m[1] = y; m[2] = z; m[3] = w;} void glVertex() const {glVertex4dv(m);} private: twofold m[4]; };

Slide 10

We truly need… Scene Graph Primitives (Things that really render) Composite articles Modeling of Transformations Color Other...

Slide 11

Example How would you Render? Barbell Composite Translate Barbell Bar Barbell Ends Color Composite … Polygon

Slide 12

Tree Node Superclass class CGrObject { open: CGrObject() {} virtual ~CGrObject(); virtual void glRender() = 0; }; This is a conceptual base class

Slide 13

A Primitive class CGrPolygon : open CGrObject { open: CGrPolygon(); virtual ~CGrPolygon(); virtual void glRender(); void AddVertex3d(double x, twofold y, twofold z); void AddVertex3dv(double *p); void AddVertices(double *a, twofold *b, twofold *c, twofold *d=NULL); private:/A polygon is a rundown of vertices std::list<CGrPoint> m_vertices; };

Slide 14

Using this class d/Non-equilateral tetrahedron focuses twofold a[3] = {1.5, 0, 0}; twofold b[3] = {0, 0, 1.5}; twofold c[3] = {-1.5, 0, 0}; twofold d[3] = {0, 3, 0}; CGrPolygon *poly1, *poly2, *poly3; poly1 = new CGrPolygon(); poly1->AddVertex3dv(a); poly1->AddVertex3dv(b); poly1->AddVertex3dv(c); poly2 = new CGrPolygon(); poly2->AddVertices(d, b, a); poly3 = new CGrPolygon(d, c, b); Polygon 1 c a b Polygon 2 Polygon 3

Slide 15

Question: What about memory administration We are allotting so how would we guarantee we deallocate? We can’t deallocate when connection uprooted We have a multigraph, not a tree Ideas?

Slide 16

Reference Counters class CGrObject { open: CGrObject() {m_refs = 0;} virtual ~CGrObject(); virtual void glRender() = 0; void IncRef() {m_refs++;} void DecRef() {m_refs- - ; if(m_refs == 0) {delete this;}} private: int m_refs; };

Slide 17

A Template Pointer Class layout <class T> class CGrPtr { open: CGrPtr() {m_ptr = NULL;} CGrPtr(T *p_ptr) {m_ptr = p_ptr; if(m_ptr) m_ptr->IncRef();} CGrPtr(CGrPtr &p_ptr) {m_ptr=p_ptr.m_ptr; if(m_ptr) m_ptr->IncRef();} ~CGrPtr() {Clear();} void Clear() {if(m_ptr) {m_ptr->DecRef(); m_ptr = NULL;}} T *operator=(T *t) {if (t) t->IncRef(); Clear(); m_ptr = t; return m_ptr;} T *operator=(CGrPtr &t) {if (t.m_ptr) t.m_ptr->IncRef(); Clear(); m_ptr = t.m_ptr; return m_ptr;} administrator T *() const {return m_ptr;} T *operator->() const {return m_ptr;} private: T *m_ptr; }; Example: CGrPtr<CGrPolygon> poly = new CGrPolygon();

Slide 18

Previous Example Revised/Non-equilateral tetrahedron focuses twofold a[3] = {1.5, 0, 0}; twofold b[3] = {0, 0, 1.5}; twofold c[3] = {-1.5, 0, 0}; twofold d[3] = {0, 3, 0}; CGrPtr<CGrPolygon> poly1, poly2, poly3; poly1 = new CGrPolygon(); poly1->AddVertex3dv(a); poly1->AddVertex3dv(b); poly1->AddVertex3dv(c); poly2 = new CGrPolygon(); poly2->AddVertices(d, b, a); poly3 = new CGrPolygon(d, c, b);

Slide 19

Procedures in CGrPolygon void CGrPolygon::AddVertex3d(double x, twofold y, twofold z) { m_vertices.push_back(CGrPoint(x, y, z)); } void CGrPolygon::AddVertices(double *a, twofold *b, twofold *c, twofold *d) { m_vertices.push_back(CGrPoint(a[0], a[1], a[2])); m_vertices.push_back(CGrPoint(b[0], b[1], b[2])); m_vertices.push_back(CGrPoint(c[0], c[1], c[2])); if(d) m_vertices.push_back(CGrPoint(d[0], d[1], d[2])); } void CGrPolygon::glRender() { glBegin(GL_POLYGON); for(list<CGrPoint>::iterator i=m_vertices.begin(); i!=m_vertices.end(); i++) i->glVertex(); glEnd(); } std::list<CGrPoint> m_vertices;

Slide 20

A Composite class CGrComposite : open CGrObject { open: CGrComposite() {} ~CGrComposite(); virtual void glRender(); void Child(CGrObject *p_child) {m_children.push_back(p_child);} private: std::list<CGrPtr<CGrObject> > m_children; }; void CGrComposite::glRender() { for(list<CGrPtr<CGrObject> >::iterator i=m_children.begin(); i != m_children.end(); i++) (*i)- >glRender(); }

Slide 21

Creating the Tetrahedron/The composite hub that will contain everything CGrPtr<CGrComposite> composite = new CGrComposite(); CGrPtr<CGrObject> obj = composite;/Non-equilateral tetrahedron focuses … CGrPtr<CGrPolygon> poly;/Polygon 1 poly = new CGrPolygon(); poly->AddVertex3dv(a); poly->AddVertex3dv(b); poly->AddVertex3dv(c);/Add to composite->Child(poly);/Polygon 2 poly = new CGrPolygon(); poly->AddVertices(d, b, a); composite->Child(poly);/Polygon 3 poly = new CGrPolygon(d, c, b); composite->Child(poly);/Polygon 4 composite->Child(new CGrPolygon(d, a, c));

Slide 22

What we get… CGrComposite CGrPolygon What happens when I call render on the CGrComposite object?

Slide 23

CGrColor class CGrColor : open CGrObject { open: CGrColor() {c[0]=c[1]=c[2] = 0.; c[3] = 1.;} CGrColor(double r, twofold g, twofold b) {c[0]=r; c[1]=g; c[2]=b; c[3] = 1.;} CGrColor(double r, twofold g, twofold b, CGrObject *p_child) {c[0]=r; c[1]=g; c[2]=b; c[3] = 1.; m_child=p_child;} virtual ~CGrColor(); virtual void glRender(); void Child(CGrObject *p_child) {m_child = p_child;} private: twofold c[4]; CGrPtr<CGrObject> m_child; }; void CGrColor::glRender() { glColor4dv(c); if(m_child) m_child->glRender(); }

Slide 24

Adding Color to Tetra Model CGrPtr<CGrColor> modelwcolor = new CGrColor(0., 0., 1., composite);

Slide 25

After including the CGrColor hub CGrColor CGrComposite CGrPolygon

Slide 26

A Translation class CGrTranslate : open CGrObject { open: CGrTranslate() {m_x=m_y=m_z = 0.;} CGrTranslate(double x, twofold y, twofold z) {m_x=x; m_y=y; m_z=z;} CGrTranslate(double x, twofold y, twofold z, CGrObject *p_child) {m_x=x; m_y=y; m_z=z; m_child=p_child;} ~CGrTranslate(); virtual void glRender(); void Child(CGrObject *p_child) {m_child = p_child;} private: CGrPtr<CGrObject> m_child; twofold m_x, m_y, m_z; };

Slide 27

Translation Class Implementation Alternatives void CGrTranslate::glRender() { if(m_child) { glPushMatrix(); glTranslated(m_x, m_y, m_z); m_child->glRender(); glPopMatrix(); } OR void CGrTranslate::glRender() { if(m_child) { glTranslated(m_x, m_y, m_z); m_child->glRender(); }

Slide 28

Translate in Barbell Composite Translate Barbell Bar Barbell Ends Color Composite … Polygon

Slide 29

Very common… Translate Rotate Translate Object

Slide 30

Means: Go ahead and disturb the change lattice, I’m disconnecting my kids! Separator Nodes Composite Separator Translate Barbell Bar Barbell Ends Color Composite … Poly

Recommended
View more...