[javascript-dev] java, jit.gl.gridshape and textures
adam synnott
acro.mosh at gmail.com
Mon May 26 16:29:46 MDT 2008
- Previous message: [javascript-dev] Re: Handling coll objects from inside js objects
- Next message: [javascript-dev] java, jit.gl.gridshape and textures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
hi,
I'm trying quite unsuccesfully to apply a texture to each of the little planes in this script. the texture would be a still picture file.
here's the script so far.
var planes = 30; //number of particles
//yo
// inlets and outlets
inlets = 2;
outlets = 2;
//blob 1
var person00x
var person00y
//blob 2
var person01x
var person01y
//blob 3
var person02x
var person02y
//blob 4
var person03x
var person03y
//blob 5
var person04x
var person04y
//jit.window creation
var mywindow = new JitterObject("jit.window","wallpaper");
mywindow.depthbuffer = 0;
mywindow.idlemouse = 0;
//jit.gl.render creation
var myrender = new JitterObject("jit.gl.render","wallpaper");
//use a 2d projection
myrender.ortho = 2;
myrender.erase_color = [0,0,0,1];
// create an array of [jit.gl.gridshape] objects randomly arrayed across the window
var myplane = new Array(planes);
//for statment to create the planes
for(var i=0;i<planes;i++){
myplane[i] = new JitterObject("jit.gl.gridshape","wallpaper");
myplane[i].shape = "plane";
myplane[i].lighting_enable = 1;
myplane[i].smooth_shading = 1;
myplane[i].scale = [0.05,0.05,0.05];
myplane[i].color = [0.5,0.3,0.7,0.5];
myplane[i].position = [Math.random()*2.-1,Math.random()*2.-1];
myplane[i].blend_enable = 1;
//myplane[i].texture = "flowers";
}
//blob1
var person00 = new JitterObject("jit.gl.gridshape","wallpaper");
person00.shape = "sphere";
person00.lighting_enable = 0;
person00.smooth_shading = 0;
person00.scale = [0.05,0.05,0.05];
person00.color = [0.4,0.4,0.4,0.4];
person00.position = [Math.random()*2.-1,Math.random()*2.-1];
person00.blend_enable = 1;
//blob2
var person01 = new JitterObject("jit.gl.gridshape","wallpaper");
person01.shape = "sphere";
person01.lighting_enable = 0;
person01.smooth_shading = 0;
person01.scale = [0.05,0.05,0.05];
person01.color = [0.4,0.4,0.4,0.4];
person01.position = [Math.random()*2.-1,Math.random()*2.-1];
person01.blend_enable = 1;
//blob3
var person02 = new JitterObject("jit.gl.gridshape","wallpaper");
person02.shape = "sphere";
person02.lighting_enable = 0;
person02.smooth_shading = 0;
person02.scale = [0.05,0.05,0.05];
person02.color = [0.4,0.4,0.4,0.40];
person02.position = [Math.random()*2.-1,Math.random()*2.-1];
person02.blend_enable = 1;
//blob4
var person03 = new JitterObject("jit.gl.gridshape","wallpaper");
person03.shape = "sphere";
person03.lighting_enable = 0;
person03.smooth_shading = 0;
person03.scale = [0.05,0.05,0.05];
person03.color = [0.4,0.4,0.4,0.4];
person03.position = [Math.random()*2.-1,Math.random()*2.-1];
person03.blend_enable = 1;
//blob5
var person04 = new JitterObject("jit.gl.gridshape","wallpaper");
person04.shape = "sphere";
person04.lighting_enable = 0;
person04.smooth_shading = 0;
person04.scale = [0.05,0.05,0.05];
person04.color = [0.4,0.4,0.4,0.4];
person04.position = [Math.random()*2.-1,Math.random()*2.-1];
person04.blend_enable = 1;
function list()
{
//blob1
if (arguments.length>0)
person00x = arguments[0];
if (arguments.length>1)
person00y = arguments[1];
//blob2
if (arguments.length>2)
person01x = arguments[2];
if (arguments.length>3)
person01y = arguments[3];
//blob3
if (arguments.length>4)
person02x = arguments[4];
if (arguments.length>5)
person02y = arguments[5];
//blob4
if (arguments.length>6)
person03x = arguments[6];
if (arguments.length>7)
person03y = arguments[7];
//blob5
if (arguments.length>8)
person04x = arguments[8];
if (arguments.length>9)
person04y = arguments[9];
}
// drive the renderer
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.
for(var i = 0;i<planes;i++) {
// cartesian distance along the x and y axis
var distx = person00.position[0]-myplane[i].position[0];
var disty = person00.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];
}
}
//2
for(var i = 0;i<planes;i++) {
var distx = person01.position[0]-myplane[i].position[0];
var disty = person01.position[1]-myplane[i].position[1];
var r = Math.sqrt(distx*distx+disty*disty);
var theta = Math.atan2(disty,distx);
if(r<0.15)
{
var movex = (0.15-r)*Math.cos(theta);
var movey = (0.15-r)*Math.sin(theta);
myplane[i].position = [myplane[i].position[0]-movex, myplane[i].position[1]-movey];
}
}
//3
for(var i = 0;i<planes;i++) {
var distx = person02.position[0]-myplane[i].position[0];
var disty = person02.position[1]-myplane[i].position[1];
var r = Math.sqrt(distx*distx+disty*disty);
var theta = Math.atan2(disty,distx);
if(r<0.15)
{
var movex = (0.15-r)*Math.cos(theta);
var movey = (0.15-r)*Math.sin(theta);
myplane[i].position = [myplane[i].position[0]-movex, myplane[i].position[1]-movey];
}
}
//4
for(var i = 0;i<planes;i++) {
var distx = person03.position[0]-myplane[i].position[0];
var disty = person03.position[1]-myplane[i].position[1];
var r = Math.sqrt(distx*distx+disty*disty);
var theta = Math.atan2(disty,distx);
if(r<0.15)
{
var movex = (0.15-r)*Math.cos(theta);
var movey = (0.15-r)*Math.sin(theta);
myplane[i].position = [myplane[i].position[0]-movex, myplane[i].position[1]-movey];
}
}
//5
for(var i = 0;i<planes;i++) {
var distx = person04.position[0]-myplane[i].position[0];
var disty = person04.position[1]-myplane[i].position[1];
var r = Math.sqrt(distx*distx+disty*disty);
var theta = Math.atan2(disty,distx);
if(r<0.15)
{
var movex = (0.15-r)*Math.cos(theta);
var movey = (0.15-r)*Math.sin(theta);
myplane[i].position = [myplane[i].position[0]-movex, myplane[i].position[1]-movey];
}
}
//positional data
person00.position = [person00x,person00y];
person01.position = [person01x,person01y];
person02.position = [person02x,person02y];
person03.position = [person03x,person03y];
person04.position = [person04x,person04y];
// rendering block...
myrender.erase(); // erase the drawing context
myrender.drawclients(); // draw the client objects
myrender.swap(); // swap in the new drawing
}
function fullscreen(v)
// function to send the [jit.window] into fullscreen mode
{
mywindow.fullscreen = v;
}
and the patch is..
max v2;
#N vpatcher 361 113 1185 640;
#P origin 94 47;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 0 146 38 9109513 sel 102;
#P newex 0 118 40 9109513 key;
#P window setfont "Fixedwidth Serif" 10.;
#P message 0 229 83 9240586 fullscreen \$1;
#P toggle 0 203 15 0;
#P user pictslider 505 42 100 100 4 4 4 4 SliderDefaultKnob.pct 1 SliderDefaultBkgnd.pct 1 2163 0 15728640 320 1. 1.;
#P user pictslider 404 42 100 100 4 4 4 4 SliderDefaultKnob.pct 1 SliderDefaultBkgnd.pct 1 2163 0 15728640 320 1. 1.;
#P user pictslider 303 42 100 100 4 4 4 4 SliderDefaultKnob.pct 1 SliderDefaultBkgnd.pct 1 2163 0 15728640 320 1. 1.;
#P user pictslider 202 42 100 100 4 4 4 4 SliderDefaultKnob.pct 1 SliderDefaultBkgnd.pct 1 2163 0 15728640 320 1. 1.;
#P user pictslider 101 42 100 100 4 4 4 4 SliderDefaultKnob.pct 1 SliderDefaultBkgnd.pct 1 2163 0 15728640 320 1. 1.;
#P window setfont "Sans Serif" 9.;
#P newex 595 204 91 9109513 expr ($i1/240.)*2.-1.;
#P newex 505 173 91 9109513 expr ($i1/320.)*2.-1.;
#P newex 494 204 91 9109513 expr ($i1/240.)*2.-1.;
#P newex 404 173 91 9109513 expr ($i1/320.)*2.-1.;
#P newex 393 204 91 9109513 expr ($i1/240.)*2.-1.;
#P newex 303 173 91 9109513 expr ($i1/320.)*2.-1.;
#P newex 292 204 91 9109513 expr ($i1/240.)*2.-1.;
#P newex 202 173 91 9109513 expr ($i1/320.)*2.-1.;
#P newex 191 204 91 9109513 expr ($i1/240.)*2.-1.;
#P newex 101 173 91 9109513 expr ($i1/320.)*2.-1.;
#P newex 101 248 402 9109513 pak 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.;
#P toggle 22 175 15 0;
#P newex 20 200 50 9109513 qmetro 20;
#P newex 20 282 51 9109513 js adam.js;
#P comment 6 354 163 9109513 collision + textures == hapiness;
#P window linecount 2;
#P comment 7 373 171 9109513 of course we still have the open cv side to sort out too. yay for java;
#P connect 23 0 24 0;
#P connect 24 0 21 0;
#P connect 21 0 22 0;
#P connect 4 0 3 0;
#P fasten 5 0 2 0 106 274 25 274;
#P connect 3 0 2 0;
#P fasten 22 0 2 0 5 250 25 250;
#P connect 16 0 6 0;
#P connect 6 0 5 0;
#P connect 7 0 5 1;
#P connect 8 0 5 2;
#P connect 16 1 7 0;
#P connect 17 0 8 0;
#P connect 9 0 5 3;
#P connect 10 0 5 4;
#P connect 17 1 9 0;
#P connect 18 0 10 0;
#P connect 11 0 5 5;
#P connect 12 0 5 6;
#P connect 18 1 11 0;
#P connect 13 0 5 7;
#P connect 19 0 12 0;
#P connect 14 0 5 8;
#P connect 15 0 5 9;
#P connect 19 1 13 0;
#P connect 20 0 14 0;
#P connect 20 1 15 0;
#P pop;
if anyone could help out with this i'd really apreciate it.
also are there and tutorials out there on this type of scripting?
best
adam
- Previous message: [javascript-dev] Re: Handling coll objects from inside js objects
- Next message: [javascript-dev] java, jit.gl.gridshape and textures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
