Author Topic: Moving an Object3D to another smoothly.  (Read 5509 times)

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Moving an Object3D to another smoothly.
« 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Moving an Object3D to another smoothly.
« Reply #1 on: May 26, 2010, 08:04:54 pm »
Like morphing?

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #2 on: May 26, 2010, 08:29:19 pm »
No no just a simple translation algorithm :P

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Moving an Object3D to another smoothly.
« Reply #3 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?

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #4 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 ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Moving an Object3D to another smoothly.
« Reply #5 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?

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #6 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());
    }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Moving an Object3D to another smoothly.
« Reply #7 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.

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #8 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 ;)

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #9 on: May 28, 2010, 02:22:03 pm »
Another question, is it possible to know world camera position ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Moving an Object3D to another smoothly.
« Reply #10 on: May 28, 2010, 04:27:24 pm »
Camera.getPosition()... ???

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #11 on: May 28, 2010, 05:19:17 pm »
^^Sorry I forgot to inherit Camera
That's why I wasn't seeing the method.

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #12 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.
« Last Edit: May 29, 2010, 08:46:25 am by dl.zerocool »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Moving an Object3D to another smoothly.
« Reply #13 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... ???
« Last Edit: May 29, 2010, 08:45:49 am by EgonOlsen »

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Moving an Object3D to another smoothly.
« Reply #14 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.