Example #1
0
/* t_insert: insert a node into the tree */
struct tnode *t_insert(struct tnode *p, const char *string, struct command *data)
{
    if (p == NULL) {
	p = malloc(sizeof(struct tnode));
	p->splitchar = *string;
	p->low = p->eq = p->hi = NULL;
	p->data = NULL;
    }
    if (*string < p->splitchar)
	p->low = t_insert(p->low, string, data);
    else if (*string == p->splitchar) {
	if (*++string == 0)
	    p->data = data;
	else if (*string != 0)
	    p->eq = t_insert(p->eq, string, data);
    } else
	p->hi = t_insert(p->hi, string, data);
    return p;
}
Example #2
0
void SE_BipedController::interpolation(std::vector<SE_BipedKeyFrame*>::iterator &source,std::vector<SE_BipedKeyFrame*>::iterator &target,
                                       std::vector<SE_BipedKeyFrame*> &targetVector)
{
    SE_BipedKeyFrame* node_s = *source;
    SE_BipedKeyFrame* node_t = *target;

    //new frame counts,than push_back(node_s).For example:node_s = 3,node_t=0,
    //needGenerate 2 frames,then,push_back(node_s),now fullframe vector is 0,  1,2,  3
    int needGenerate = node_s->frameIndex - node_t->frameIndex - 1;

    for(int i = 0; i < needGenerate; ++i)
    {
        SE_Quat q_s = node_s->rotateQ;
        SE_Vector3f t_s = node_s->translate;

        SE_Quat q_t = node_t->rotateQ;
        SE_Vector3f t_t = node_t->translate;

        float t = (i+1.0) / (needGenerate+1.0);

        SE_Quat q_insert = SE_Quat::slerp(q_t,q_s,t);

        float x = SE_Lerp(t_t.x,t_s.x,t);
        float y = SE_Lerp(t_t.y,t_s.y,t);
        float z = SE_Lerp(t_t.z,t_s.z,t);

        SE_Vector3f t_insert(x,y,z);
        SE_Vector3f s_insert(1,1,1);//scale,not use

        SE_BipedKeyFrame* insertFrame = new SE_BipedKeyFrame();
        insertFrame->rotateQ = q_insert;
        insertFrame->translate = t_insert;
        insertFrame->scale = s_insert;
        insertFrame->frameIndex = node_t->frameIndex + i + 1;

        targetVector.push_back(insertFrame);
        target = targetVector.end();
        --target;
        
    }

    //push source node to target
    SE_BipedKeyFrame* insertSourceFrame = new SE_BipedKeyFrame();
    insertSourceFrame->rotateQ = node_s->rotateQ;
    insertSourceFrame->translate = node_s->translate;
    insertSourceFrame->scale = node_s->scale;
    insertSourceFrame->frameIndex = node_s->frameIndex;
    targetVector.push_back(insertSourceFrame);
    target = targetVector.end();
    --target;

    //don't increase source,next test will automatic increase

}
Example #3
0
/* t_build: given an array, insert all the commands. Will produce better
   results if the array is sorted.      */
struct tnode *t_build(struct tnode *root, struct command c[], int n)
{
    int m;

    if (n < 1)
	return root;
    m = n / 2;
    root = t_insert(root, c[m].name, &c[m]);

    root = t_build(root, c, m);
    root = t_build(root, c + m + 1, n - m - 1);
    return root;
}
Example #4
0
File: main.cpp Project: CCJY/coliru
int main(){
	/* construct tree by hand */
	struct tree_node *tp, *root_p = 0;
	int i;
	/* we ingore the return value of t_insert */
	t_insert(&root_p, 4);
	t_insert(&root_p, 2);
	t_insert(&root_p, 60);
	t_insert(&root_p, 10);
	t_insert(&root_p, 3);
	t_insert(&root_p, 5);
	t_insert(&root_p, 7);
	/* try the search */
	for(i = 1; i < 9; i++){
		tp = t_search(root_p, i);
		if(tp)
			printf("%d found\n", i);
		else
			printf("%d not found\n", i);
	}
	exit(EXIT_SUCCESS);
}