## 3D coordinate transformations

Jan 27, 2006 at 8:11pm

# 3D coordinate transformations

I want to align an object to the local coordinate system of another object,
so that If I rotate or move object1, object2 moves along and keeps it’s
relative position to object1. I read through chapter 3 of the redbook and
searched around on the internet before trying to get it right in max. After
a long time of patching with just “expr” objects and a lot of trial and
error I got halfway and then I lost track. It seems I really can’t figure it
out on my own and it’s driving me nuts. From what I understand now, I need
to combine their 4×4 matixes, somehow. (?)

In the first place I want to use this to align objects to the view space
coordinates, like you’re driving a car and the outside world is moving but
the steering wheel stays in front of you. It seems a pretty common thing in
3d applications, so I’m hoping someone can explain how to do this in jitter.
My patch uses several ogl externals, so I can’t do everything within one
gl.sketch

I think I need to know:
- how to translate the camera/lookat messages to a 4x4matrix
- how to apply that matrix to the rotate/position parameters of another ogl
object.

I’d really appreciate any help on this.

Thijs

#24130
Jan 28, 2006 at 6:15pm

This is something GEM (on PureData and Max) handles really nicely.
they have separate rotateXYZ and transformXYZ objects you can link
serially in a render chain, which lets you do fairly complex
movements really easily. This is however due to the way GEM render-
chains work (afaict).

does anyone from c74 know if this could be implemented in jitter
(without having to deal with transformation matrices implicitly ?)

if it wouldnt be too hard to have a jit.gl.rotate and a
jit.gl.translate that could be attached to chained objects somehow,
it could make easier to play with potentially. However im guessing
that since most ways of working with a jit.gl context is without
patch cords (automatic 1), making a ‘serial’ implementation would be
difficult.

thoughts?

am I way off base?

v a d e //

#69330
Jan 28, 2006 at 7:36pm

Thanks for the replies. I can’t use GEM because I’m on windows. And Wesley,
I already knew your patch, but when I first looked at it, I didn’t really
understand what it was for. I remembered it and checked it out a second
time…and still I didn’t see how it was related to what I wanted to do.
Maybe I should check it again and look even closer this time;-)

I’ll give it another try soon, but I guess it would be really nice to have
some jitter objects dealing with these things like vade mentioned.

Best, Thijs

#69331
Jan 29, 2006 at 9:54pm

Thanks a lot Wesley. To bad I still don’t get it. I spend a few hours going
through you linetrans and jelly code and trying to patch it. I thought I was
don’t get yet. I tried to use code from linetrans to lock an objects
position to the camera like this: point1 camera position, point2 lookat
position and then use the calculated pointp to set the objects position.

For its rotation I used point1′s x+y as inputs to the jelly orient function.
Unless I’m missing something obvious and you can explain it in a few words,
I guess I’ll give up for now, and maybe try again when I’m smarter or have
more time.

Best, T_

#69333
Jan 31, 2006 at 12:08pm

That’s exactly the code I used from the jellyfish. I’ll make an example
patch soon showing what I’m trying to achieve exactly, but I don’t have any
time for this untill the end of this week. Thanks for all the help.

Best, Thijs

#69335
Jan 31, 2006 at 9:47pm

On Jan 27, 2006, at 12:11 PM, Thijs Koerselman wrote:

> I want to align an object to the local coordinate system of another
> object, so that If I rotate or move object1, object2 moves along
> and keeps it’s relative position to object1. I read through chapter
> 3 of the redbook and searched around on the internet before trying
> to get it right in max. After a long time of patching with just
> “expr” objects and a lot of trial and error I got halfway and then
> I lost track. It seems I really can’t figure it out on my own and
> it’s driving me nuts. From what I understand now, I need to combine
> their 4×4 matixes, somehow. (?)

I would recommend using jit.gl.sketch in conjunction with the
drawobject message. You can perform any type of
hierarchical transformation this way, including those exposed by the
procedural rendering model of GEM (which essentially uses object
boxes in sequence for the drawing commands of jit.gl.sketch. Anyone
that is looking for the GEM model in Jitter, should take a look at
jit.gl.sketch’s drawing commands).

For example, something like the following:

glmatrixmode modelview,
glpushmatrix,
gltranslate ,
glrotate 1. 0. 0.,
glrotate 0. 1. 0.,
glrotate 0. 0. 1.,
drawobject ,
glmatrixmode modelview,
glpushmatrix,
gltranslate ,
glrotate 1. 0. 0.,
glrotate 0. 1. 0.,
glrotate 0. 0. 1.,
drawobject ,
glmatrixmode modelview,
glpopmatrix,
glpopmatrix

Subpatchers or JS functions could be used to simplify building up
these command lists.

Of course you can do all the matrix math yourself if you want, but I
think the above strategy is a little bit easier.

-Joshua

#69336
Feb 1, 2006 at 12:42am

sketch, this makes things much easier, I will have to play with it.

Thanks for the reminder, this is exactly what I was looking for
myself (GEM style procedural, etc).

v a d e //

#69337
Jun 23, 2007 at 6:54pm

Hi all,

is this really that hard to do?:
I want to rotate a jit.gl.model around different origins.
Obviously there’s no easy way to move the origin, right?
more precisely described the model should rotate slowly all the time but depending on user interaction another spot of it should be in the middle of the scene.
The next problem I will have is that the final model will consist of multiple models (with different shaders) which I will have to group together somehow. I have no idea how to do this. If there was the possibility to move the origin it would be very simple.

thanks
secco

