Forums > Jitter

gl 3d rotation of parent child shapes

March 19, 2006 | 12:42 pm

hope someone with trig or linear algebra knowledge can clarify this for me
seems like for years Ive stumbled on deriving the xyz cordinates of a
cylinder’s tip so I can bind it seemlessly to other shapes as arms or
tendrils. this patch shows my appraoch to the problem and can be aded to a
gl.sketch environment, it uses jasch’s rotatexyz to attempt to bind a sphere
to a cylinders end, I just cant get it to bind when xy and z are actively
rotating, I use a half black half white texture to make the cylinder half
invisible for simplicity, the shape orient command is scaled and moded into
pi phases
it seems like the shape orient and the xyzrotate just arn’t in the same
coordinate system, and that there is some constant attenuation that needs to
be made to get them to agree,
siggraph site has these equations but I dont know how to translate math
matri in my head anymore let alone into max, can someone drop me a patch or
mod mine so I can jump this hurdle get back into the art of things

Z-axis rotation is identical to the 2D case:
x’ = x*cos q – y*sin q
y’ = x*sin q + y*cos q
z’ = z

( cos q sin q 0 0)
Rz (q) = (-sin q cos q 0 0)
( 0 0 1 0)
( 0 0 0 1)

X-axis rotation looks like Z-axis rotation if replace:
X axis with Y axis
Y axis with Z axis
Z axis with X axis
So we do the same replacement in the equations:
y’ = y*cos q – z*sin q
z’ = y*sin q + z*cos q
x’ = x

(1 0 0 0)
Rx(q) = (0 cos q sin q 0)
(0 -sin q cos q 0)
(0 0 0 1)

Y-axis rotation looks like Z-axis rotation if replace:
X axis with Z axis
Y axis with X axis
Zaxis with Y axis
So we do the same replacement in equations :
z’ = z*cos q – x*sin q
x’ = z*sin q + x*cos q
y’ = y

(cos q 0 -sin q 0)
Ry(q) = (0 1 0 0)
(sin q 0 cos q 0)
(0 0 0 1)

