view TaskManager/Test/test_render/task/update_sgp.cpp @ 137:6cf991f28c6c

SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 10:07:48 +0900
parents c65aee1528ef
children 3fd24be89d02
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);

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
move3(SceneGraphNodePtr node, int w, int h)
{
    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }
}

static void
no_move(SceneGraphNodePtr node, int w, int h)
{
    node->obj_pos[0] = 0;
    node->obj_pos[1] = 0;
}

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)
{
    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
coll(SceneGraphNodePtr node, int w, int h)
{
}

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;
}