Archive

Archive for the ‘jitter’ Category

Inspired slicing

Slicing geometries in jitter, very much inspired by my own work with vvvv. So the ‘getSlice’ becomes a ‘zl slice’, hlsl turns into glsl and c# into java. Pretty much back and forth on the parallel world!
I find very interesting how the same approach creates a different result depending on the system that is being used; a different view for the same mind set.

Some of these materials might find its way into the ‘worm songs’…

join all the parts

join all the parts

join all the parts

Categories: glsl, java, jitter

Tutorial 46 to java

I had the impression that the only “official” particle system example on jitter( tutorial 46) was rather slow using javascript so I ported it to java. The porting was really straight forward and I think it might be a nice study source. Notice that the methods bang_expr() and bang_iter() are not implemented( yet!).
Hope someone finds this useful.


import com.cycling74.max.*;
import com.cycling74.jitter.*;
import java.io.*;

public class MxTutorial46b extends MaxObject{
int PARTICLE_COUNT = 1000;
int ATTRACTOR_COUNT = 3;
JitterObject noisegen;
JitterObject attgen;
JitterObject myexpr;
JitterObject myexpr2;
//matrices
JitterMatrix particlemat;
JitterMatrix velomat;
JitterMatrix attmat;
JitterMatrix distmat;
JitterMatrix tempmat;
JitterMatrix summat;
JitterMatrix summat2;
JitterMatrix scalarmat;
JitterMatrix amat;

float a = 0.001f;
float d = 0.01f;
//String perform_mode = “op”;
//String perform_mode;
int perform_mode;
//String draw_primitive = “points”;
String draw_primitive;

public MxTutorial46b(){
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});

//perform_mode = new String(“op”);
perform_mode = 0;
draw_primitive = new String(“points”);

//declare the noise objects
//noisegen = new JitterObject(“jit.noise”,”float32″);
noisegen = new JitterObject(“jit.noise”);
noisegen.setAttr(“dim”, PARTICLE_COUNT);
noisegen.setAttr(“planecount”,3);
noisegen.setAttr(“type”, “float32”);

attgen = new JitterObject(“jit.noise”);
attgen.setAttr(“dim”, ATTRACTOR_COUNT);
attgen.setAttr(“planecount”, 3);
attgen.setAttr(“type”, “float32”);

myexpr = new JitterObject(“jit.expr”);
myexpr.setAttr(“expr”, “in[0].p[0]+in[0].p[1]+in[0].p[2]”);
// second expression: evaluate a+((b-c)*d/e)

myexpr2 = new JitterObject(“jit.expr”);
myexpr2.setAttr(“expr”, “in[0]+((in[1]-in[2])*in[3]/in[4])”);

//matrices declaration
particlemat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
velomat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
attmat = new JitterMatrix(3,”float32″,ATTRACTOR_COUNT);
distmat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
tempmat = new JitterMatrix(3,”float32″, PARTICLE_COUNT);
summat = new JitterMatrix(3,”float32″, PARTICLE_COUNT);
summat2 = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
scalarmat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
amat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);

init();

post(“this is a port of tutorial 46!\n”);
}

public void init(){
noisegen.matrixcalc(particlemat, particlemat);
particlemat.op(“*”, 2.0f);
particlemat.op(“-“, 1.0f);
// generate a matrix of random velocities spread between -1 and 1
noisegen.matrixcalc(velomat, velomat);
velomat.op(“*”, 2.0);
velomat.op(“-“, 1.0);
// generate a matrix of random attractors spread between -1 and 1
attgen.matrixcalc(attmat, attmat);
attmat.op(“*”, 2.0);
}

public void bang(){
switch(perform_mode) { // choose from the following…
case 0: // use Jitter matrix operators
bang_op();
break;
case 1: // use [jit.expr] for the bulk of the algorithm
bang_expr();
break;
case 2: // iterate cell-by-cell through the matrices
bang_iter();
break;
default:
bang_op();
break;
}

outlet(0,”jit_matrix”,particlemat.getName());
}

