Forums > Jitter

Rotating a polygon created with jit.gl.sketch around it's own axis

January 24, 2007 | 9:25 pm

hi
I have been desperately trying to get a polygon created with the jit.gl.sketch cmdlist to rotate around it’s own axis, and not the axis of the screen. So far, I didn’t make it. Tried fooling around with the glmatrixmode, didn’t really help, quite possibly I’m missing something fundemental.

The difference can be noticed if the polygon is translated off the center of the frame- it then still rotates around the center of the screen instead of around itself.
Is "self centered" rotation possible? If so I would love to know how… A small example patch follows. To see where I’m going with this, look at my previous (and sadly unanswered..) question in the forum about creating and controlling a "shatter-like effect" with jitter.

Here’s the patch, Thanks,
-Nadav

max v2;
#N vpatcher 428 100 1157 711;
#P origin 0 92;
#P window setfont "Sans Serif" 9.;
#P window linecount 3;
#P comment 462 313 167 196617 Steps to duplicate the problem: 1. translate the Y 2. rotate around the X or the Z axis;
#B color 14;
#P window linecount 1;
#P comment 332 197 20 196617 Z;
#P comment 285 197 20 196617 Y;
#P comment 238 197 20 196617 X;
#P comment 237 181 54 196617 Translate:;
#P comment 500 234 54 196617 Rotate Z;
#P comment 484 189 54 196617 Rotate Y;
#P flonum 462 233 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
#P newex 462 254 201 196617 sprintf cmd_replace 5 glrotate %f 0. 0. 1.;
#B color 5;
#P flonum 445 190 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 445 211 201 196617 sprintf cmd_replace 4 glrotate %f 0. 1. 0.;
#B color 5;
#P newex 155 43 31 196617 t b 1;
#P newex 155 23 48 196617 loadbang;
#P button 196 236 15 0;
#P flonum 433 145 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
#P newex 433 166 201 196617 sprintf cmd_replace 3 glrotate %f 1. 0. 0.;
#B color 5;
#P flonum 333 211 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 285 211 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
#P flonum 238 211 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 267 309 32 196617 print;
#P message 216 260 57 196617 getcmdlist;
#P newex 215 236 210 196617 sprintf cmd_replace 6 gltranslate %f %f %f;
#B color 5;
#P newex 187 285 90 196617 jit.gl.sketch domo;
#P newex 14 498 156 196617 jit.window domo @depthbuffer 1;
#P newex 14 120 43 196617 jit.qball;
#P number 59 71 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 14 71 15 0;
#P newex 14 97 55 196617 metro 20;
#P newex 14 151 58 196617 t b b erase;
#P newex 14 475 91 196617 jit.gl.render domo;
#P window linecount 3;
#P message 187 77 380 196617 reset , glmatrixmode modelview , glpushmatrix , glscale 1. 1. 1. , glrotate 0. 1. 0. 0. , glrotate 0. 0. 1. 0. , glrotate 0. 0. 0. 1. , gltranslate 0. 0. 0. , glbegin polygon , glvertex -0.5 -0.5 0. , glvertex 0. 0.5 0. , glvertex 0.5 0.3 0. , glend , glpopmatrix;
#B color 1;
#P window linecount 1;
#P comment 474 148 54 196617 Rotate X;
#P window linecount 6;
#P comment 338 313 100 196617 The problem: I want to rotate the polygon around it’s own center , not around the center of the screen.;
#B color 14;
#P connect 21 1 6 0;
#P connect 6 0 5 0;
#P connect 5 0 8 0;
#P connect 8 0 4 0;
#P connect 4 0 3 0;
#P connect 4 2 3 0;
#P connect 7 0 5 1;
#P connect 20 0 21 0;
#P connect 21 0 2 0;
#P fasten 24 0 10 0 467 278 192 278;
#P fasten 22 0 10 0 450 281 192 281;
#P connect 11 0 10 0;
#P connect 2 0 10 0;
#P connect 12 0 10 0;
#P fasten 17 0 10 0 438 280 192 280;
#P fasten 15 0 19 0 290 228 201 228;
#P connect 16 0 19 0;
#P connect 14 0 11 0;
#P connect 19 0 11 0;
#P connect 10 1 13 0;
#P connect 15 0 11 1;
#P connect 16 0 11 2;
#P connect 18 0 17 0;
#P connect 23 0 22 0;
#P connect 25 0 24 0;
#P pop;


January 24, 2007 | 9:38 pm

You have to set make a jit.matrix with the rotation matrix set, and
then within jit.gl.sketch use the glloadmatrix

check out the pelado patches, they are excellent in showing this.

:)

On Jan 24, 2007, at 4:25 PM, Nadav Assor wrote:

