Home > code, jitter > going OOP with jitter-java

going OOP with jitter-java

There is a big question mark over the question if jitter is OOP or not. It might be. However, for generating big amount of instances I still consider java(or c++) as the best way to go. It is possible to create interfaces or import external libraries to our jitter matrices(like processing’s traer physics).
A simple example:
I create a class called PointA

import java.util.Random;

public class PointA {
private float x,y,z,quantity;
private int direction=-1;
private Random dd1=new Random();
private int dd2=0;

PointA(){

}

PointA(float x,float y, float z, float quantity){
this.x=x;
this.y=y;
this.z=z;
this.quantity=quantity;

}

public void setup(){
dd2=dd1.nextInt(2);
if(dd2==0){
direction =-1;
}else{
direction = 1;
}
}

public void update(){

x +=quantity*direction;
if(x>0.8f || x0.8f || y<=-0.8f){
direction *=-1;
}

z=0.0f;
}

public float getXPos(){
return x;
}

public float getYPos(){
return y;
}

public float getZPos(){
return z;
}

public void draw(){

}

}

then we make it usable for the jitter matrix:


import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

import com.cycling74.max.*;
import com.cycling74.jitter.*;
import com.cycling74.jitter.JitterMatrix;
import com.cycling74.max.AttributeInfo;
import com.cycling74.max.DataTypes;
import com.cycling74.max.MaxObject;

public class MxGLBegin2a extends MaxObject{

//PointA mPoint;
int amount=50;
float[] x=new float[amount];
float[] y=new float[amount];
float[] z=new float[amount];
Random quant=new Random();
PointA[] mPoints=new PointA[amount];
JitterMatrix p1=new JitterMatrix(3,”float32″,amount);

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

//mPoint= new PointA(0.0f,0.0f,0.0f,0.1f);

for(int i=0;i<amount;i++){
float rx=(float)Math.random()-0.5f;
float ry=(float)Math.random()-0.5f;
float rz=0.0f;
//float rq=(float)Math.random()-0.8f;
float rq=(quant.nextInt(3)*0.001f)+0.01f;;
//post("rq value is: "+rq);
mPoints[i]=new PointA(rx,ry,rz,rq);
mPoints[i].setup();
}

}

public void bang(){
int plane=0;
int dim=0;
int[] offset=new int[]{0};
int count=amount;
int arrayoffset=0;

for(int i=0;i<amount;i++){
mPoints[i].update();
x[i]=mPoints[i].getXPos();
//post("value x: is " + mPoints[i].getXPos());
y[i]=mPoints[i].getYPos();
z[i]=mPoints[i].getZPos();
}

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

outlet(0,"jit_matrix",p1.getName());
}
}

here the max patch:
———-begin_max5_patcher———-
865.3ocyX1saaBCFF93jqBKzNLKBa9IvNpamrS5tBlphLAWp6.SK1QIcU8de
Fanoo0Y3zDHnD4.Fi40O9yuel77zINIkaIbGv2.+FLYxySmLQUUcESZNehSA
d6pbLW0LmayKYqKblouDMUUYYx8eEE0V4skLACWPTW56UTbd6Uj2IkkSDptB
tqxx0h1ZQuoS3z+p5j34tM0pan3oGHZMWKGrvYFvIAyxb.2zztGvhU2QYYKq
HqD5lhh7kcCHbQcYfacITdL3l563koSqKlYIDJHbNNizNrDjspGhyCkTlXYs
rAeAZhQgGIiPFYD73XjMXIVAjP0wvfOIVXjMxQ4Gnh.3NGBPt.TrIl3eVha7
9jwMxIr1e9eXx2UG8nvTf2IE8b.LIUTpJJ9iLBFdVXzQF2z4RpFn3EUW5GcZ
PYcQBoxzXO9R3qzDVzIBf5gMJL7LXqbXuU2ws2JL.oF3998n4JoByIKWUlWV
IMTZ9ZzlEFM5rYaITiCqqaeXz9XNsntuMfjEiOhfTDAEqLS8CNoXlj0BQIyv
3N7SXOd7FgPWndrn+wssbfROfFkYGz4J0kmXxgCYITQ3DwLPZEdSAVTQ2BJd
5ZJivApchwM4MLBWI3EraKXPeTeXMbOULOKeN+OD4iGvWUQHLvUZyTXymqRx
IrzkDFVdvtyKJSIfv5yey1a8Lg1fKQVp5DT1fWndYoWPPer4sZ9tgxRK27Jb
ukiw.iom7uDbR6czAqzqVQPcnHr2PkLTrRFaQpdkV6kcW8wH57F4nCF0r4md
4UDD.El.IlPC5RfFkdrZOhM7Qu4P+vSBOhxrrbhIH.OG4665kA0CkX29KY+i
EDQUI.YZqbwWhDX1N8pwQ.ruLN1OMuA5bQ9WnjJaoVYcmMRuUQOMuhb6CPUr
8dvu19yq+AIixPXSqSFmYpaXimlM9FYipCbxUS+68+Vp5v552GX7x0UqZkPq
GgL8RqNRIbAkgET46OrqQw60l6nooD0kaGbEzzlsXptmCL6YqjhsPQ096iLI
sXPUTnMPZPUjMARQCqhP1.IugWSvwklrBSvwmjF1Ubu6wc.MELrXx0FMMvq5
hFeq5VL9bKsMkBb3BlrYhCENrA3givEc91XgGO7Zpy4N2gMD2l4t2I7AgSnt
zzoXXJO4ko+CoBgdtC
———–end_max5_patcher———–

You can compile the example using your favorite IDE(Eclipse!) or directly on the terminal using the javac.
Next time I will post an example of how to use some processing native libraries with jitter.

About these ads
Categories: code, jitter
  1. March 28, 2011 at 5:52 am

    Hello Emmanuel,

    Interesting tutorial, but It seems the maxpat above gives nothing.
    Since it is compressed it is hard to understand what’s the issue in parsing the code.
    Could it be possible to get the source of your patch?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: