stackgl / shader-school

:mortar_board: A workshopper for GLSL shaders and graphics programming
Other
4.28k stars 252 forks source link

Exercise 6... no looping allowed? #104

Open maxscott opened 9 years ago

maxscott commented 9 years ago

I understand if the goal is to get the total-n00b (me :point_left:) to write a solution without any loops, but it isn't terribly clear that you can't do that based on the previous lessons and the exercises instructions. I got a message about using a for loop without a "constant" because it relies on the param, and a message that while's were 'not allowed' or something to that effect. I remember recursion was out, but I tried it just for kicks.

If there are such contraints in general, maybe during the intro to looping these constraints could be made known?

mwalczyk commented 9 years ago

Yeah I agree with this. A little further explanation here would've helped.

sparkmorry commented 8 years ago

I am having the same problem, though n is given 1<n<16, I can't figure out a way to tell the machine = =

ambethia commented 8 years ago

@sparkmorry I solved it like this:

  if(n == 0) return mat2(1.0);
  mat2 p = m;
  for(int i = 1; i < 16; i++)
  {
    if (i < n)
    {
      p = p * m;
    } else {
      return p;
    }
  }

I don't know if it's the best answer? but It works.