XML Feeds

.

[javascript-dev] Re: java, jit.gl.gridshape and textures

adam synnott acro.mosh at gmail.com
Thu May 29 07:03:35 MDT 2008


Hi,
I took all your advice and rewrote the script... 
a new problem occured when i started to experimetn with textures.
My texture has black in the corners which i'd like to get rid of. In jitter i'd usually get rid of it with a jit.op @op max object. I attempted to do this in js. any suggestions?

js



autowatch = 1 // turn off when not coding

//blobs
var persons = 5;
var myperson = new Array(persons);
//particles
var planes = 100;
myplane = new Array(planes);
var op = planes;
myop = new Array(op);


//render
var myrender = new JitterObject("jit.gl.render","test");
myrender.ortho = 2;
myrender.erase_color = [0,0,0,1];

//jit window
var mywindow = new JitterObject("jit.window","test");
mywindow.depthbuffer = 0;
mywindow.idlemouse = 0;
mywindow.mode = "texture"
mywindow.interp = 1;



var mytexture = new JitterObject("jit.gl.texture","test");
mytexture.name = "flower";

var mywallpaper = new JitterObject("jit.gl.texture","test");
mywallpaper.name = "wallpaper";


for(i=0;i<planes;i++){
myplane[i] = new JitterObject("jit.gl.gridshape","test");
myplane[i].shape = "plane";
myplane[i].lighting_enable = 1;
myplane[i].smooth_shading = 1;
myplane[i].scale = [0.05,0.05,0.0];
myplane[i].color = [1.0,1.0,1.0,1.0];
myplane[i].position = [Math.random()*2.-1,Math.random()*2.-1];
myplane[i].blend_enable = 1;
myplane[i].texture = "flower";
myplane[i].matrix_output = 1;

//jit.op attempt
//myop[i] = new JitterObject("jit.op")
//myop[i].op = ("max",myplane[i]);
}



var planepaper = new JitterObject("jit.gl.gridshape","test");
planepaper.shape = "plane";
planepaper.lighting_enable = 1;
planepaper.smooth_shading  = 1;
planepaper.scale = [1,1,0.1];
planepaper.color = [1,1,1,1];
planepaper.position = [0,0];
planepaper.blend_enable = 1;
planepaper.texture = "wallpaper";


for(i=0;i<persons;i++){
myperson[i] = new JitterObject("jit.gl.gridshape","test");
myperson[i].shape = "sphere";
myperson[i].lighting_enable = 0;
myperson[i].smooth_shading = 1;
myperson[i].scale = [0.05,0.05,0.0];
myperson[i].color = [0,0,0,1];
myperson[i].position = [Math.random()*2.-1,Math.random()*2.-1];
myperson[i].blend_enable = 1;
}




function list(idx,xx, yy)
{

myperson[idx].position = [xx,yy,0.0];

}


function bang()
{
//1
	// collision detection block. we need to iterate through 
	// the little spheres and check their distance from the control 
	// object. if we're touching we move the little sphere away 
	// along the correct angle of contact.
	
var i,j,distx,disty,r,theta,movex,movey;

for(j=0;j<persons;j++){

		for(var i = 0;i<planes;i++) { 
		// cartesian distance along the x and y axis
		var distx = myperson[j].position[0]-myplane[i].position[0]; 
		var disty = myperson[j].position[1]-myplane[i].position[1]; 

		// polar distance between the two objects
		var r = Math.sqrt(distx*distx+disty*disty); 
		// angle of little sphere around control object
		var theta = Math.atan2(disty,distx); 

		// check for collision...
		if(r<0.15) 
		// control object is size 0.1, little spheres are 0.05, 
		// so less than 0.15 and it's a hit...
		{
			// convert polar->cartesian to figure out x and y displacement
			var movex = (0.15-r)*Math.cos(theta); 
			var movey = (0.15-r)*Math.sin(theta); 

			// offset the little sphere to the new position, 
			// which should be just beyond touching at the 
			// angle of contact we had before. the result 
			// should look like we've "pushed" it along...
			myplane[i].position = [myplane[i].position[0]-movex, myplane[i].position[1]-movey];
		}
	}

}
//outlet
//outlet(0,"jit_matrix",test.name);
//rendering block
myrender.erase(); // erase the drawing context
myrender.drawclients(); // draw the client objects
myrender.swap(); //swap in the new drawing

}

function fullscreen(v)
{
mywindow.fullscreen = v;
}

function jit_matrix(inname)
{
mytexture.jit_matrix(inname);
mywallpaper.jit_matrix(inname);


patch is

max v2;
#N vpatcher 452 182 1052 582;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 144 165 19 9109513 t b;
#P newex 144 143 40 9109513 key;
#P toggle 144 191 15 0;
#P message 159 247 62 9109513 fullscreen \$1;
#P message 31 208 52 9109513 read \, bang;
#P newex 31 230 55 9109513 jit.qt.movie;
#P newex 194 206 49 9109513 prepend 0;
#P newex 284 161 81 9109513 scale 0 127 -1. 1.;
#P newex 194 161 81 9109513 scale 0 127 -1. 1.;
#P user pictslider 194 59 100 100 4 4 4 4 SliderDefaultKnob.pct 1 SliderDefaultBkgnd.pct 1 2163 0 8323072 127 1. 1.;
#P newex 194 184 50 9109513 pack 0. 0.;
#P toggle 98 212 15 0;
#P newex 98 232 45 9109513 metro 20;
#P newex 98 263 56 9109513 js person.js;
#P connect 9 0 8 0;
#P connect 2 0 1 0;
#P connect 10 0 0 0;
#P connect 7 0 0 0;
#P connect 1 0 0 0;
#P fasten 8 0 0 0 36 256 103 256;
#P connect 12 0 13 0;
#P connect 13 0 11 0;
#P connect 11 0 10 0;
#P connect 4 0 5 0;
#P connect 5 0 3 0;
#P connect 3 0 7 0;
#P fasten 6 0 3 1 289 182 239 182;
#P connect 4 1 6 0;
#P pop;

am i even close to being on the right track?
best 
adam


More information about the javascript-dev mailing list