Hey,
I’ve been learning matrix multiplication, but problems started while trying to setup a PVector that utlilzes a matmul function similar to Daniel Schiffman’s example for making 3D projections. I ran into problems when I wanted to perform this specific method of matrix multiplication: " PVector projected2d = matmul(projection, v);" Even if I copy the whole Schiffman example to that point the same error pops up.
Processing 3+ gives this error in the console
The function “matmul()” expects parameters like: “matmul(float[][], float[][])”
I figured that since the example is few years old maybe the syntax changed? Maybe somebody knows a workaround?
Thanks guys!
Here's the rest of the code. Tab 1:
--
float angle = 0;
PVector [] points = new PVector[4];
float[][] projection = {{1, 0, 0}, //
{0, 1, 0}
};
int w = 600;
int h = 400;
void settings() {
size(w, h);
}
void setup() {
points[0] = new PVector(50, 50, 0);
points[1] = new PVector(50, -50, 0);
points[2] = new PVector(-50, 50, 0);
points[3] = new PVector(-50, -50, 0);
}
void draw() {
background(0);
translate(width/2, height/2);
stroke(255);
strokeWeight(15);
noFill();
for (PVector v : points){
PVector projected2d = matmul(projection, v);
// PVector transformed2d = matmul(projected2d, trans2d);
// point(projected2d.x, projected2d.y);
//point(v.x, v.y);
}
angle += 0.01;
}
----
tab 2:
----
PVector v = new PVector(100, 75, 50);
float[][] vecToMatrix(PVector v){ // the matrix recieves the values of the introduced Vector v
float[][] m = new float[3][1];
m[0][0] = v.x;
m[1][0] = v.y;
m[2][0] = v.z;
return m;
}
PVector matrixToVec(float[][]m){ // receives the Matrix m
PVector v = new PVector();
v.x = m[0][0];
v.y = m[1][0];
if (m.length > 2){
v.z = m[2][0];
}
return v;
}