polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

node.h (1500B)


      1 
      2 #ifndef POLYADVENT_NODE_H
      3 #define POLYADVENT_NODE_H
      4 
      5 #include "resource.h"
      6 
      7 #define MAX_NODE_CHILDREN 4
      8 
      9 enum node_flags {
     10   NODE_IGNORE_RECALC = 1 << 0
     11 };
     12 
     13 typedef struct resource_id node_id;
     14 
     15 struct node {
     16     float pos[3];
     17     float rot[3];
     18     float scale[3];
     19     float mat[16];
     20     float orientation[4];
     21     char label[8];
     22     int needs_recalc;
     23     int flags;
     24     int n_children;
     25     void (*custom_update)(struct node*);
     26     void *custom_update_data;
     27 
     28     node_id parent_id;
     29     node_id children_ids[MAX_NODE_CHILDREN];
     30 };
     31 
     32 int node_recalc(struct node *root);
     33 void node_attach(node_id *node, node_id *to);
     34 int node_detach(struct node *node, struct node *from);
     35 void node_detach_from_parent(struct node *node);
     36 void node_mark_for_recalc(struct node *node);
     37 struct node *node_init(struct node *node);
     38 void node_translate(struct node *node, float *p);
     39 void node_forward(struct node *node, float *p);
     40 void node_forward_dir(struct node *node, float *orientation, float *p);
     41 void node_rotate(struct node *node, float *p);
     42 void node_scale(struct node *node, float val);
     43 int node_count(struct node *node);
     44 float *node_world(struct node *node);
     45 int node_set_label(struct node *node, const char *label);
     46 
     47 struct node *get_node(node_id *);
     48 struct node *new_node(node_id *);
     49 void destroy_node(node_id *);
     50 void init_node_manager();
     51 
     52 
     53 extern struct resource_manager node_manager;
     54 
     55 static inline struct node *static_nodes()
     56 {
     57     return (struct node*)node_manager.resources;
     58 }
     59 
     60 #endif /* POLYADVENT_NODE_H */