public void bang_op(){
//int plane = 0;

for(int i =0;i<ATTRACTOR_COUNT;i++){
scalarmat.setall(attmat.getcell1d(i));
tempmat.op("-", scalarmat, particlemat);
distmat.op("*", tempmat, tempmat);

//summat.planemap = 0;
summat.setAttr("planemap", 0);
summat.frommatrix(distmat);
summat.setAttr("planemap", 1);
summat.frommatrix(distmat);
summat.setAttr("planemap", 2);
summat2.frommatrix(distmat);
summat.op("+", summat, summat2);

tempmat.op("*", a);
// divide our distances by the sum of the distances
// to derive gravity for this frame:
tempmat.op("/", summat);
// add to the current velocity bearings to get the
// amount of motion for this frame:
velomat.op("+", tempmat);
}

particlemat.op("+", velomat);
// reduce our velocities by the decay factor for the next frame:
velomat.op("*", d);
}

public void bang_expr(){
//not implemented yet

}

public void bang_iter(){
//not implemented yet

}

public void particles(int v){
PARTICLE_COUNT = v;

// resize matrices
noisegen.setAttr("dim", PARTICLE_COUNT);
particlemat.setAttr("dim", PARTICLE_COUNT);
velomat.setAttr("dim", PARTICLE_COUNT);
distmat.setAttr("dim", PARTICLE_COUNT);
attmat.setAttr("dim",PARTICLE_COUNT);
tempmat.setAttr("dim", PARTICLE_COUNT);
summat.setAttr("dim", PARTICLE_COUNT);
summat2.setAttr("dim", PARTICLE_COUNT);
scalarmat.setAttr("dim",PARTICLE_COUNT);
amat.setAttr("dim",PARTICLE_COUNT);

init(); // re-initialize particle system
}

public void attractors(int v){
ATTRACTOR_COUNT = v;

attgen.setAttr("dim", ATTRACTOR_COUNT);

init();
}

public void accel(int v){
a = v * 0.001f;
}

public void decay(int v){
d = v * 0.001f;
}

// public void mode(String v){
// perform_mode = v;
// }

public void mode(int v){
perform_mode = v;
}

public void primitive(String v){
draw_primitive = v;
}

/*
function smear(v) // turn on drawing smear by zeroing the alpha on the renderer's erase color
{
if(v) {
// smear on (alpha=0):
outlet(0, "erase_color", 1., 1., 1., 0.);
}
else {
// smear off (alpha=0.1):
outlet(0, "erase_color", 1., 1., 1., 0.1);
}
}
*/

}

NOTE: WORDPRESS SUCKS!!!, I HAVE TRIED TO UPLOAD THE MAX PATCH BUT SOMEHOW IT DOESN’T WORK ON COPY COMPRESSED FORMAT. I WILL MIGRATE MOST OF MY POSTS TO MY WEBPAGE AND WILL ZIP MOST OF THE MATERIALS. MEANWHILE YOU CAN REQUEST ME DIRECTLY THE MAX PATCH!

Categories: code, java, jitter

So the controversy continues…

For sure one of the most interesting and elusive topics I have dealt with the last months has been the idea of porting processing libraries to jitter. I’ve gotten a lot of feedback from different friends that are( by far) more proficient java users.
But first an important question: why bothering porting libraries from an applet-based programing language into jitter. Many possible answers can be given, some of them as simple as to say it is an interesting challenge. However, the tool of having java inside jitter provides an interesting window to some of the functionalities that are not ‘native’ to the way jitter handles visuals. Let’s put as a very simple example the traer physics engine: it is a very simple and elegant way to handle physical modeling. So why not using such nice facility within jitter?
Second interesting point to deal with is the way things should be implemented. As far as my understanding goes jitter manages only planar arrays( not multidimensional). There are two basic methods to assign the value of each one of the members:
-copyArrayToVectorPlanar
-setcell

so far I am not sure which one of the methods is better. Or even better, as both methods seem to be quite efficient their usage criteria falls more into specific needs.
Take the next example:
case 1-a random cluster of lines. Then to have something like this on the bang() method:

int plane=0;
int dim=0;
int[] offset=new int[]{0};
int count=amount;
int arrayoffset=0;

for(int i=0;i<amount;i++){
x[i]=(float)Math.random()-0.5f;
y[i]=(float)Math.random()-0.5f;
z[i]=(float)Math.random()-0.5f;
}

gl1.copyArrayToVectorPlanar(plane,dim,offset,x,count,arrayoffset);
plane=1;
gl1.copyArrayToVectorPlanar(plane,dim,offset,y,count,arrayoffset);
plane=2;
gl1.copyArrayToVectorPlanar(plane,dim,offset,z,count,arrayoffset);

