view TaskManager/Test/test_render/task/update_sgp.cpp @ 267:7f2b30acf311

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 04 Jun 2009 00:01:11 +0900
parents e1d24c951408 a59868d37093
children 3e9c0039e15c
line wrap: on
line source

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include "scene_graph_pack.h"
#include "sys.h"
#include "update_sgp.hpp"

SchedDefineTask(Update_SGP);

<<<<<<< local
=======
typedef void (*moveFunc)(SceneGraphNodePtr, int, int);
typedef void (*collFunc)(SceneGraphNodePtr, int, int);

static moveFunc moveList[3];
static collFunc collList[3];

static void
move0(SceneGraphNodePtr node, int w, int h)
{
    static float dest_x = 0.3f;
    static float dest_y = 0.5f;

    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }

    node->obj_pos[0] += dest_x;
    if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
	dest_x = -dest_x;
    }

    node->obj_pos[1] += dest_y;
    if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
	dest_y = -dest_y;
    }
}

static void
move1(SceneGraphNodePtr node, int w, int h)
{
    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }

    static float dest_x = 0.5f;
    static float dest_y = 1.3f;

    node->obj_pos[0] += dest_x;
    if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
	dest_x = -dest_x;
    }

    node->obj_pos[1] += dest_y;
    if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
	dest_y = -dest_y;
    }
}

static void
move2(SceneGraphNodePtr node, int w, int h)
{
    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }

    static float dest_x = 1.0f;
    static float dest_y = 0.8f;

    node->obj_pos[0] += dest_x;
    if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
	dest_x = -dest_x;
    }

    node->obj_pos[1] += dest_y;
    if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
	dest_y = -dest_y;
    }
}

static void
move4(SceneGraphNodePtr node, int w, int h)
{
    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }
}


static void
coll(SceneGraphNodePtr node, int w, int h)
{
}

static void
init(void)
{
    moveList[0] = move0;
    moveList[1] = move4;
    moveList[2] = move2;

    collList[0] = coll;
    collList[1] = coll;
    collList[2] = coll;
}

>>>>>>> other
int
Update_SGP::run(void *rbuf, void *wbuf)
{
    SceneGraphNodePtr node;
    SceneGraphPack *sgp  = (SceneGraphPack*)get_input(rbuf, 0);
    SceneGraphPack *_sgp = (SceneGraphPack*)get_output(wbuf, 0);
    //int screen_width = get_param(0);
    //int screen_height = get_param(1);

    // 本当はここでやるもんじゃないんだが。。。
    for (int i = 0; i < sgp->info.size && i < 3; i++) {
	node = &sgp->node[i];

	do {
	    if (node->pn != -1) {
		get_matrix(node->translation,
			   node->angle, node->obj_pos,
			   sgp->node[node->pn].translation);
	    } else {
		get_matrix(node->translation,
			   node->angle, node->obj_pos,
			   NULL);
	    }

	    node = node->next;
	} while (node);
    }

    memcpy(_sgp, sgp, sizeof(SceneGraphPack));
  
    return 0;
}