i have one dimensional (1 cell per object), 3 plane (xyz) matrices
- dir // think of this as a 'bounce' property for each plane (component). either +1 or -1. This is what I flip when an object hits a wall. (I don't want to flip the sign of the vel matrix on bounce, because it's being written into by external processes. So I want to store the 'flippedness' in a separate matrix).
pos = vel * dir + pos
this is easy with jit.+ and jit.*
but I also want to bounce (i.e. flip the sign of dir) of any individual cell plane, when the current cell plane value goes beyond a threshold. And the threshold is dependent on the plane.
i.e. my world boundary is [xmin ymin zmin] -> [xmax ymax zmax]
Hi Jesse, yes apologies there was a typo in my code. I've fixed that now.
thanks for the sample, I've learnt a lot from it. though the conditional multiplication mask for dir matrix has lots of zeros in it. That would zero out the dir matrix. Wouldn't they need to be 1, not 0?. What's a good way of doing that? Based on what you've done I've attempted to do this by jit.== against a freshly initted jit.matrix (full of zeros) and then add to your conditional mask (which is 0s, and -1s) to give the multiplication matrix (1s and -1s), which I can multiply my dir matrix with. Or is there a quicker way?
Wow, thanks for sending me on the delicious rabbit hole that is gen! I'd never seen it before, I wish I knew about it a year ago.
I'd love to be able to do this whole thing in jit.gen / codebox, I was hoping I could do it in 3 lines of code! But i was wrong. I'm still getting stuck on flipping only some components of dir, not all simultaneously. I've attached my patch, and just the codebox code (most of it is for readability, the actual code is just 3 lines. ). is it possible to do the bounce in codebox?
Param mins(-1., -2., -3.);
Param maxs(1., 2., 3.);
pos = in1;
vel = in2;
dir = in3;
pos += vel * dir;
//dir[posmaxs)] *= -1; // this is what I really want to do
if(pos=maxs) dir*= -1; // this only checks the first component of the vector, and flips the entire dir vector
out2 = dir;
pos = clamp(pos, mins, maxs);
out1 = pos;