Forums > MaxMSP

Moving objects around jit.gl.renderer

May 14, 2014 | 10:04 am

I have a java script scene renderer that I am using to create objects and move them around the world. The problem I am seeing is that when I add an object to the world and try to move it, it does not update as expected. It looks like it is only moving along the X axis. But my trace output clearly shows I am setting both the x and y. I have included an example that demonstrates the problem.

Also, is there some rule of thumb as to what unit of measurement the world is using when moving objects?

Thanks,
Anthony

– Pasted Max Patch, click to expand. –

Rename code below as SceneRenderer.js

/////////////////////////////////////////////////////////////////////////////////////////////////////////
autowatch = 1;
inlets = 1;

var MAX_X = 50;
var MAX_Y = 50;
var MAX_Z = 50;

// Object Types
var OBJTYPE_SPHERE = 1;
var OBJTYPE_TORUS = 2;
var OBJTYPE_CYLINDER = 3;
var OBJTYPE_CYLINDER_OPEN = 4;
var OBJTYPE_CUBE = 5;
var OBJTYPE_CUBE_OPEN = 6;
var OBJTYPE_PLANE = 7;
var OBJTYPE_CIRCLE = 8;
var OBJTYPE_CONE = 9;
var OBJTYPE_CAPSULE = 10;
var OBJTYPE_VIDEO_PLANE = 11;

// global difinitions
var objectList = Array();
var cameraList = Array();
var objectCounter = 0;

TRACE("loading Scene Renderer")

// external attributes
var RendererContext;
var RendererName;
declareattribute("RendererContext", null, null, 1);
declareattribute("RendererName", null, null, 1);

// find out renderer
post("target renderer: " + RendererName + "\n");
var sceneRenderer = FindObj(RendererName);
if(sceneRenderer == null)
post("No gl renderer found.\n");

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Utility

function FindObj(objname)
{
return patcherTraverse(FindRoot().firstobject, objname);
}

function FindRoot()
{
var root = this.patcher;
while(root.parentpatcher != null)
root = root.parentpatcher;

return root;
}

function patcherTraverse(obj, objname)
{
while(obj != null) {

if(obj.varname == objname) {
return obj;
}

var subp = obj.subpatcher();
if (subp) {
var gotobj = patcherTraverse(subp.firstobject, objname);
if (gotobj) {
return gotobj; // only return if we got something!
}
}
obj = obj.nextobject;
}
return null;
}

function TRACE(msg)
{
post(msg + "\n");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Renderer state

function initRenderer()
{
post("Initializing renderer…");
objectList = Array();
cameraList = Array();
objectCounter = 0;

sceneRenderer = FindObj(RendererName);
if(sceneRenderer == null)
post("No gl renderer found.\n");

sceneRenderer.Clear();
}

var testObj;
function testMove(x, y, z)
{
var posStr = x + " " + y + " " + z;
post(posStr + "\n");
testObj.position = posStr;
}

function testCreate()
{
testObj = new JitterObject("jit.gl.gridshape", "render-ctx");
testObj.lighting_enable = 1;
testObj.position = "0 0 0";
}

function reset()
{
initRenderer();
//sceneRenderer.message("reset");
}


May 14, 2014 | 10:59 am

Hi Anthony,

I believe that position is expecting an array, so if you just do:

testObj.position = [x,y,z];

You should be all set.
-Ben


May 14, 2014 | 1:06 pm

Ahhhh that’s it! Thanks for pointing that out. Is there any documentation that states that this is the format it is expecting it to be in?

Also, is there some rule of thumb as to what unit of measurement the world is using when moving objects?


May 14, 2014 | 1:45 pm

You definitely don’t want to send a string, which was what was happening above. I think you can count on most things like this to be safe in arrays. If its a function that you are calling, you will generally use args.

An OB3D with a position of 0,0,0 places the center of the object in the middle of the screen. A "unit" of measurement in OpenGL is essentially arbitrary, and depends on the object, the viewport, and the context.

-Ben


Viewing 4 posts - 1 through 4 (of 4 total)