ProgrammingJavaScript

GL Line Structure Patch and JavaScript

toneburst's picture

Is it possible to use a JavaScript patch to create a structure to feed into a GL Line Structure patch?

I've tried this as a basic test, which takes in input structure from the Kineme Audio Input patch and creates a struct of points from it:

// Initialise objects
var points = new Object();
var levels = new Object();
 
function (__structure outputStructure) main (__structure inputStructure, __number dummy)
{
   // Adjustment variables
   var dist = 0.05;      // Distance between points on X-axis
   var offsetx = 0.25;   // Offset on X-axis
   var scaley = 5.0;      // Scale points on Y-axis
 
   // Copy input levels struct if not undefined
   if(inputStructure != undefined)
   {
      levels = inputStructure[0];
   }
 
   // Create points structure
   for(i = 0; i < 64; i++) {
      px = dist * i - offsetx;      // Point X
      py = levels[i] * scaley;      // Point Y
      points[i] = Array(px,py,0);   // Point XYZ
   }
 
   var result = new Object();
   result.outputStructure = points;
 
   return result;
}

The weird thing is, the items in the structure appearing at the output aren't in the right order. Any way to get the structure into the right order so that the resulting lines make some kind of sense?

a|x

lunch break games

psonice's picture

Out of boredom (I'm working off-site, with an old G4 powerbook that's not powerful enough to work on my current project) I decided to do some games in QC.

Before you fire them up, let me add a disclaimer: these were made during my lunch break, i.e. in under an hour. Expect no graphics, no sound, and very basic gameplay ;) They're also more experimental than serious attempts at playable games.

http://www.psonice.plus.com/canyonchopper.qtz - guide the helicopter down the canyon. Move your mouse to the middle of the screen and click to start.. it's mouse controlled. It takes a while to get going, but gets steadily harder. Actually the difficulty level stops increasing after you get to around 2,250 points, so anything past that is good going :)

http://www.psonice.plus.com/unpong.qtz - 1 player pong in reverse, or perhaps wrong arkanoid without bricks. Mouse control again, and click to start. You control the ball instead of the bat, and you have to hit the bat or it's game over. The bat slowly gets smaller. If you can't see the bat, resize your browser window so it's not as wide (the quartz plugin chops the bottom off the screen otherwise). Then again, not being able to see the bat is good if you're after an extra challenge (or honing your mastery of the force ;)

Anyone else done any games in it?

Multi-Pass GLSL Shader Patch

No idea if this is possible as a QC patch, but it would be incredibly cool to have support for multi-pass GLSL shaders in QC, so that the the geometry of one shader could be passed to another.

It would also be great to be able to run multiple GLSL patches at the same time (in an Iterator, for example), and have the geometry from all the instances combined into a single 3D scene (it's currently only possible to run multiple GLSL patches if you place each inside a Render In Image patch, and then of course, they're effectively all 2D images, rather than 3D objects, so can't be drawn convincingly together). This is possible in VVVV on the PC, and I've seen multi-pass GLSL shaders working in RenderMonkey, so I know it's theoretically possible, at least in OpenGL on Windows.

Cheers,

alx http://machinesdontcare.wordpress.com

Bug in javascript patch

psonice's picture

Just found an annoying bug in the javascript patch, this is on 10.5.2 but might affect older systems. So be warned, perhaps it'll save you a bit of head scratching.

Basically, the line length seems to be limited. I'm not sure if this affects all lines, but it definitely affects the line where you specify in/outputs for main. If your line is too long, it lets you type away but doesn't interpret past a certain point, resulting in an error telling you there's a mistake. (For me, it was saying that the main definition was invalid, or something like that).

The cure is to shorten your variable names - splitting it between multiple lines doesn't work (I guess it splits the code by ';' characters rather than new lines, but only alocates 256b for the line).

Bugs/Special features

psonice's picture

I think it would be good if people posted up compositions that highlight bugs or unexpected/undocumented features of QC (and any of the plugin patches) so the rest of us are aware of (and can abuse ;) them.

I'll start off as I suggested it.. I just figured out that it's possible to do feedback effects like motionblur without using the accumulator. If you use the Render in Image patch, and render to a billboard within it, it doesn't automatically clear the screen between frames so you get feedback straight away. If you create another billboard layer behind whatever is moving you remove the feedback effect, but by adjusting the Opacity of the lower layer you can control the amount of feedback.

The attachment shows the effect with a simple moving texture.