>
> hi
> I have been desperately trying to get a polygon created with the
> jit.gl.sketch cmdlist to rotate around it’s own axis, and not the
> axis of the screen. So far, I didn’t make it. Tried fooling around
> with the glmatrixmode, didn’t really help, quite possibly I’m
> missing something fundemental.
>
> The difference can be noticed if the polygon is translated off the
> center of the frame- it then still rotates around the center of the
> screen instead of around itself.
> Is "self centered" rotation possible? If so I would love to know
> how… A small example patch follows. To see where I’m going with
> this, look at my previous (and sadly unanswered..) question in the
> forum about creating and controlling a "shatter-like effect" with
> jitter.
>
> Here’s the patch, Thanks,
> -Nadav
>
> max v2;
> #N vpatcher 428 100 1157 711;
> #P origin 0 92;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 3;
> #P comment 462 313 167 196617 Steps to duplicate the problem: 1.
> translate the Y 2. rotate around the X or the Z axis;
> #B color 14;
> #P window linecount 1;
> #P comment 332 197 20 196617 Z;
> #P comment 285 197 20 196617 Y;
> #P comment 238 197 20 196617 X;
> #P comment 237 181 54 196617 Translate:;
> #P comment 500 234 54 196617 Rotate Z;
> #P comment 484 189 54 196617 Rotate Y;
> #P flonum 462 233 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
> #P newex 462 254 201 196617 sprintf cmd_replace 5 glrotate %f 0. 0.
> 1.;
> #B color 5;
> #P flonum 445 190 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 445 211 201 196617 sprintf cmd_replace 4 glrotate %f 0. 1.
> 0.;
> #B color 5;
> #P newex 155 43 31 196617 t b 1;
> #P newex 155 23 48 196617 loadbang;
> #P button 196 236 15 0;
> #P flonum 433 145 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
> #P newex 433 166 201 196617 sprintf cmd_replace 3 glrotate %f 1. 0.
> 0.;
> #B color 5;
> #P flonum 333 211 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 285 211 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
> #P flonum 238 211 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 267 309 32 196617 print;
> #P message 216 260 57 196617 getcmdlist;
> #P newex 215 236 210 196617 sprintf cmd_replace 6 gltranslate %f %f
> %f;
> #B color 5;
> #P newex 187 285 90 196617 jit.gl.sketch domo;
> #P newex 14 498 156 196617 jit.window domo @depthbuffer 1;
> #P newex 14 120 43 196617 jit.qball;
> #P number 59 71 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P toggle 14 71 15 0;
> #P newex 14 97 55 196617 metro 20;
> #P newex 14 151 58 196617 t b b erase;
> #P newex 14 475 91 196617 jit.gl.render domo;
> #P window linecount 3;
> #P message 187 77 380 196617 reset , glmatrixmode modelview ,
> glpushmatrix , glscale 1. 1. 1. , glrotate 0. 1. 0. 0. ,
> glrotate 0. 0. 1. 0. , glrotate 0. 0. 0. 1. , gltranslate 0. 0.
> 0. , glbegin polygon , glvertex -0.5 -0.5 0. , glvertex 0. 0.5
> 0. , glvertex 0.5 0.3 0. , glend , glpopmatrix;
> #B color 1;
> #P window linecount 1;
> #P comment 474 148 54 196617 Rotate X;
> #P window linecount 6;
> #P comment 338 313 100 196617 The problem: I want to rotate the
> polygon around it’s own center , not around the center of the
> screen.;
> #B color 14;
> #P connect 21 1 6 0;
> #P connect 6 0 5 0;
> #P connect 5 0 8 0;
> #P connect 8 0 4 0;
> #P connect 4 0 3 0;
> #P connect 4 2 3 0;
> #P connect 7 0 5 1;
> #P connect 20 0 21 0;
> #P connect 21 0 2 0;
> #P fasten 24 0 10 0 467 278 192 278;
> #P fasten 22 0 10 0 450 281 192 281;
> #P connect 11 0 10 0;
> #P connect 2 0 10 0;
> #P connect 12 0 10 0;
> #P fasten 17 0 10 0 438 280 192 280;
> #P fasten 15 0 19 0 290 228 201 228;
> #P connect 16 0 19 0;
> #P connect 14 0 11 0;
> #P connect 19 0 11 0;
> #P connect 10 1 13 0;
> #P connect 15 0 11 1;
> #P connect 16 0 11 2;
> #P connect 18 0 17 0;
> #P connect 23 0 22 0;
> #P connect 25 0 24 0;
> #P pop;
>
>

v a d e //

http://www.vade.info
abstrakt.vade.info


January 24, 2007 | 11:00 pm

If you draw the polygon around it’s own axis (i.e. in model
coordinates), this is easy.

example:

//gltranslate to the center of the polygon and then glrotate and
finally draw a shape

glpushmatrix, gltranslate 0.5, 0.2, 0., glrotate 90 0 1 0, cylinder
0.4 glpopmatrix

wes

