A bit lost with axis and rotations

Have jReality programming problems or questions? Post them here.
Post Reply
tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

A bit lost with axis and rotations

Post by tiofredo » Fri 10. Jun 2011, 11:08

Hi guys.
I'm starting having results with jreality, but it's a long way.
For now, I can translate my objects (boxes in my storage facility), it's a big win.
Here's the thing :
being new to 3D, I'm wondering which is the "proper" way to use axis.
Say I have a surface representing the ground of my warehouse.
Should it be on X and Y, or X and Z ? Therefore should Z or Y or X??? be the altitude ?
Is there any page explaining all this, and how rotations work ?
Example :
I receive a message to create a forklift at (1,1,0)
Then another to move it to (3,5,0),
and this implies to rotate the forklift so it's along the (2,4,0) vector.
Any "proper" way to do so ?
That would be very helpful.
Thanks for the help guys!!

benjamin.kutschan
Posts: 48
Joined: Mon 16. May 2011, 16:29

Re: A bit lost with axis and rotations

Post by benjamin.kutschan » Sun 12. Jun 2011, 10:29

I think the coordinate system is usually aligned so that y points upwards and x, z are horizontal.

You could use the class MatrixBuilder i guess. A Translation would be

MatrixBuilder.euclidean().translate(new double[]{2, 4, 0, 1}).rotateFromTo(new double[]{1, 0, 0, 1}, new double[]{2, 4, 0, 1}).assignTo(sgc);

For details you can consult the tutorials at
http://www3.math.tu-berlin.de/jreality/ ... formations
and
http://www3.math.tu-berlin.de/jreality/ ... ilder.html

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: A bit lost with axis and rotations

Post by tiofredo » Tue 21. Jun 2011, 11:50

Hi.
Thanks for your answer.
Considering I basically work in 2D for rotations (always on the same plan), I ended up using a simple way:
I have the coordinates of my new position, and the vector between new and old position at each update of my position,
say coordinates(x, y, z) and vector(x, y, z=0)

Code: Select all

//angle of the vector
double angleZ = Math.atan2(vector.getY(), vector.getX());
//just to have an axis on z
double axis1[] =	{ coordinates.getX(), coordinates.getY(), 0 };
double axis2[] =	{ coordinates.getX(), coordinates.getY(), 1 };

MatrixBuilder.euclidean().rotate(axis1, axis2, angleZ).translate(coordinates.getX(), coordinates.getY(), coordinates.getZ()).assignTo(component);
Is that a proper way to do things ?

benjamin.kutschan
Posts: 48
Joined: Mon 16. May 2011, 16:29

Re: A bit lost with axis and rotations

Post by benjamin.kutschan » Wed 22. Jun 2011, 11:49

looks quit good I think.
i think the transformations that are at the end of the statement are executed first. ie. in your case first the translation and afterwards a rotation around the origin.
check this page for the use of .rotate(...)http://www3.math.tu-berlin.de/jreality/ ... ilder.html

If you want the forklift to move smoothly here's the tutorial:
http://www3.math.tu-berlin.de/jreality/ ... ation_tool

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: A bit lost with axis and rotations

Post by Andre » Wed 22. Jun 2011, 12:21

yeah, it looks good, you just have to choose what you want to do first:

rotation -> translation

translation -> rotation

don't mix this up, this has to be consistent through your whole code.

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: A bit lost with axis and rotations

Post by tiofredo » Wed 22. Jun 2011, 15:28

Thanks for your answers.
I just made some tests, it works fine with rotate().translate(), my box is moved, then rotates on itself, things are good.
I'm taking the next step now, moving the cameras.
The situation is a bit different, translations are on all 3 axes (and without the auto-orientation thing i did for boxes, so far so good), and rotations on itself are on 2 axes (up/down, left/right, but no tilt).
I'm gonna give a try at rotateFromTo and other sweets.
Hopefully my next post will be "I did it!"
Then another post about "how to have an ambient light ?"

About the animation tool, as in my component I only have notifications about the new position of my boxes which I can't predict, I'm not sure it fits the need.

I'm really starting to enjoy this project!
Thanks guys!

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: A bit lost with axis and rotations

Post by tiofredo » Thu 23. Jun 2011, 15:47

It went fine so far.
Now I'm wondering if I could change the coordinate system to meter unit (not quite sure I'm clear...), considering my .obj models and the incoming positions data is in meters,
and I'd like to use raw data.
Any possibility ?
edit :
I tried to rotate my camera on itself, but it seems it revolves around the origin, I think I've missed something...
I need to be able to do something like look up, down, left, right.
I receive angles on vertical and horizontal axis, I have to change my point of view angle, like a person would do.
Thanks.

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: A bit lost with axis and rotations

Post by Andre » Thu 23. Jun 2011, 18:25

As far as i understood, depends your problem on the size, scaled by jreality. You have to overwrite the global scalingfactor with 1, then you should have something like meters for your application. And don't use,

Code: Select all

		JRViewer v = new JRViewer();
                ...
		v.addContentSupport(ContentType.TerrainAligned);
                or
                v.addContentSupport(ContentType.CenteredAndScaled);
because this enables also a kind of scaling. (for the TerrainAligned I'm not sure, but the second for sure ;) )

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: A bit lost with axis and rotations

Post by Andre » Thu 23. Jun 2011, 18:46

Or better, watch into these classes and look how they are working or use simple

Code: Select all

		JRViewer v = new JRViewer();
		v.addContentSupport(ContentType.Raw);
"Raw" should just use the original sizes of your .obj-files

tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Re: A bit lost with axis and rotations

Post by tiofredo » Fri 24. Jun 2011, 10:19

Hi, thanks Andre for the answer.
As I'm using the jogl viewer, it seems I don't have these methods available...
Maybe I'm gonna have to multiply my positions by a common factor.
Example :
my test.obj file contains data in centimers for a ~600x250x250 box.
Data I'm receiving about the positioning is in meters, like (x, y, z) = (452.6, 229.3, 5.4)
and considering y and z should be inverted as z is the height in the system feeding data to me (which might be a problem with rotations anyway).
Maybe I should just multiply positions by 1000 and things will work fine ?

About the camera problem I'm facing, I'm lost, it's like axis are swapped and rotations are around the origins and not the camera itself.
But this might be totally normal and I'm just stupid ( very likely :) )

Thanks for the support, jreality is fun!

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: A bit lost with axis and rotations

Post by Andre » Tue 5. Jul 2011, 13:32

The jogl-viewer just describes the rendering backend you are using, what I mean is the kind of viewer you are using, because there are several versions of running viewers in jReality, eg. to point out an older viewer "ViewerApp" or a new viewer with VR-Support "JRViewerVR":

at the wiki you find some tutorials about viewers:
http://www3.math.tu-berlin.de/jreality/ ... r_Tutorial

especially this one should be interesting for you:
http://www3.math.tu-berlin.de/jreality/ ... ctionality

Have fun and keep on working. I try to answer to all Questions I'm able.

best
Andre

Post Reply