I'm doing Sierpinski carpet using recursion. In function DrawCarpet in linen, where I redefine a value I got error "To many initializer values". Do somebody know what I'm doing wrong?
typedef float point[2];
float x = 100;
float y = 100;
point a = { x , y };
int grade = 4;
void DrawCarpet(point a, GLfloat width, GLfloat grade)
{
if(grade>0)
{
width = width / 3;
DrawCarpet(a, width, grade - 1);
a = { x - width , y };
DrawCarpet(a, width, grade - 1);
a = { x - 2*width , y };
DrawCarpet(a, width, grade - 1);
a = { x , y-width };
DrawCarpet(a, width, grade - 1);
a = { x , y-2*width };
DrawCarpet(a, width, grade - 1);
a = { x - width , y-width };
DrawCarpet(a, width, grade - 1);
a = { x - width , y -2*width };
DrawCarpet(a, width, grade - 1);
a = { x -2* width , y -2*width };
DrawCarpet(a, width, grade - 1);
a = { x,y };
}
}
The type of parameter a
is not array of 2 float
but rather float*
(because of array to pointer decay , also because your function parameter shadows the global variable). So what you're trying to do is assign two values to a pointer variable. Try using a struct with two members as a point type instead, and pass that by reference if you want to assign to it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.