On 1/24/07, vade wrote:
> You have to set make a jit.matrix with the rotation matrix set, and then
> within jit.gl.sketch use the glloadmatrix
>
> check out the pelado patches, they are excellent in showing this.
>
> :)
>
>
> On Jan 24, 2007, at 4:25 PM, Nadav Assor wrote:
>
>
> hi
> I have been desperately trying to get a polygon created with the
> jit.gl.sketch cmdlist to rotate around it’s own axis, and not the axis of
> the screen. So far, I didn’t make it. Tried fooling around with the
> glmatrixmode, didn’t really help, quite possibly I’m missing something
> fundemental.
>
> The difference can be noticed if the polygon is translated off the center of
> the frame- it then still rotates around the center of the screen instead of
> around itself.
> Is "self centered" rotation possible? If so I would love to know how… A
> small example patch follows. To see where I’m going with this, look at my
> previous (and sadly unanswered..) question in the forum about creating and
> controlling a "shatter-like effect" with jitter.
>
> Here’s the patch, Thanks,
> -Nadav
>
> max v2;
> #N vpatcher 428 100 1157 711;
> #P origin 0 92;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 3;
> #P comment 462 313 167 196617 Steps to duplicate the problem: 1. translate
> the Y 2. rotate around the X or the Z axis;
> #B color 14;
> #P window linecount 1;
> #P comment 332 197 20 196617 Z;
> #P comment 285 197 20 196617 Y;
> #P comment 238 197 20 196617 X;
> #P comment 237 181 54 196617 Translate:;
> #P comment 500 234 54 196617 Rotate Z;
> #P comment 484 189 54 196617 Rotate Y;
> #P flonum 462 233 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
> #P newex 462 254 201 196617 sprintf cmd_replace 5 glrotate %f 0. 0. 1.;
> #B color 5;
> #P flonum 445 190 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 445 211 201 196617 sprintf cmd_replace 4 glrotate %f 0. 1. 0.;
> #B color 5;
> #P newex 155 43 31 196617 t b 1;
> #P newex 155 23 48 196617 loadbang;
> #P button 196 236 15 0;
> #P flonum 433 145 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
> #P newex 433 166 201 196617 sprintf cmd_replace 3 glrotate %f 1. 0. 0.;
> #B color 5;
> #P flonum 333 211 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 285 211 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
> #P flonum 238 211 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 267 309 32 196617 print;
> #P message 216 260 57 196617 getcmdlist;
> #P newex 215 236 210 196617 sprintf cmd_replace 6 gltranslate %f %f %f;
> #B color 5;
> #P newex 187 285 90 196617 jit.gl.sketch domo;
> #P newex 14 498 156 196617 jit.window domo @depthbuffer 1;
> #P newex 14 120 43 196617 jit.qball;
> #P number 59 71 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P toggle 14 71 15 0;
> #P newex 14 97 55 196617 metro 20;
> #P newex 14 151 58 196617 t b b erase;
> #P newex 14 475 91 196617 jit.gl.render domo;
> #P window linecount 3;
> #P message 187 77 380 196617 reset , glmatrixmode modelview , glpushmatrix
> , glscale 1. 1. 1. , glrotate 0. 1. 0. 0. , glrotate 0. 0. 1. 0. ,
> glrotate 0. 0. 0. 1. , gltranslate 0. 0. 0. , glbegin polygon , glvertex
> -0.5 -0.5 0. , glvertex 0. 0.5 0. , glvertex 0.5 0.3 0. , glend ,
> glpopmatrix;
> #B color 1;
> #P window linecount 1;
> #P comment 474 148 54 196617 Rotate X;
> #P window linecount 6;
> #P comment 338 313 100 196617 The problem: I want to rotate the polygon
> around it’s own center , not around the center of the screen.;
> #B color 14;
> #P connect 21 1 6 0;
> #P connect 6 0 5 0;
> #P connect 5 0 8 0;
> #P connect 8 0 4 0;
> #P connect 4 0 3 0;
> #P connect 4 2 3 0;
> #P connect 7 0 5 1;
> #P connect 20 0 21 0;
> #P connect 21 0 2 0;
> #P fasten 24 0 10 0 467 278 192 278;
> #P fasten 22 0 10 0 450 281 192 281;
> #P connect 11 0 10 0;
> #P connect 2 0 10 0;
> #P connect 12 0 10 0;
> #P fasten 17 0 10 0 438 280 192 280;
> #P fasten 15 0 19 0 290 228 201 228;
> #P connect 16 0 19 0;
> #P connect 14 0 11 0;
> #P connect 19 0 11 0;
> #P connect 10 1 13 0;
> #P connect 15 0 11 1;
> #P connect 16 0 11 2;
> #P connect 18 0 17 0;
> #P connect 23 0 22 0;
> #P connect 25 0 24 0;
> #P pop;
>
>
>
> v a d e //
>
> http://www.vade.info
> abstrakt.vade.info
>
>
>
>
>
>
>


January 25, 2007 | 4:57 pm

Thanks Vade and Wesley, after following your good advice I can see a way to make this work fine. will post if anything interesting comes out of this…
-Nadav


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