Hello Guest

# [SOLVED] JAVA AffineTransform and OPENGL

• 5 Replies
• 4747 Views

#### mrgibson

• 11
##### [SOLVED] JAVA AffineTransform and OPENGL
« on: June 23, 2013, 05:43:46 »
I do some translation and zooming in a JAVA affine transform, what is the best way to use it in OPENGL (with LWJGL) ?

Thank you,
mrgibson

« Last Edit: June 29, 2013, 04:29:54 by mrgibson »

#### quew8

• 569
• Because Square Eyes Look More Real
##### Re: JAVA AffineTransform and OPENGL
« Reply #1 on: June 23, 2013, 09:12:32 »
You would have to extract the matrix from the affine transform and set it to your OpenGL shader. Unfortunately, as far as I know, you cannot get the matrix from the affine transform so...

Fortunately for you, translation and scaling matrices are very simple.
Translation : 1 0 0 tx Where the translation vector is (tx, ty, tz)
0 1 0 ty
0 0 1 tz
0 0 0 1

Scaling : sx  0   0   0 Where sx, sy, sz are the respective x, y and z scaling coefficients.
0   sy  0   0
0   0    sz  0
0   0    0    1

However a sound knowledge of transformation matrices is essential for advanced OpenGL so I would advice a bit of research. I found http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/ to be an excellent starter.

#### mrgibson

• 11
##### Re: JAVA AffineTransform and OPENGL
« Reply #2 on: June 25, 2013, 20:46:41 »

I think I could extract the matrix using Affinetransform.getMatrix() function.

I guess I could send it to my shader then.

#### quew8

• 569
• Because Square Eyes Look More Real
##### Re: JAVA AffineTransform and OPENGL
« Reply #3 on: June 26, 2013, 17:40:00 »
Sure you could. I must have missed that function (I did look through the javadoc). One thing to be careful of - make sure you get the column major / row major order the right way round.

#### mrgibson

• 11
##### Re: JAVA AffineTransform and OPENGL
« Reply #4 on: June 29, 2013, 04:24:06 »
This is working nicely, I ported all my code from Graphics2D to OpenGL.
I also discovered glScissor(), really simple to use for clipping regions.

Here a small video of the result: