void RenderBatchLine::draw_line_strip(Canvas &canvas, const Vec2f *line_positions, const Vec4f &line_color, int num_vertices)
{
	if (num_vertices < 2)
	{
		return;	// Invalid line strip, we ignore this. It could be null call to this function
	}

	// We convert a line strip to a line
	num_vertices -=1;
	set_batcher_active(canvas, num_vertices * 2);


	Vec4f next_start_position = to_position(line_positions->x, line_positions->y);

	for (; num_vertices > 0; num_vertices--)
	{
		vertices[position].color = line_color;
		vertices[position].position = next_start_position;
		line_positions++;
		position++;

		vertices[position].color = line_color;
		next_start_position = to_position(line_positions->x, line_positions->y);
		vertices[position].position = next_start_position;
		position++;
	}
}
示例#2
0
static int position_orientationto(lua_State* l)
{
    CelxLua celx(l);

    celx.checkArgs(3, 3, "Two arguments expected for position:orientationto");
    
    UniversalCoord* src = this_position(l);
    UniversalCoord* target = to_position(l, 2);
    
    if (target == NULL)
    {
        celx.doError("First argument to position:orientationto must be a position");
    }
    
    Vec3d* upd = celx.toVector(3);
    if (upd == NULL)
    {
        celx.doError("Second argument to position:orientationto must be a vector");
    }
    
    Vec3d src2target = *target - *src;
    src2target.normalize();
    Vec3d v = src2target ^ *upd;
    v.normalize();
    Vec3d u = v ^ src2target;
    Quatd qd = Quatd(Mat3d(v, u, -src2target));
    celx.newRotation(qd);
    
    return 1;
}
示例#3
0
void gen_area(char * map, int size, void (*wr)(char *, int)) {

	int i;
	int currpos = (map_size_y*(rand()%map_size_y))+rand()%map_size_x;

	Position q = to_position(currpos);

	for (i = 0; i < size; i++) {
		/* The woodlands pattern is as so:
		 *  @
		 * @#@
		 *  @
		 * where the @ are replication positions
		 */
		wr(map, currpos);

		int v = rand()%4;
		switch (v) {
			case 0: currpos = currpos-2; break;
			case 1: currpos = currpos+2; break;
			case 2: currpos = currpos-map_size_x-map_size_x; break;
			case 3: currpos = currpos+map_size_x+map_size_x; break;
			default: printf("Randomization error.");break;
		}
		if (currpos < 0) {
			currpos = ((map_size_x*(map_size_y/2))+(map_size_x/2));
		}
	}
	return;
}
inline void RenderBatchTriangle::to_sprite_vertex(const Pointf &texture_position, const Pointf &dest_position, RenderBatchTriangle::SpriteVertex &v, int texindex, const Colorf &color) const
{
	v.position = to_position(dest_position.x, dest_position.y);
	v.color = color;
	v.texcoord = texture_position;
	v.texindex = texindex;
}
示例#5
0
void cave(char *map, int currpos) {
	if (currpos > (map_size_x+2)) {
		map[currpos-map_size_x+1] = 'C';
		map[currpos-map_size_x-1] = 'C';
		map[currpos+map_size_x+1] = 'C';
		map[currpos+map_size_x-1] = 'C';
		map[currpos+map_size_x] = 'c';
		map[currpos-map_size_x] = 'c';
		map[currpos] = 'c';
		map[currpos-1] = 'c';
		map[currpos+1] = 'c';
		int q;
		int i;
		q = rand()%4;
		switch (q) {
			case 0:
				break;
			case 1:
				water.pos[water.count] = to_position(currpos);
				water.count++;

				break;
			case 2:
				food.pos[food.count] = to_position(currpos);
				food.count++;
				break;
			case 3:
				food.pos[food.count] = to_position(currpos);
				food.count++;
				water.pos[water.count] = to_position(currpos);
				water.count++;
				break;
		}
		/*for (i = 0; i < 4; i++) {
			q = rand()%4;
			switch (q) {
				case 0: map[currpos-map_size_x] = 'C'; break;
				case 1: map[currpos+map_size_x] = 'C'; break;
				case 2: map[currpos+1] = 'C'; break;
				case 3: map[currpos-1] = 'C'; break;
				default: printf("Randomization error.\n"); break;
			}
		}*/
	} else {
		return;
	}
}
示例#6
0
static UniversalCoord* this_position(lua_State* l)
{
    CelxLua celx(l);

    UniversalCoord* uc = to_position(l, 1);
    if (uc == NULL)
    {
        celx.doError("Bad position object!");
    }
    
    return uc;
}
void CL_RenderBatch3D::draw_image(CL_GraphicContext &gc, const CL_Rectf &src, const CL_Rectf &dest, const CL_Colorf &color, const CL_Texture &texture)
{
	int texindex = set_batcher_active(gc, texture);
	vertices[position+0].position = to_position(dest.left, dest.top);
	vertices[position+1].position = to_position(dest.right, dest.top);
	vertices[position+2].position = to_position(dest.left, dest.bottom);
	vertices[position+3].position = to_position(dest.right, dest.top);
	vertices[position+4].position = to_position(dest.right, dest.bottom);
	vertices[position+5].position = to_position(dest.left, dest.bottom);
	float src_left = (src.left)/tex_sizes[texindex].width;
	float src_top = (src.top) / tex_sizes[texindex].height;
	float src_right = (src.right)/tex_sizes[texindex].width;
	float src_bottom = (src.bottom) / tex_sizes[texindex].height;
	vertices[position+0].texcoord = CL_Vec2f(src_left, src_top);
	vertices[position+1].texcoord = CL_Vec2f(src_right, src_top);
	vertices[position+2].texcoord = CL_Vec2f(src_left, src_bottom);
	vertices[position+3].texcoord = CL_Vec2f(src_right, src_top);
	vertices[position+4].texcoord = CL_Vec2f(src_right, src_bottom);
	vertices[position+5].texcoord = CL_Vec2f(src_left, src_bottom);
	for (int i=0; i<6; i++)
	{
		vertices[position+i].color = CL_Vec4f(color.r, color.g, color.b, color.a);
		vertices[position+i].texindex.x = (float)texindex;
	}
	position += 6;
}
void RenderBatchTriangle::draw_glyph_subpixel(Canvas &canvas, const Rectf &src, const Rectf &dest, const Colorf &color, const Texture2D &texture)
{
	int texindex = set_batcher_active(canvas, texture, true, color);

	vertices[position+0].position = to_position(dest.left, dest.top);
	vertices[position+1].position = to_position(dest.right, dest.top);
	vertices[position+2].position = to_position(dest.left, dest.bottom);
	vertices[position+3].position = to_position(dest.right, dest.top);
	vertices[position+4].position = to_position(dest.right, dest.bottom);
	vertices[position+5].position = to_position(dest.left, dest.bottom);
	float src_left = (src.left)/tex_sizes[texindex].width;
	float src_top = (src.top) / tex_sizes[texindex].height;
	float src_right = (src.right)/tex_sizes[texindex].width;
	float src_bottom = (src.bottom) / tex_sizes[texindex].height;
	vertices[position+0].texcoord = Vec2f(src_left, src_top);
	vertices[position+1].texcoord = Vec2f(src_right, src_top);
	vertices[position+2].texcoord = Vec2f(src_left, src_bottom);
	vertices[position+3].texcoord = Vec2f(src_right, src_top);
	vertices[position+4].texcoord = Vec2f(src_right, src_bottom);
	vertices[position+5].texcoord = Vec2f(src_left, src_bottom);
	for (int i=0; i<6; i++)
	{
		vertices[position+i].color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f);
		vertices[position+i].texindex = texindex;
	}
	position += 6;
}
void RenderBatchTriangle::draw_image(Canvas &canvas, const Rectf &src, const Quadf &dest, const Colorf &color, const Texture2D &texture)
{
	int texindex = set_batcher_active(canvas, texture);

	vertices[position+0].position = to_position(dest.p.x, dest.p.y);
	vertices[position+1].position = to_position(dest.q.x, dest.q.y);
	vertices[position+2].position = to_position(dest.s.x, dest.s.y);
	vertices[position+3].position = to_position(dest.q.x, dest.q.y);
	vertices[position+4].position = to_position(dest.r.x, dest.r.y);
	vertices[position+5].position = to_position(dest.s.x, dest.s.y);
	float src_left = (src.left)/tex_sizes[texindex].width;
	float src_top = (src.top) / tex_sizes[texindex].height;
	float src_right = (src.right)/tex_sizes[texindex].width;
	float src_bottom = (src.bottom) / tex_sizes[texindex].height;
	vertices[position+0].texcoord = Vec2f(src_left, src_top);
	vertices[position+1].texcoord = Vec2f(src_right, src_top);
	vertices[position+2].texcoord = Vec2f(src_left, src_bottom);
	vertices[position+3].texcoord = Vec2f(src_right, src_top);
	vertices[position+4].texcoord = Vec2f(src_right, src_bottom);
	vertices[position+5].texcoord = Vec2f(src_left, src_bottom);
	for (int i=0; i<6; i++)
	{
		vertices[position+i].color = Vec4f(color.r, color.g, color.b, color.a);
		vertices[position+i].texindex = texindex;
	}
	position += 6;
}
示例#10
0
void RenderBatchTriangle::fill_triangles(Canvas &canvas, const Vec2f *positions, const Vec2f *texture_positions, int num_vertices, const Texture2D &texture, const Colorf *colors)
{
	int texindex = set_batcher_active(canvas, texture);

	for (; num_vertices > 0; num_vertices--)
	{
		vertices[position].color = *(colors++);
		vertices[position].position = to_position(positions->x, positions->y);
		positions++;
		vertices[position].texcoord = *(texture_positions++);
		vertices[position].texindex = texindex;
		position++;
	}
}
示例#11
0
void RenderBatchPoint::draw_point(Canvas &canvas, Vec2f *line_positions, const Vec4f &point_color, int num_vertices)
{
	set_batcher_active(canvas, num_vertices);


	for (; num_vertices > 0; num_vertices--)
	{
		vertices[position].color = point_color;
		vertices[position].position = to_position(line_positions->x, line_positions->y);
		line_positions++;
		position++;
	}

}
示例#12
0
void RenderBatchTriangle::fill_triangle(Canvas &canvas, const Vec2f *triangle_positions, const Colorf &color, int num_vertices)
{
	int texindex = set_batcher_active(canvas, num_vertices);


	for (; num_vertices > 0; num_vertices--)
	{
		vertices[position].color = color;
		vertices[position].position = to_position(triangle_positions->x, triangle_positions->y);
		triangle_positions++;
		vertices[position].texcoord = Vec2f(0.0f, 0.0f);
		vertices[position].texindex = texindex;
		position++;
	}
}
示例#13
0
static int position_distanceto(lua_State* l)
{
    CelxLua celx(l);

    celx.checkArgs(2, 2, "One argument expected to position:distanceto()");
    
    UniversalCoord* uc = this_position(l);
    UniversalCoord* uc2 = to_position(l, 2);
    if (uc2 == NULL)
    {
        celx.doError("Position expected as argument to position:distanceto");
    }
    
    Vec3d v = *uc2 - *uc;
    lua_pushnumber(l, astro::microLightYearsToKilometers(v.length()));
    
    return 1;
}
示例#14
0
static int position_vectorto(lua_State* l)
{
    CelxLua celx(l);

    celx.checkArgs(2, 2, "One argument expected to position:vectorto");
    
    UniversalCoord* uc = this_position(l);
    UniversalCoord* uc2 = to_position(l, 2);
    
    if (uc2 == NULL)
    {
        celx.doError("Argument to position:vectorto must be a position");
    }

    celx.newVector(*uc2 - *uc);

    return 1;
}
示例#15
0
void CL_RenderBatch3D::fill(CL_GraphicContext &gc, float x1, float y1, float x2, float y2, const CL_Colorf &color)
{
	int texindex = set_batcher_active(gc);
	vertices[position+0].position = to_position(x1, y1);
	vertices[position+1].position = to_position(x2, y1);
	vertices[position+2].position = to_position(x1, y2);
	vertices[position+3].position = to_position(x2, y1);
	vertices[position+4].position = to_position(x2, y2);
	vertices[position+5].position = to_position(x1, y2);
	for (int i=0; i<6; i++)
	{
		vertices[position+i].color = CL_Vec4f(color.r, color.g, color.b, color.a);
		vertices[position+i].texcoord = CL_Vec2f(0.0f, 0.0f);
		vertices[position+i].texindex.x = (float)texindex;
	}
	position += 6;
}
示例#16
0
void RenderBatchTriangle::fill(Canvas &canvas, float x1, float y1, float x2, float y2, const Colorf &color)
{
	int texindex = set_batcher_active(canvas);

	vertices[position+0].position = to_position(x1, y1);
	vertices[position+1].position = to_position(x2, y1);
	vertices[position+2].position = to_position(x1, y2);
	vertices[position+3].position = to_position(x2, y1);
	vertices[position+4].position = to_position(x2, y2);
	vertices[position+5].position = to_position(x1, y2);
	for (int i=0; i<6; i++)
	{
		vertices[position+i].color = Vec4f(color.r, color.g, color.b, color.a);
		vertices[position+i].texcoord = Vec2f(0.0f, 0.0f);
		vertices[position+i].texindex = texindex;
	}
	position += 6;
}
示例#17
0
	void RenderBatchPath::render(const Path &path, PathRenderer *path_renderer)
	{
		for (const auto &subpath : path.get_impl()->subpaths)
		{
			clan::Pointf start_point = to_position(subpath.points[0]);
			path_renderer->begin(start_point.x, start_point.y);

			size_t i = 1;
			for (PathCommand command : subpath.commands)
			{
				if (command == PathCommand::line)
				{
					clan::Pointf next_point = to_position(subpath.points[i]);
					i++;

					path_renderer->line(next_point.x, next_point.y);
				}
				else if (command == PathCommand::quadradic)
				{
					clan::Pointf control = to_position(subpath.points[i]);
					clan::Pointf next_point = to_position(subpath.points[i + 1]);
					i += 2;

					path_renderer->quadratic_bezier(control.x, control.y, next_point.x, next_point.y);
				}
				else if (command == PathCommand::cubic)
				{
					clan::Pointf control1 = to_position(subpath.points[i]);
					clan::Pointf control2 = to_position(subpath.points[i + 1]);
					clan::Pointf next_point = to_position(subpath.points[i + 2]);
					i += 3;

					path_renderer->cubic_bezier(control1.x, control1.y, control2.x, control2.y, next_point.x, next_point.y);
				}
			}

			path_renderer->end(subpath.closed);
		}
	}