Author Topic: Help adding movement to the Ninja demo  (Read 18727 times)

Offline neo187

  • int
  • **
  • Posts: 73
    • View Profile
Help adding movement to the Ninja demo
« on: September 11, 2011, 08:52:31 pm »
Hello

Sorry for what could seem like an extremely noob question. I have just discovered jPCT AE which seems perfect for my Android project. I am playing with the Ninja demo as I will be needing to have a skeletal model in, I am just trying to test mesh movement.

So in the addNinja method (the button for adding extra copies of the model) the mesh is placed with:

ninja.getRoot().translate((float)(Math.cos(angle) * radius), 0, (float)(Math.sin(angle) * radius));

Under that I am testing moving the model a bit on the Y axis everytime a new one is added:

ninja.getRoot().translate(new SimpleVector(0.0f,3.0f,0.0f));

I've actually tried any coordinates but i don't see any changes...am I looking at the right method for translating meshes in world space?

Thanks a lot!


Offline MrM

  • byte
  • *
  • Posts: 36
    • View Profile
Re: Help adding movement to the Ninja demo
« Reply #1 on: September 13, 2011, 03:54:06 am »
Taken from DOC, Object3D:
Quote
translate

public void translate(float x,
                      float y,
                      float z)

    Translates ("moves") the object in worldspace by modifying the translation matrix. The translation will be applied the next time the object is rendered.
Trust me, the DOC will help you A LOT when beginning with JPCT, it's very thorough and well made.
http://www.jpct.net/doc/

I guess it's the right method, although I don't know it's being rendered since I haven't seen the demo.
Keep in mind that:
http://www.jpct.net/wiki/index.php/Coordinate_system

Sine and Cosine have really small values (from -1 to 1), and depending on the radius, I guess (Math.cos(angle) * radius) or (Math.sin(angle) * radius) would still give a really small value.
So, try translating to really small values, like ninja.getRoot().translate(new SimpleVector(0, 0.3f ,0.)); or even 0.03f, just to check that the ninja isn't moved too far away to see.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Help adding movement to the Ninja demo
« Reply #2 on: September 17, 2011, 02:57:56 pm »
@neo187, if you want to move the model around, you should translate it every frame, not when a new ninja is added.

AnimatedGroup.getRoot().translate(..) is the correct and recommended way of this.

Offline neo187

  • int
  • **
  • Posts: 73
    • View Profile
Re: Help adding movement to the Ninja demo
« Reply #3 on: September 17, 2011, 09:57:02 pm »
Thanks guys. That did work ok if called at every frame.... Any suggestions on how to make the character move in relation to the camera position? So that if the camera rotates and you press forward the character moves in that forward direction?

Thanks all for your great help, love this forum!

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Help adding movement to the Ninja demo
« Reply #4 on: September 18, 2011, 04:45:40 pm »
something like this:

Code: [Select]
SimpleVector d = Camera.getDirection();
d.scalarMul(..);
AnimatedGroup.getRoot().translate(d);