Forums > Javascript

javascript gl.sketch start


Jun 07 2012 | 9:09 am

hi i want to create a js which creates an sketch object with drawing triangels by hand. my problem is, i couldn’t figure out how to create them in js. with jit tutorial 40 an 47. but there are no sketch objects. thanks
the command
mysketch.shape = ["tri",x….z] doesent work

thanks for your help


Lee
Jun 07 2012 | 11:17 am

At work at mo, so can’t try it, but here’s some example code using gridshape that might help you:

obj = new JitterObject( "jit.gl.gridshape", dest );
obj.shape = "plane";
obj.scale = [ 0.095, 0.040, 1 ];
obj.color = [ 0.3, 0.3, 0.3, 1 ];
obj.position = render.screentoworld( x, y );

i think if you add:
obj.gridmode = 1;

it will output triangles, but not sure as I’ve only used this for drawing quads.

not sure what the performance is either using sketch against shape, would be interested to know.

anyway, hope this helps you figure out what you need

Jun 07 2012 | 1:51 pm

This is the same construct i am using for creating spheres and cubes. The problem is, i know how to create the jitter sketch object
sketch = new JitterObject("jit.gl.sketch",dest);
but i didnt know how to access it to draw an triangle. this doesnt work.
sketch.shape = ["tri",x….z];
and i didnt find anything to this at the help
http://cycling74.com/docs/max6/dynamic/c74_docs.html#jit.gl.sketch
and jit tutorial 40


Lee
Jun 07 2012 | 2:15 pm

try this (off my head)

sketch.glbegin( "triangles" );
sketch.glcolor( … );
sketch.glvertex( v1 );
sketch.glvertex( v2 );
sketch.glvertex( v3 );
sketch.glend();

Jun 07 2012 | 4:41 pm

yeah leehu, many thanks it is working now.

Jun 07 2012 | 5:23 pm

also, make sure you understand the difference between calling messages and setting attributes on Jitter objects in js.

"position" is an attribute of gl.sketch, so you set it like this:
sketch.position = [0, 0, 0];

"gltranslate" is a message to gl.sketch, which means it’s an object method in js, and called like this:
sketch.gltranslate(0, 1, 0);

Jun 08 2012 | 9:40 am

thanks for this explanation.

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

Forums > Javascript