/** Catmull-rom spline interpolation */ scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t) { vec4_t tmp; scalar_t tsq = t * t; static mat4_t crspline_mat = { {-1, 3, -3, 1}, {2, -5, 4, -1}, {-1, 0, 1, 0}, {0, 2, 0, 0} }; tmp = v4_scale(v4_transform(v4_cons(a, b, c, d), crspline_mat), 0.5); return v4_dot(v4_cons(tsq * t, tsq, t, 1.0), tmp); }
/** b-spline approximation */ scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t) { vec4_t tmp; scalar_t tsq = t * t; static mat4_t bspline_mat = { {-1, 3, -3, 1}, {3, -6, 3, 0}, {-3, 0, 3, 0}, {1, 4, 1, 0} }; tmp = v4_scale(v4_transform(v4_cons(a, b, c, d), bspline_mat), 1.0 / 6.0); return v4_dot(v4_cons(tsq * t, tsq, t, 1.0), tmp); }
static void update_buffer(sprite_t* self) { int status = ((node_t*)self)->updated; const vec4* col = &(((node_t*)self)->color); float r = col->r; float g = col->g; float b = col->b; float a = col->a; vec4* bbox = & ( ((node_t*) self)->bbox ); vec2* size = & ( ((node_t*) self)->size ); const vec4* coords; float sw, sh; float x0,y0,x1,y1,s0,s1,t0,t1; V4F_T2F_C4F vertices[4]; int update_model; if (status & SEN_NODE_UPDATE_INVALIDATE_BUFFER) { vertex_buffer_invalidate(self->quad); status &= ~SEN_NODE_UPDATE_INVALIDATE_BUFFER; } if (status & SEN_NODE_UPDATE_BBOX) { vertex_buffer_clear(self->quad); sw = self->tex->img_width / 2.0f; sh = self->tex->img_height / 2.0f; x0 = -sw; x1 = sw; y0 = -sh; y1 = sh; coords = &(self->tex->coords); s0 = coords->s0; t0 = coords->t0; s1 = coords->s1; t1 = coords->t1; /* V4F_T2F_C4F vertices[4] = {{ -sw,-sh,0,1, coords->s0,coords->t1, col->r,col->g,col->b,col->a,}, { -sw, sh,0,1, coords->s0,coords->t0, col->r,col->g,col->b,col->a,}, { sw, sh,0,1, coords->s1,coords->t0, col->r,col->g,col->b,col->a,}, { sw,-sh,0,1, coords->s1,coords->t1, col->r,col->g,col->b,col->a,}};*/ vertices[0].x = (float)x0; vertices[0].y = (float)y0; vertices[0].z = 0.0f; vertices[0].w = 1.0f; vertices[0].s = s0; vertices[0].t = t1; vertices[0].r = r; vertices[0].g = g; vertices[0].b = b; vertices[0].a = a; vertices[1].x = (float)x0; vertices[1].y = (float)y1; vertices[1].z = 0.0f; vertices[1].w = 1.0f; vertices[1].s = s0; vertices[1].t = t0; vertices[1].r = r; vertices[1].g = g; vertices[1].b = b; vertices[1].a = a; vertices[2].x = (float)x1; vertices[2].y = (float)y1; vertices[2].z = 0.0f; vertices[2].w = 1.0f; vertices[2].s = s1; vertices[2].t = t0; vertices[2].r = r; vertices[2].g = g; vertices[2].b = b; vertices[2].a = a; vertices[3].x = (float)x1; vertices[3].y = (float)y0; vertices[3].z = 0.0f; vertices[3].w = 1.0f; vertices[3].s = s1; vertices[3].t = t1; vertices[3].r = r; vertices[3].g = g; vertices[3].b = b; vertices[3].a = a; bbox->x = -sw; bbox->y = -sh; bbox->z = sw; bbox->w = sh; size->x = (float) (self->tex->img_width); size->y = (float) (self->tex->img_height); vertex_buffer_push_back( self->quad, vertices, 4, indices, 6 ); // vertex_buffer_push_back_vertices( self->quad, vertices, 4); memcpy(self->vertices, vertices, sizeof(vertices)); status &= ~SEN_NODE_UPDATE_BBOX; status |= SEN_NODE_UPDATE_MODEL; } update_model = status & SEN_NODE_UPDATE_MODEL; if ( status & (SEN_NODE_UPDATE_MODEL | SEN_NODE_UPDATE_COLOR)) { //V4F_T2F_C4F vertices[4]; // memcpy(vertices, self->vertices, 4*sizeof(V4F_T2F_C4F)); const mat4* model = sen_node_model(self); int i; for (i=0; i<4; ++i) { if (update_model) { // vec4* v = (vec4*) ( i*sizeof(V4F_T2F_C4F )+(self->quad->vertices->items)); //vec4* v = (vec4*) ( i*sizeof(V4F_T2F_C4F )+(vertices)); //vec4* v = (vec4*) (& vertices[i]);// ( i*sizeof(V4F_T2F_C4F )+(vertices)); vec4* vp = (vec4*) (& (self->vertices[i]) ); vec4* v = (vec4*) ( (char*)(self->quad->vertices->items) + i*sizeof(V4F_T2F_C4F ) ); //v4_transform(model->data, v->data,v->data); v4_transform(model->data, vp->data,v->data); if ( i ) { if (v->x < bbox->x) bbox->x = v->x; else if (v->x > bbox->z) bbox->z = v->x; if (v->y < bbox->y) bbox->y = v->y; else if (v->y > bbox->w) bbox->w = v->y; } else { bbox->x = bbox->z = v->x; bbox->y = bbox->w = v->y; } } if (status & SEN_NODE_UPDATE_COLOR) { vec4* c = (vec4*) ( (char*)(self->quad->vertices->items)+ i*sizeof(V4F_T2F_C4F )+ sizeof(float)*6); // vec4* c = (vec4*) ( i*sizeof(V4F_T2F_C4F )+sizeof(float)*6+(vertices)); //vec4* c = (vec4*) (& (vertices[i].r) );// i*sizeof(V4F_T2F_C4F )+sizeof(float)*6+(vertices)); // vec4* c = (vec4*) (& (self->vertices[i].r) );// i*sizeof(V4F_T2F_C4F )+sizeof(float)*6+(vertices)); memcpy(c,col,sizeof(vec4)); } } //self->quad->state = 1; status &= ~(SEN_NODE_UPDATE_COLOR|SEN_NODE_UPDATE_MODEL|SEN_NODE_UPDATE_PARENT_MODEL); } ((node_t*)self)->updated = status; }