view TaskManager/Test/test_render/node.cpp @ 138:f35504025f73 draft

オブジェクトを増やして複数の表示に成功。 TODO:オブジェクトの削除
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 12:16:24 +0900
parents 91c74dbc32e4
children bacb6dde2d17
line wrap: on
line source

#include "SceneGraph.h"
#include "xml_file/universe.h"
#include "xml_file/cube.h"


static void
earth_move(SceneGraphPtr node, int screen_w, int screen_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->xyz[0] += dest_x;
    if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
	dest_x = -dest_x;
    }

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

static void
moon_move(SceneGraphPtr node, int screen_w, int screen_h)
{
    node->angle[0] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }
}

static void
earth_collision(SceneGraphPtr node, int screen_w, int screen_h,
		SceneGraphPtr tree)
{
}

static void
moon_collision(SceneGraphPtr node, int screen_w, int screen_h,
	       SceneGraphPtr tree)
{
}

static void
cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
	       SceneGraphPtr tree)
{
}

static void
cube_move2(SceneGraphPtr node, int screen_w, int screen_h)
{
    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }

    node->xyz[0] += node->stack_xyz[0];
    if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
	node->stack_xyz[0] = -node->stack_xyz[0];
    }

    node->xyz[1] += node->stack_xyz[1];
    if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
	node->stack_xyz[1] = -node->stack_xyz[1];
    }
}

static void
cube_move(SceneGraphPtr node, int screen_w, int screen_h)
{
    node->angle[1] += 1.0f;
    if (node->angle[1] > 360.0f) {
	node->angle[1] = 0.0f;
    }

    node->xyz[0] += node->stack_xyz[0];
    if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
	node->stack_xyz[0] = -node->stack_xyz[0];
    }

    node->xyz[1] += node->stack_xyz[1];
    if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {

	SceneGraphPtr p = node->clone();
	p->position_init();
	node->addBrother(p);
	scene_graph->set_move_collision(p, cube_move2, cube_collision);
	p->stack_xyz[0] = 0.5f;
	p->stack_xyz[1] = 0.5f;
	//p->xyz[0] = screen_w/2;
	//p->xyz[1] = screen_h/2;

	node->stack_xyz[1] = -node->stack_xyz[1];
    }
}

void
node_init(void)
{
#if 0
    scene_graph->set_move_collision(Earth, earth_move, earth_collision);
    scene_graph->set_move_collision(Moon, moon_move, moon_collision);
#else
    scene_graph->set_move_collision(Cube, cube_move, cube_collision);
    Cube->stack_xyz[0] = 0.5f;
    Cube->stack_xyz[1] = 0.5f;
#endif
}