Пример #1
0
std::vector<std::shared_ptr<gua::node::TransformNode>> add_lights(gua::SceneGraph& graph,
                                                  int count) {

  std::vector<std::shared_ptr<gua::node::TransformNode>> lights(count);

  for (int i(0); i < count; ++i) {
    scm::math::vec3 randdir(gua::math::random::get(-1.f, 1.f),
                            gua::math::random::get(-1.f, 1.f),
                            gua::math::random::get(-1.f, 1.f));
    scm::math::normalize(randdir);

    gua::TriMeshLoader loader;
    auto sphere_geometry(
      loader.create_geometry_from_file(
      "sphere" + gua::string_utils::to_string(i),
      "data/objects/light_sphere.obj",
      "data/materials/White.gmd"
    ));

    sphere_geometry->scale(0.04, 0.04, 0.04);

    lights[i] = graph.add_node("/", std::make_shared<gua::node::TransformNode>("light" + gua::string_utils::to_string(i)));
    lights[i]->add_child(sphere_geometry);
    lights[i]->translate(randdir[0], randdir[1], randdir[2]);

    auto light = lights[i]->add_child(std::make_shared<gua::node::PointLightNode>("light"));
    light->data.set_color(gua::utils::Color3f::random());
  }

  return lights;
}
Пример #2
0
void depth_first(void){
	int *xstack = malloc(mx * my * sizeof(int));
	int *ystack = malloc(mx * my * sizeof(int));
	xstack[0] = 0;
	ystack[0] = 0;
	int sp = 0;
	int x, y;
	int dir;
	while(sp >= 0){
		if(sp >= mx * my){
			return;
		}
		x = xstack[sp];
		y = ystack[sp];
		//printf("sp = %d, (x, y) = (%d, %d)\n", sp, x, y);
		if((y == 0      || maze[y - 1][x]) &&
		   (y == my - 1 || maze[y + 1][x]) &&
		   (x == 0      || maze[y][x - 1]) &&
		   (x == mx - 1 || maze[y][x + 1])){
			sp--;
			continue;
		}
		dir = randdir(((y > 0      && !maze[y - 1][x]) << 3) |
		              ((y < my - 1 && !maze[y + 1][x]) << 1) |
		              ((x > 0      && !maze[y][x - 1]) << 2) |
		              ((x < mx - 1 && !maze[y][x + 1]) << 0));
		sp++;
		//printf("dir = %d\n", dir);
		maze[y][x] |= dir;
		switch(dir){
			case 1:
				maze[y    ][x + 1] |= 4;
				xstack[sp] = x + 1;
				ystack[sp] = y;
				break;
			case 2:
				maze[y + 1][x    ] |= 8;
				xstack[sp] = x;
				ystack[sp] = y + 1;
				break;
			case 4:
				maze[y    ][x - 1] |= 1;
				xstack[sp] = x - 1;
				ystack[sp] = y;
				break;
			case 8:
				maze[y - 1][x    ] |= 2;
				xstack[sp] = x;
				ystack[sp] = y - 1;
				break;
			default:
				fprintf(stderr, "INVALID DIRECTION.\n");
				break;
		}
	}
	if(odds){
		random_connections();
	}
}