animation example

Started by han1332, August 13, 2007, 03:25:21 PM

Previous topic - Next topic

han1332

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

EgonOlsen

Moving an entity isn't done via mesh keyframes, but by using the translate()-methode of Object3D.

han1332

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

EgonOlsen

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

Mizuki Takase

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!

han1332

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?


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

EgonOlsen

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.