Moving an Object3D to another smoothly.

Started by dl.zerocool, May 26, 2010, 07:55:02 PM

Previous topic - Next topic

EgonOlsen

Don't be confused with the wording in the Javadoc...they are taken from desktop jPCT and i forgot to change them. In AE, the camera isn't double buffered. Everything works directly on one matrix. The only difference between rotateY(angle) and rotateCameraY(angle) is, that one rotates the matrix by angle and the other one by -angle. That can't be the reason of the problem.

dl.zerocool

#16
Oh strange.

Let me just show what I do:
Quote
tiltSensors.addSensorsListener(new SensorEventAdapter() {
       public void onOrientationChanged(OrientationEvent e) {
      // NOT A GOOD IDEA !!!! initial camera position should be kept
      // when initialized and then the necessary angle calculated.
      PLAYER.lookAt(honeyPot);
      PLAYER.rotateCameraY(e.yaw);
      PLAYER.rotateCameraX(-e.roll);
      // PLAYER.rotateCameraZ(e.pitch);
       }
   });
PLAYER inherits from Camera so it's a camera with few more members and function I added ( I know it should be composed instead of inheriting but I've very few time left and I'm doing as fast as I can).

now when I shout a projectile I take the vector direction and position to get the "starting point + direction" of the projectile.

I've just a little function live wich create the projectile
public void live(SimpleVector start, SimpleVector dir) {
this.dir = dir;
alive = true;
System.out.println("Bee : " + getName() + " IA id: " + getID());
System.out.println("Bee dir : " + dir.toString());
System.out.println("Bee start : " + start.toString());
translate(start);
//rotateY(Game.ROTATION_Y_FACE_SCENE_FROM_CAMERA);
show();
enableCollisionListeners();
   }


So nothing big here...
Then to move the projectile I do this

             dir.add(dir);
             translate(dir);

The problem is when I do this.
   
