/
scenegraph.h
104 lines (68 loc) · 2.05 KB
/
scenegraph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef _SCENEGRAPH_H_
#define _SCENEGRAPH_H_
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#define DEBUG 0
#define MAX_POLYGONS 12
enum OBJ_OPERATION{ TRANSLATE = 0, ROTATE = 1, SCALE = 2, RENDER = 3, DESTROY = 4 };
typedef struct VER
{
GLdouble x, y, z;
} vertex;
typedef struct OBJ
{
int id; /*This is the array value in SM.object_registry*/
/* We are using a sphere, as we only have to recalculate on translate
and not rotate. Also it takes less memory to hold a bounding sphere.
Additionally it takes less checks to do the frustum intersections. */
vertex bound_sphere_loc;
GLfloat bound_sphere_rad;
vertex location;
vertex rotation;
vertex scale;
/* relative vertexes to hold state of scenegraph traversal so far */
vertex r_location;
vertex r_rotation;
vertex r_scale;
vertex* polygon_data;
vertex polygon_color;
int render_callist;
int vertex_count;
int polygon_count; /* Number of polygons */
int render_mode; /* GL_TRIANGLE_STRIPS ... so on */
int children_id[8]; /*Limit children of a node to 8, which allows easier implementation of octree later*/
bool is_root;
int parent;
unsigned int children; /*Number of children*/
} object;
typedef struct LOBJ
{
struct LOBJ* next;
struct LOBJ* previous;
object* object_ptr; /*This is the array value in SM.object_register */
} linked_object;
typedef struct SM
{
int objects;
/*We keep an array of objects so we have locality on this data*/
object* object_registry;
int registered; //Value of objects registered so far
/*A linked list implementation for quick sorting of closest objects will help us with maintaining a ploygon limit*/
linked_object* rm_all;
linked_object* rm_first;
linked_object* rm_last;
/* Our root object */
int root_object_id;
GLfloat frustum[6][4];
vertex camera;
int polygon_rendered;
} scene_manager;
#include "scene.h"
#include "object.h"
#include "vertex.h"
#endif