Can't create 2D array

PVector pos;
float yaw;
float pitch;
float roll;
float[][] rmx;
PVector posinit;

void setup() {

  size(640, 360, P3D);
  pos = new PVector(width/2, height/2, 0);
  posinit = new PVector(width/2, height/2, 0);
  yaw = PI/8;
  pitch = PI/12;
  roll = PI/10;
  rmx = {{cos(yaw)*cos(pitch), cos(yaw)*sin(pitch)*cos(roll) - sin(yaw)*cos(roll), cos(yaw)*sin(pitch)*cos(roll) + sin(yaw)*sin(roll) },
         {sin(yaw)*cos(pitch), sin(yaw)*sin(pitch)*sin(roll) + cos(yaw)*cos(roll), sin(yaw)*sin(pitch)*cos(roll) - cos(yaw)*sin(roll) },
         {-sin(pitch), cos(pitch)*sin(roll), cos(pitch)*cos(roll)}};
}

it shows me an error called “bad identifier” at line where i put the values for “rmx”

my apologies if its something stupid

Hello,

Consider:

  rmx =  new float [] [] 
         {
         {cos(yaw)*cos(pitch), cos(yaw)*sin(pitch)*cos(roll) - sin(yaw)*cos(roll), cos(yaw)*sin(pitch)*cos(roll) + sin(yaw)*sin(roll) },
         {sin(yaw)*cos(pitch), sin(yaw)*sin(pitch)*sin(roll) + cos(yaw)*cos(roll), sin(yaw)*sin(pitch)*cos(roll) - cos(yaw)*sin(roll) },
         {-sin(pitch),         cos(pitch)*sin(roll),                               cos(pitch)*cos(roll)                               } 
         };

I looked for some references on initializing an array and found this:

:)

1 Like

Dunno might be that this only works outside any function

thanks fam it worked

i just had to initialize it once outside setup() and then put the values like you did inside the setup

2 Likes

its weird that if i do the entire array thing outside setup then it doesnt give me error but doesnt work either

1 Like