Author Topic: animation example  (Read 7415 times)

Offline han1332

  • byte
  • *
  • Posts: 3
    • View Profile
animation example
« on: August 13, 2007, 03:25:21 pm »
hi!

I am a jpct beginner.
Can anybody send me simple examples using animation with keyframes.
For example moving a box from one position to another.

thank you
Hannes

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: animation example
« Reply #1 on: August 13, 2007, 04:01:18 pm »
Moving an entity isn't done via mesh keyframes, but by using the translate()-methode of Object3D.

Offline han1332

  • byte
  • *
  • Posts: 3
    • View Profile
Re: animation example
« Reply #2 on: August 13, 2007, 04:26:48 pm »
i know,
maybe it is a not a good example, but i only want to know how animation with keyframes works.
i want to use it for product animation, something should move in a certain
behavier(using certain interpolation methods) from one place to another.
i hope it is clear what i mean.

mfg hannes

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: animation example
« Reply #3 on: August 13, 2007, 04:30:25 pm »
Ok, then you can have a look at the advanced example, which can be downloaded from the download page (but it's maybe a bit overkill for beginners) or you can find some example code in the forum. Like in this thread (2nd post): http://www.jpct.net/forum2/index.php/topic,251.0.html

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Re: animation example
« Reply #4 on: August 13, 2007, 09:44:36 pm »
As Egon said, Object3D.translate(SimpleVector trans) moves the 3d object instance from one position to another.

If you wanted to play animations from a MD2, then Object3D.animate(float index, int seq)  is for you. The float data type is a number between 0 and 1; 0 = start of animation, 0.5 = middle of animation 1 = end of animation. The int seq refers to the animation index that you want your object to use.

I hope that helps!

Offline han1332

  • byte
  • *
  • Posts: 3
    • View Profile
Re: animation example
« Reply #5 on: August 13, 2007, 10:52:37 pm »
thanks for answering
it is quite clear now, but i still have troubles with animation.
i try to get it work with a box,but there is something wrong
is it basically correct?
Code: [Select]

private void init3DStuff()
{
....
  obj = new Object3D(Primitives.getBox(10, 1));
....
  anim = new Animation(2);
....
  anim.setInterpolationMethod(Animation.LINEAR);
  anim.addKeyFrame(obj.cloneObject().getMesh());
  obj.translate(10, 10, 0); 
  anim.addKeyFrame(obj.cloneObject().getMesh());
  obj.setAnimationSequence(anim);
  obj.build();
  world.addObject(obj);
}

private void gameLoop() {
......
while (!exit) {

....
if(anim_count <=1)
{
anim_count += 0.1f;
obj.animate(anim_count, 0);
}
else {
count = 0;
obj.animate(anim_count, 1);
}
....
.....
                try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}

System.exit(0);
}



thanks
hannes

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: animation example
« Reply #6 on: August 13, 2007, 10:59:35 pm »
No, because a translation is not permanent to the mesh, you are adding the same mesh data two times. Try to insert a translateMesh() before adding the second frame and see if that helps.