max v2;
#N vpatcher 54 274 757 708;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#N vpatcher 30 89 375 535;
#P origin 17 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 102 97 14 196617 0;
#P newex 112 171 33 196617 lbang;
#P newex 91 384 47 196617 s sketch;
#P newex 91 333 144 196617 prepend texture movie;
#P message 137 83 74 196617 texture movie;
#P number 105 122 35 9 0 3 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 105 142 62 196617 tex_map $1;
#P user jit.pwindow 126 261 82 62 0 1 0 0 1 0;
#P button 100 214 15 0;
#P message 142 218 147 196617 setcell 0 1 val 0 255 255 255;
#P message 136 197 111 196617 setcell 0 0 val 0 1 1 1;
#P newex 117 244 105 196617 jit.matrix 4 char 1 2;
#P newex 181 126 48 196617 s render;
#P connect 1 0 9 0;
#P connect 9 0 10 0;
#P connect 11 0 4 0;
#P connect 11 0 12 0;
#P connect 12 0 7 0;
#P connect 7 0 6 0;
#P connect 4 0 1 0;
#P connect 3 0 1 0;
#P connect 2 0 1 0;
#P connect 1 0 5 0;
#P connect 11 0 2 0;
#P connect 11 0 8 0;
#P connect 11 0 3 0;
#P connect 8 0 0 0;
#P connect 6 0 0 0;
#P pop 1;
#P newobj 51 305 52 196617 p texture;
#P message 7 32 233 196617 running this list to a constantly dumping
gl.sketch;
#P flonum 402 78 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 354 34 169 196617 ading z rotaiton to x y ruins phases;
#P message 240 33 115 196617 x y rotation works fine;
#P message 155 55 79 196617 cylender length;
#P newex 422 147 37 196617 abs 0.;
#P newex 429 123 39 196617 – 360.;
#P newex 290 343 58 196617 + 0.799375;
#P newex 548 60 40 196617 + 180.;
#P newex 542 88 40 196617 % 360;
#P newex 548 148 116 196617 scale 0 360 3.14 -3.14;
#P newex 281 149 34 196617 * -1.;
#P newex 456 80 40 196617 + 180.;
#P newex 325 175 34 196617 + 90.;
#P newex 546 128 37 196617 abs 0.;
#P newex 627 37 40 196617 % 360;
#P newex 548 109 39 196617 – 360.;
#P newex 324 322 76 196617 unpack 0. 0. 0.;
#P message 259 387 217 196617 5 moveto 0.17649 1.793164 1.542559;
#P newex 244 386 14 196617 _;
#P message 479 295 217 196617 -0.622885 0.543164 1.542559;
#P comment 554 282 16 196617 z;
#B frgb 116 116 116;
#P comment 538 282 16 196617 y;
#B frgb 116 116 116;
#P flonum 536 223 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 500 223 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 464 223 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 466 241 61 196617 pak 0. 0. 0.;
#P newex 464 294 14 196617 _;
#P newex 464 269 55 196617 3Dpoltocar;
#P comment 523 282 16 196617 x;
#B frgb 116 116 116;
#P newex 270 203 137 196617 pak 7 shapeorient 180. 0. 0.;
#P newex 352 344 40 196617 + 1.25;
#P newex 487 104 40 196617 % 360;
#P newex 493 176 116 196617 scale 0 360 3.14 -3.14;
#P flonum 167 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 59 110 192 196617 pak 4 cylinder -0.16 -0.16 1. 360. 0. 0.;
#P newex 246 363 148 196617 pak 5 moveto 0.79375 1.25 1.;
#P flonum 308 64 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 354 63 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 255 101 137 196617 pak 3 shapeorient 180. 0. 0.;
#N coll temple;
#T flags 1 0;
#T 0 reset 0;
#T 1 moveto 0.79375 1.25 0.;
#T 2 glcolor 1. 1. 1. 1.;
#T 3 shapeorient 1242. 338. 442.;
#T 4 cylinder -0.16 -0.16 1.75 360. 0. 0.;
#T 5 moveto 0.17649 1.793164 1.542559;
#T 6 sphere 0.16 0. 360. 0. 180. 0.;
#T 7 shapeorient 1332. 0. 0.;
#P newobj 83 223 59 196617 coll temple;
#P connect 4 0 0 0;
#P connect 10 0 0 0;
#P connect 5 0 0 0;
#P connect 1 0 0 0;
#P connect 6 0 5 4;
#P connect 4 0 21 0;
#P hidden fasten 21 0 22 0 249 404 264 404;
#P connect 6 0 29 0;
#P connect 23 0 33 0;
#P connect 33 0 4 2;
#P connect 3 0 1 2;
#P connect 12 0 23 0;
#P connect 3 0 27 0;
#P connect 27 0 10 2;
#P connect 2 0 1 3;
#P connect 9 0 4 3;
#P connect 23 1 9 0;
#P connect 39 0 1 4;
#P connect 23 2 4 4;
#P connect 34 0 35 0;
#P connect 3 0 28 0;
#P connect 30 0 15 0;
#P connect 14 0 12 0;
#P connect 12 0 13 0;
#P connect 15 0 14 0;
#P lcolor 1;
#P hidden fasten 13 0 20 0 469 312 484 312;
#P connect 28 0 8 0;
#P connect 16 0 14 1;
#P lcolor 1;
#P connect 8 0 7 0;
#P connect 35 0 7 0;
#P connect 7 0 16 0;
#P connect 17 0 14 2;
#P lcolor 1;
#P connect 29 0 17 0;
#P connect 32 0 31 0;
#P connect 24 0 26 0;
#P connect 2 0 32 0;
#P fasten 31 0 24 0 548 105;
#P connect 26 0 30 0;
#P pop;


March 19, 2006 | 11:46 pm

Hi Derek,

The easy way to handle this is use the transform matrix rather than
calculating the 4×5 modelview matrix by hand. Please see the OpenGL
Redbook (html/pdf of v1.1 available at http://www.opengl.org), or the
various online tutorials on OpenGL modelview matrix manipulation for
more information. You can then avoid having to calculate the 4×4
modelview matrix values explicitly. The important sketch commands you
will want to familiarize yourself with are:

glmatrixmode
glpushmatrix
glpopmatrix
gltranslate
glscale
glrotate

Hope this points you in the right direction.

-Joshua


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