Object rotation vs. world axes

Started by Peter Dym, February 29, 2012, 05:24:57 PM

Previous topic - Next topic

Peter Dym

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]


Peter Dym

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]

EgonOlsen

#3
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).

QuoteAnd 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...

Peter Dym

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]

EgonOlsen

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.

EgonOlsen


Peter Dym

#7
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]

EgonOlsen

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).

Peter Dym

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. 

Peter Dym

#10
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]

EgonOlsen

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.

Peter Dym

#12
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.

Peter Dym

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.

EgonOlsen

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...