public void onFireBee()
   {
for(Weapon w: bees){
   if(!w.isALive()){
w.live(PLAYER.getPosition(), PLAYER.getDirection());
System.out.println("Live a bee : "+w.getName()+" id: "+w.getID());
break;
   }
}

I just "create" make a projectile alive, on an arraylist of projectiles when a button is pressed.

That's all, but when I do this the projectile still follow the initial camera direction not the current one...

ps: I don't touch camera values or function inside PLAYER, it's a direct call to Camera functions.

EgonOlsen

As said, rotateXXX in Camera works on the same matrix that getDirection uses. I don't see any reason why this shouldn't work nor have i ever experienced that problem. Does all this processing happens in the same thread? Remember that you have two (both triggered by Android), one that started the Activity and one that does the GL drawing. Maybe this interferes somehow? If that isn't the problem, a test case would be helpful as i can't verify this problem.

And another question: What is the "initial camera position" in this case?

dl.zerocool

#18
hmmmm I'm going to check this, but getDirection and getPosition are in one thread (game)

Sensors are initialized inside Game so basically rotates called by sensors event should be made inside game thread.
sensors are certainly threaded by android of course but I don't think this is the problem.

Because it should only cause a small change in angle in case fire bee is called before the angle is updated by sensors.
So this is not the case

The case is that it's always fired to ->initial getDirection

When I start the game Camera looking at center of the scene :
05-29 08:18:36.314: INFO/System.out(12161): End initialisation
05-29 08:18:38.844: INFO/System.out(12161): Bee : Bee0 IA id: 6
05-29 08:18:38.854: INFO/System.out(12161): Bee dir : (0.0,0.0,1.0)
05-29 08:18:38.854: INFO/System.out(12161): Bee start : (0.0,0.0,0.0)



After moved the camera and waited a while (to be sure that camera values have been update, but of cours they where because the camera moved)
Bee0 had time to die that's why it's again bee0 who is fired.
05-29 08:18:41.014: INFO/System.out(12161): Bee : Bee0 IA id: 6
05-29 08:18:41.014: INFO/System.out(12161): Bee dir : (0.0,0.0,1.0)
05-29 08:18:41.014: INFO/System.out(12161): Bee start : (0.0,0.0,0.0)




dl.zerocool

#19
Better print to understand :  start direction is  getDirection from camera  and start position getPosition.
Called each time a bee is fire

[First fire -> camera looking scene]
05-29 09:32:46.719: INFO/System.out(15615): Bee start direction : (0.0,0.0,1.0)
05-29 09:32:46.719: INFO/System.out(15615): Bee start position: (0.0,0.0,0.0)
05-29 09:32:46.719: INFO/System.out(15615): Live a bee : Bee0 id: 6


[Second fire -> camera looking away]
05-29 09:32:50.869: INFO/System.out(15615): Bee start direction : (0.0,0.0,1.0)
05-29 09:32:50.869: INFO/System.out(15615): Bee start position: (0.0,0.0,0.0)
05-29 09:32:50.879: INFO/System.out(15615): Live a bee : Bee0 id: 6



[edit]
since I only apply rotation to camera I understand that position never change
but direction should change T_T

EgonOlsen

Try to print out the content of the camera's matrix in addition (i.e. Camera.getBack()).

dl.zerocool

Here you have it : (First fire)
05-29 09:44:44.009: INFO/System.out(16056): Live a bee : Bee0 id: 6
05-29 09:44:44.029: INFO/System.out(16056): Camera onFire getPosition(0.0,0.0,0.0)
05-29 09:44:44.039: INFO/System.out(16056): Camera onFire getDirection(0.0,0.0,1.0)
05-29 09:44:44.039: INFO/System.out(16056): Camera onFire getBack(
05-29 09:44:44.039: INFO/System.out(16056):     1.0    0.0    0.0    0.0
05-29 09:44:44.039: INFO/System.out(16056):     0.0    1.0    0.0    0.0
05-29 09:44:44.039: INFO/System.out(16056):     0.0    0.0    1.0    0.0
05-29 09:44:44.039: INFO/System.out(16056):     0.0    0.0    0.0    1.0
05-29 09:44:44.039: INFO/System.out(16056): )



After rotation : (snd Fire)
05-29 09:44:46.579: INFO/System.out(16056): Camera onFire getDirection(0.0,0.0,1.0)
05-29 09:44:46.589: INFO/System.out(16056): Camera onFire getBack(
05-29 09:44:46.589: INFO/System.out(16056):     1.0    0.0    0.0    0.0
05-29 09:44:46.589: INFO/System.out(16056):     0.0    1.0    0.0    0.0
05-29 09:44:46.589: INFO/System.out(16056):     0.0    0.0    1.0    0.0
05-29 09:44:46.589: INFO/System.out(16056):     0.0    0.0    0.0    1.0
05-29 09:44:46.589: INFO/System.out(16056): )


After more rotation (just in case) :
05-29 09:44:50.359: INFO/System.out(16056): Camera onFire getPosition(0.0,0.0,0.0)
05-29 09:44:50.359: INFO/System.out(16056): Camera onFire getDirection(0.0,0.0,1.0)
05-29 09:44:50.359: INFO/System.out(16056): Camera onFire getBack(
05-29 09:44:50.359: INFO/System.out(16056):     1.0    0.0    0.0    0.0
05-29 09:44:50.359: INFO/System.out(16056):     0.0    1.0    0.0    0.0
05-29 09:44:50.359: INFO/System.out(16056):     0.0    0.0    1.0    0.0
05-29 09:44:50.359: INFO/System.out(16056):     0.0    0.0    0.0    1.0
05-29 09:44:50.359: INFO/System.out(16056): )




dl.zerocool

I think I've found something it's probably related to the fact that Player inerith from Camera.
When a player is create it does automaticly call constructor from Camera
perhaps at this moment it does override the jpct world camera.

I'm trying to do this with a composition instead.

EgonOlsen

I don't think so, but unless you are using PLAYER as the world camera, there's no relation between the two...i'm confused now about who is using which camera in which context...anyway, i've uploaded a new jar that corrects a small oddity in lookAt(). It now recycles the internal matrix instead of assigning a new one for each call. This may help, if you are buffering the back matrix somewhere yourself, so that you might work with an outdated instance of it. I doubt that this will help, but maybe it's worth a try.

dl.zerocool

Solved,

Ahhh... I can't trust this kind of things ^^

It was that, the camera from Player was not the Camera from jpct
But the object camera that Player created because he was extending Camera...

what is strange it that sensors does had effect on the Player.rotate  things who where functions from Camera directly...
Now what I do is pretty simple, Player is not more extending Camera, when I create a Player I pass a camera object
and I reimplemented the methods I need to call on Player.

So basically a composition :P

Thanks for your help !