from here it would be easier to use the sketch object providing ‘raw’ gl commands. Notice that each plane is filled with an array of values coming from the for loop( don’t forget to declare your arrays or containers!).

case 2- using a wrapper to gain a more ‘literal’ version of the processing original patch into jitter’s matrixland. So for instance:

public void toMatrix(JitterMatrix jm) {
if (jm == null) { return;}
final int size = (jm.getDim()[0] >= _particles.size()) ? _particles.size() : jm.getDim()[0] ;
if (_particles.isEmpty()) {
populateParticleList();
}
Vector3D vec = null;

for (int i = 0; i < size; i++) {
vec = _particles.get(i).position();
pos[0] = i;
jm.setcell(pos, 0,(vec.x() – 200.0f) / 200.0f );
jm.setcell(pos, 1,(vec.y() – 200.0f) / 200.0f );
jm.setcell(pos, 2,(vec.z() – 200.0f) / 200.0f );
}
}
/**
* run once in setup, after all elements of the system are created
*/
protected final void populateParticleList() {
for (int i = 0; i < _ps.numberOfParticles(); i++) {
//
_particles.add(i, _ps.getParticle(i));
}
}

So far I am still trying to put my hands on this approach( thanks Panos for the eye opener!). Not sure if this is more efficient or easier( this type of implementation relies deeply on overriding methods).

We will see, I will try to post more examples as soon as I can!

P.S.By opening the source of the traer physics I was kinda of amazed how old the java lang used on the package seemed to be. There are not even containers on them! Still the library is super cool!

Categories: code, jitter, processing

Bump map on jitter

This is a simple bump map shader made on GLSL and using jitter as the launching app. It is nice, I amazed how many improvements the C74 development team has made during the last updates. I am planning to start using this kind of texture mappings with more complex vertex functions. The result could be nice, let’s hope!

Here are the small tests:

I will try to clean up the code a little bit(somehow I am really messy when prototyping shaders in jitter) and post the source code here.

Categories: glsl, jitter

setcell vs copyArrayToVectorPlanar method

Java/jitter offers two different ways to ‘fill up’ matrices: setcell and copyArrayToVectorPlanar. So far I find the second cleaner and more efficient. However, the criteria for their use might be related with the context of use. Herewith a small example of how to use setcell in order to create a random jitter matrix:


import com.cycling74.max.*;
import com.cycling74.jitter.*;
import java.util.Random;

public class SetMe extends MaxObject{
Random rrand;
JitterMatrix jl;
static final int PLANES=3;

public SetMe(){
//super();
//declareIO(1,2);
jl=new JitterMatrix(“hehe”,PLANES,”float32″,10,10);
this.rrand=new Random();
}

public void bang(){
this.calculateMe();
outlet(0,”jit_matrix”,jl.getName());
}

public void calculateMe(){
for(int k=0;k<PLANES;k++){
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
jl.setcell(new int[]{i,j},k,rrand.nextInt(10));
}
}
}
}
}

It is important to notice how copyArrayToVectorPlanar uses a single dimension loop to fill the matrix, whereas setcell requires two values to point the location of each one of the values. Maybe here is the bottleneck for this method?

Categories: jitter

Wormer songs

For the last months I have been working, step by step, on a project ‘Worm Songs’ for composer/sound artist Henry Vega. The project consist of a one hour long performance of songs for voice and live electronics. We are still nailing down lot of things for it, but now we have the first small teaser!
So far the interaction design is almost ready but there are many things to improve, in particular with the ‘make up’ of the images. Let’s make them shinny!
I love the music, very inspiring!

http://vimeo.com/15708129

The address for Henry’s web page is:

http://www.henryvega.net/main/index.php

Categories: jitter

Florito++Flores = inspiration!

February 8, 2011 Leave a comment

We are currently preparing a foyer installation for the CaDance Festival in Den Haag, Netherlands:


http://www.cadance.nl/

I am having the enormous pleasure of working with my friend Marcus Graf:

http://www.marcusgraf.com/

http://www.florito.net

All i can say is that the level of inspiration is at the top. It is fantastic to have the chance to exchange code, view and good times with such a skilled and amazing software artist.
We have been playing with the Kinect and making vector fields with it. What you actually see is my hand waving around. We expect to have lot of nice code and fun the coming days!


Categories: code, jitter