Author Topic: Object rotation vs. world axes  (Read 11709 times)

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Object rotation vs. world axes
« on: February 29, 2012, 05:24:57 pm »
Hi,

I have an airplane in the world which is moved/rotated along its axes. In one point I need to know its "world"  position. Angles beween the airplane axis (planes/surfaces) and the world represented by the terrain. Or better say - the absolute angles in the world. The question is related with the airplane flying model. My model is very simple - just rotates airplane around x (bank) and y (climb/desc.). The behaviour of the real airplane is the same so the azimut or direction is changed accordingly. But I would like to know the easiest way how to find the absolute angles (to be able to detect - should I land or crash :-)
(I'm talking about jpct-AE)
Thanx.

[attachment deleted by admin]
« Last Edit: February 29, 2012, 06:18:45 pm by Peter Dym »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #2 on: February 29, 2012, 09:40:32 pm »
Thank you very much Egon, but I'm too simple to get the reasonable results. Of course I'm reading the docu and calcAngle was the first try, but problem is to build/find/select  the right parameters. I'm always getting different angles like if all angles depend on others. I was starting with something like :

 SimpleVector vecx=airplane.getX(); // so I have one axis
 set vecx.z=0 ; // to have only a flat plane to measure  (?)
 vecx.calcAngle(SimpleVector(1,0,0);

But I have only confusing values. And if my airplane is upside-down, it is time for ejection - No angle is like expected.
The project is about radiotelephony communication for pilots (non commercial, just my hobby) but a nice 3d environment is actually why I'm doing that.
Because I did not have a solution, I was working on other features, som my peacefull biplane can shut down ballons now, can crash and can make smoke and explosions - which was not in the original "requirement". But is still not able to land, see the attachment  ;)  :



[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object rotation vs. world axes
« Reply #3 on: February 29, 2012, 11:03:21 pm »
Setting z to 0 isn't a good idea. Imagine that the plane has rotated 90° around Y. In that case, the x-axis in object space becomes the z-axis in world space. 0-ing that actually gives you a vector with length 0.

I would try to calculate the angle between getXAxis() and (0,-1,0); but that won't be sufficient. IIRC, the method will return angles between 0 and 90°, i.e. you also have to take into account if the x-axis is pointing up or down (i.e. if it has a negative or positive y component).

Quote
And if my airplane is upside-down, it is time for ejection
Detecting if the plane is upside down is simple...if the result of getYAxis() points down, the plane is flipped.

Apart from that, the screens look fine to me...they look exactly like me landing a plane...  ;)

Edit: Corrected up-vector...
« Last Edit: February 29, 2012, 11:18:45 pm by EgonOlsen »

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #4 on: March 01, 2012, 08:19:45 pm »
Thanks Egon. It's is hard to explain. 
Concerning "zeroing" the z axis: I supposed that I should do it for the airplane only and comparing it with world (1,0,0) which has also "z=0". If I do not set airplane.z=0 then I would calculate the "space" angle which is different than the "flat plane" angle which I'm interested in only. An angle between airplane.x and abstract vector (1,0,0). But you are right, of course, it is not such simple.

The upside down problem is clear, I used it only as an example how confusing is the whole stuff.

And to landing - actually I can use the normals taken from the runway to know how the airplane "should be" positioned. But I do not know if it is. This is the whole problem. If my explanation is too confusing, we can leave it. It is probably too much to me and I should rather programm a bublesorting of integers.
Otherwise I have another bunch of questions/problem which I would really like to ask. But they are so specific, that I do not know if it makes sense. May be the thread should be named - Android fly simulator, questions and answers for desperate (and lazy)  programmers.

And finally one practical question:
There is a warning message concerning the materials and colors are not rendered correctly. All problematic materials are rendered black (see the attachment) . The proposal says :
"WARNING: Error reading material's diffuse color...try Config.oldStyle3DSLoader=true!"
but in the AE there is no such option. Any suggestion?

Btw - thanx for jpct-AE. I love it.


[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object rotation vs. world axes
« Reply #5 on: March 02, 2012, 09:49:02 am »
If you know the ground's normal vector, isn't it sufficient to check the angle between the planes y-axis and that normal? If it's larger than maybe 45°, you are crash landing.

About that Config-setting...maybe this wasn't public in the last official release...i'm not sure about the reason, but if you download the latest jar mentioned in the "Version Updates!"-thread, it should be visible.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object rotation vs. world axes
« Reply #6 on: March 02, 2012, 10:17:09 am »
BTW: The screen shots look nice!

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #7 on: March 03, 2012, 12:21:49 am »
Thanx.  Actually - may be there is programmed one sexy feature. The terrain consists of 9 tiles. These tiles are modified by height bitmaps. So far so simple, nothing special. The central tile is different - with an airport in the middle. Other tiles are 100% symetrical. It means that their borders are the same = each corresponding point  is at the same altitude so they can be arbitrary combined without having known gaps, holes or emtpy spaces.  All tiles are sharing only one mesh.  They are always creating a compact land. Why? because my intention was to move tiles in dependency of the camera position. If the fog/visibility is set to approx. 2/3 of the tile width and the camera is looking to the given direction , the tiles behind (invisible) can be translated to the position which would create an endless terrain. The texture can be even changed so the tiles do not look similar. Finally the texture will be blended with some details so the feeling should be even more realistic. Unfortunatelly my invention was totally exhausted by the described feature and I'm not able to find the "formula" to detect when and which tile should be translated to the new position if it should be visible in the current "lookAt" direction (and is invisible in the back of camera).
As you see I'm solving a lot of problems and it probably needs some time. (some basic problems like animated textures, fonts for blitting, transparent explosions and smoke, terrain generator, some extra problems like 3d models and their wrong positioning, flying model, collision system (which I can succesfully use, but I do not understand it :-) , and some additional problems like sound (looping, the end detection, queing and correctly stopping...), android views and components, airspeak techniques and lessons...). But it looks promissing. I do not want to think about the Android market and own application there...But if anbody has an idea how to deal with my 9-tiled world, it would be appreciated.
To illustate what I'm talking about, please, see the attached simplified terrain picture (fog is disabled, tiles are shrinked and distances between tiles are added).

[attachment deleted by admin]
« Last Edit: March 03, 2012, 10:50:30 am by Peter Dym »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object rotation vs. world axes
« Reply #8 on: March 04, 2012, 08:42:42 pm »
That's not easy...well, actual it is, but a lot could go wrong on the way... ;) You have to calculate, which tiles are within your view frustum. The view frustum is basically given by the view direction and the field of view in x and y direction (in screen space). It might be possible to abuse the project3D2D-methods in Interact2D to do this. By projecting the center of a tile into screen space, you can determine if it will be visible or not by seeing if the center is on screen (plus some offset, because parts of the tile might be visible even if the center isn't).

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #9 on: March 06, 2012, 10:55:29 pm »
Just as an update: after some fighting I think that I have it. An endless world. I want to check if it is practically usable. But if I have something to show/share I will try to post a link to video which can be better than screenshots in this case. 

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #10 on: April 08, 2012, 05:48:15 pm »
My problem is now how to interpolate vector to "turn" it to the given direction:

- If I create a test object and
- if I calculate the direction vector to the target and
- the rotation matrix of the vector is then used for the the test object,

it works well - always pointing to my target.
But how to do do it incrementally? I do not know. This is the code:


...
// returns a vector from the source position to the target pos.
SimpleVector dir=Chaser.getDirection(sourceObj, targetObj);

// set the directon to point to the target
testObject.setRotationMatrix(dir.getRotationMatrix());

// and put the testObject to the source to see it
testObject.translate(sourceObj.getTranslation());
...


In the attached pictures is shown how my test object (the arrow) always points to the target (the baloon).
I would like my launched rocket to incrementally turn towards the target and hit it. Now I'm still missing something :-)


(http://www.youtube.com/watch?v=DrPFrDcffc4)



[attachment deleted by admin]
« Last Edit: April 08, 2012, 05:53:46 pm by Peter Dym »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object rotation vs. world axes
« Reply #11 on: April 08, 2012, 09:19:47 pm »
You could try:


You might have to play around with the interpolation's values and it won't look good when both matrices are very different, but it might be worth a try.

Edit: Video looks cool btw.

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #12 on: April 09, 2012, 12:58:46 pm »
I haven't noticed the interpolate method. Sorry. It works great ! It works better than great :- ! Thank you. I will post a video if  I find a better way to grab it than to hold my camera in one hand and the phone in the second hand.

Edit: jPCT-AE is cool btw.
« Last Edit: April 09, 2012, 01:13:21 pm by Peter Dym »

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Object rotation vs. world axes
« Reply #13 on: April 11, 2012, 07:18:38 pm »
Hi Egon, I do not know if I should ask here, because it is simply another problem, but I have it in this project so...after having the rockets navi done I wanted to do some simplification on my objects. And I'm fighting the whole day with one problem. My object is not shown correctly anymore. The plane is without wings :-)
I recreated the wings completely, I'm playing with settings, doing a copy of the correctly shown parts and modifying them like wings...nothing. And I'm asking here because of two things (I'm using the obj format):

1. Names are not set when obj is read. Simply the names are like "_jPCT...". Without the original name.

2. There is a warning shown:
"WARNING: This OBJ-file contains n-polygons with n>4! These polygons wont be displayed correctly!"
and because there is no name - I can not identify the wrong component.

...and my object is not displayed correctly.

Any idea what to do?

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object rotation vs. world axes
« Reply #14 on: April 11, 2012, 08:32:58 pm »
If possible, try to import the obj-file in another program and export it again. I'm using DeepExploration for this and it usually fixes flawed obj files for me. You can search the forum for some rants of mine about why obj is a crazy format...

And avoid n>4. jPCT won't load the correctly anyway.

You can also send the model to me if you want to and i can do that import/export step to see if that helps...