javascript gl.sketch start

Jun 7, 2012 at 9:09am

javascript gl.sketch start

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

Jun 7, 2012 at 11:17am

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

obj = new JitterObject( “”, 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 7, 2012 at 1:51pm

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(“”,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
and jit tutorial 40

Jun 7, 2012 at 2:15pm

try this (off my head)

sketch.glbegin( “triangles” );
sketch.glcolor( … );
sketch.glvertex( v1 );
sketch.glvertex( v2 );
sketch.glvertex( v3 );

Jun 7, 2012 at 4:41pm

yeah leehu, many thanks it is working now.

Jun 7, 2012 at 5:23pm

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 8, 2012 at 9:40am

thanks for this explanation.


You must be logged in to reply to this topic.