www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: dl.zerocool on May 26, 2010, 07:55:02 pm

Title: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 26, 2010, 07:55:02 pm
Hello.

I would like to know if someone know how to move an Object3D to another smoothly,
without using too much resources ?

Thank you in advance.
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 26, 2010, 08:04:54 pm
Like morphing?
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 26, 2010, 08:29:19 pm
No no just a simple translation algorithm :P
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 26, 2010, 08:55:05 pm
I don't get it...what is a translation if not a morph in this case. Any examples?
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 26, 2010, 09:13:56 pm
hmm... I didn't explain myself very well certainly. (sorry)

I want to move and object X to another object Y  position, but smoothly, and I want to use calculation time as low  as possible

The best would be to be able to render simple vector between both objects and make the object X follow this vector.

So if needed I can apply some math to this vector to make it less straight to the other object.

I don't know if I explained myself pretty well.
I already have a way to do it. But it's not very clean, and use too much calculation.

at moment I've a function "move" proprietary to each of my objects and make them move not in a straight line to a direction.

But I've to store few last pos value to be able to decide the next point to move to.

I don't want my object to move   like this ->    ___/\/\/\/  etc... I want something more smoth like a sinus or a cos ;)
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 26, 2010, 10:02:13 pm
To keep it simple and fast, i would use some kind of linear interpolation. But i guess, you are already doing something like that. What's wrong with it? Too slow?
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 26, 2010, 10:42:25 pm
No atm I'm using something like this
Code: [Select]
" if (getTransformedCenter().x < obj.getTransformedCenter().x)
    translate(speed, 0f, 0f);
etc."

Just wanted to know if there was something better.

I don't know pretty much 3D math, I know basic vectors equations etc...
find an opposite point of a plan, distance between a point and a line or a plan, projection of a point to a plan, apply matrice to transforme an object (rotate,
scale, translate)  etc..
So very basic IMO.

^^ I try to do a function to lookAt another object but I think I didn't understand it correctly XD
   public void lookAt(Object3D obj){
   lookVector.set(getXAxis().x-obj.getXAxis().x,
      getYAxis().y-obj.getYAxis().y,
      getZAxis().z-obj.getZAxis().z);
   
   setOrientation(lookVector.normalize(), obj.getYAxis().normalize());
    }
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 26, 2010, 11:11:56 pm
Those vectors have to be perpendicular and in your example, they are not (except by accident).
You might try to set the objects rotation matrix to delta.getRotationMatrix()...it will suffer from the usual lookAt drawbacks, but might be sufficient.
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 26, 2010, 11:17:23 pm
Thank you !
:)
"those vectors have to be perpendicular solved my problem"
I didn't tough they had to be perpendicular.

I was seeing dir as   vector director from A to B
and up like the vector OY of B

Thank you ;)
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 28, 2010, 02:22:03 pm
Another question, is it possible to know world camera position ?
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 28, 2010, 04:27:24 pm
Camera.getPosition()... ???
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 28, 2010, 05:19:17 pm
^^Sorry I forgot to inherit Camera
That's why I wasn't seeing the method.
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 08:28:16 am
I've another problem, I'm using camera.getDirection()

But even if I move the camera with camera.rotateCameraX/Y/Z
getDirection still continue to give me the direction of the backbuffer and not the actual poiting camera direction.

Is there a way to solve this ?

I shot projectiles from the camera position and direction that's why I need this.

[edit] I'm using rotateCamera  not rotate.
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 29, 2010, 08:42:29 am
Which backbuffer? The Camera in AE isn't buffered like in desktop jPCT, so you should be getting the current direction... ???
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 08:45:49 am
No sadly I'm not,

There's rotateCameraY(Rotates the camera around the y-axis.)  and rotateY wich(Rotates the backbuffer matrix around the y-axis.)

I'm using rotateCameraY

and when I do a getDirection I get the direction that the camera what initially pointing, not the current direction.
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 29, 2010, 08:50:16 am
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.
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 09:03:46 am
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
Code: [Select]
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.
Code: [Select]
   
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.
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 29, 2010, 09:16:45 am
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?
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 09:31:12 am
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 :
Code: [Select]
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.
Code: [Select]
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)


Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 09:35:19 am
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]
Code: [Select]
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]
Code: [Select]
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
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 29, 2010, 09:38:23 am
Try to print out the content of the camera's matrix in addition (i.e. Camera.getBack()).
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 09:46:38 am
Here you have it : (First fire)
Code: [Select]
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)
Code: [Select]
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) :
Code: [Select]
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): )


Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 09:56:10 am
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.
Title: Re: Moving an Object3D to another smoothly.
Post by: EgonOlsen on May 29, 2010, 10:00:46 am
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.
Title: Re: Moving an Object3D to another smoothly.
Post by: dl.zerocool on May 29, 2010, 10:03:20 am
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 !