#69338
Jun 24, 2007 at 10:08pm

It sounds like you need to get your hands dirty on a bit of low level
opengl. When I posted the first message to this thread I didn’t know much
about it either, but since then I’ve been doing a lot of things like that,
but if you know how to use it you can basically do anything you want,
changing origins and all you mention. It took me a while to get my head
around it, the matrix math and all, but its really worth learning. Look into
the opengl redbook and numerous tutorials online about transformations.

If you use drawraw() on jitter gl objects instead of the regular draw()/bang
they get drawn without their transformation and material related attributes
(just a plain gray shape at the origin). They can inherit all those things
from the lowlevel gl calls that you do around those drawraw() calls. You can
even bind and unbind shaders to change them between different objects you’re
drawing. You’ll need to use the glPushMatrix, glPopMatrix, glTranslate and

There are two options for doing low level gl in Jitter (without writing your
own externals) which are jit.gl.sketch (+javascript) and jit.gl.lua.
Personally I much prefer the latter one. One reason is because it can do
direct opengl calls similar to the original opengl api. In your scripts
you’ll have complete control over how you draw and group things together.

To answer to your first question: Its not hard to do once you’ve
familiarized yourself with that bit of opengl, but it will take some time
and effort to get comfortable with it. What you get back is ultimate control
and more efficient drawing routines. Hope this helps.

Cheers,
Thijs

http://www.nano-soundworks.com

On 6/23/07, secco wrote:
>
>
> Hi all,
>
> is this really that hard to do?:
> I want to rotate a jit.gl.model around different origins.
> Obviously there’s no easy way to move the origin, right?
> more precisely described the model should rotate slowly all the time but
> depending on user interaction another spot of it should be in the middle of
> the scene.
> The next problem I will have is that the final model will consist of
> multiple models (with different shaders) which I will have to group together
> somehow. I have no idea how to do this. If there was the possibility to move
> the origin it would be very simple.
>
> thanks
> secco
>

#69339
Jun 25, 2007 at 10:13am

Thanks a lot Thijs,

I’ll try that out.
Is it somehow possible to step out of the processing of the sketch commands to change some parameters?

I want to achieve this:
reset,
glscale 1 1 1,
glrotate \$3 0 1 0,
gltranslate \$1 0 \$2,
drawobject myfirstobject 1,
gltranslate \$4 0 \$4,
glrotate \$5 0 1 0,
glscale \$6 \$6 \$6,
drawobject my3dtext 1,
glrotate \$7 0 1 0,
gltranslate \$8 0 \$8,
gltranslate \$9 0 \$9,
glrotate \$5 0 1 0,
drawobject my3dtext_but_changed 1

I want to draw different texts but with the same object because there will be a lot of textobjects in the scene and I don’t want to use a new jit.gl.text3d object for each text. so I have to step out somehow and change the text.
I can’t start a new sketch because the whole bunch is turning in a certain way.
Probably the way I’m doing it is not the best but it all works fine for me now except of this problem with multiple texts.

Thanks
secco

#69340
Jun 25, 2007 at 11:46am

On 6/25/07, secco wrote:
>
>
> I want to achieve this:
> reset,
> glscale 1 1 1,
> glrotate \$3 0 1 0,
> gltranslate \$1 0 \$2,
> drawobject myfirstobject 1,
> gltranslate \$4 0 \$4,
> glrotate \$5 0 1 0,
> glscale \$6 \$6 \$6,
> drawobject my3dtext 1,
> glrotate \$7 0 1 0,
> gltranslate \$8 0 \$8,
> gltranslate \$9 0 \$9,
> glrotate \$5 0 1 0,
> drawobject my3dtext_but_changed 1
> …
>
> I want to draw different texts but with the same object because there will
> be a lot of textobjects in the scene and I don’t want to use a new
> jit.gl.text3d object for each text. so I have to step out somehow and
> change the text.
> I can’t start a new sketch because the whole bunch is turning in a certain
> way.
> Probably the way I’m doing it is not the best but it all works fine for me
> now except of this problem with multiple texts.

Hi secco,

No need to use multiple text objects and certainly no need to start a new
sketch. Use JavaScript or Lua like I suggested (it’ll be easier than sending
messages from max) , and you have full control over your objects, also in
between drawing commands. Below is a piece of pseudo JS code. I’m probably
wrong on the exact function names, cause I haven’t used JS in a while…

myfirstobject = jit.new(“jit.gl.model”, mycontext)
my3dtext = jit.new(“jit.gl.text3d”, mycontext)
mysketch = jit.new(“jit.gl.sketch”, mycontext)

(don’t forget to set the objects to @automatic 0)

with(mysketch)
{
glscale(…)
glrotate(…)
gltranslate(…)
drawobject(myfirstobject, 1)
gltranslate(…)
glrotate(…)
glscale(…)
my3dtext.text(“some string”)
drawobject(my3dtext, 1)
glrotate(…)
gltranslate(…)
gltranslate(…)
glrotate(…)
my3dtext.text(“change the text”)
drawobject(my3dtext, 1)
}

Like I said you’ll have to figure the syntax out for yourself, but I hope
you get the idea.

cheers,
-thijs

#69341
Jun 25, 2007 at 1:39pm

Hi Thijs,

thanks again. I just tried to install lua and get an error when trying to load the demos:
any idea?

thanks
secco

#69342
Jun 25, 2007 at 2:22pm

On 6/25/07, secco wrote:
>
>
> Hi Thijs,
>
> thanks again. I just tried to install lua and get an error when trying to