Pivot Points

Hi all,

I was creating a ThirdPersonHandler when I thought of something. My handler needs the player at (0, 0, 0) and the cameraNode somerwhere else within the handeled Node.



                             HandeledNode <-- Input Controls this
                                /               
                              /                 
                            /                      
      CameraNode (0, 0, -50)         Player (0, 0, 0)



This is done to achieve a pivot point around the player. But this is rather constricting.

So what I would like to do is add a setPivotPoint(Vector3f..) in each node and when a rotation occurs, the rotation rotates around that point. Its uselful for bones as well where each bone as a pivot point.

So with pivot points, i could do this instead:


player.setLocalTranslation(new Vector3f(0, 0, 10));
camNode = new CameraNode("CamNode", cam);
camNode.attachChild(player);
camNode.setPivotPoint(new Vector3f(0, 0, 10));



much easier on the eyes and on the brain

What are your thoughts about this?

DP

Try attaching the camera to the player node and controlling the player node (keyboard moves the player, mouse rotates the camera). A pivot point should not have to be explicitly set.

thats what I meant with that little tree diagram I drew.



But the thing is, a pivot point has already been initialised to (0, 0, 0) surely we can change that? It would mean one less node to attach things to, and collectively, with loads of pivot points, alot less objects.



DP

In your code you have:



camNode.attachChild(player);



so unless that’s a typo…



setting the local translation of any node in effect changes it’s pivot point. So, attaching the camera to the player (who is at (0,0,0)) and offsetting the camera to (0,0, -50), the camera will still pivot about (0,0,0).



Maybe I’m just not understanding your problem.

ok, this is the code that currently creates a virtual pivot point:



private Node InputControlledNode = new Node("Input Handlers controls this");

private CameraNode camNode;

public void initPlayer() {
  JmeBinaryReader jbr = new JmeBinaryReader();
 
  camNode = new CameraNode("Camera Node", cam);
  Node model = null;

  try {
    URL model = Main.class.getClassLoader().getResource("com/data/models/player/player.jme");
    model = jbr.loadBinaryFormat(model.openStream());
  }catch (IOException ioe) {
  }
 
  InputControlledNode.attachChild(model);
  camNode.getLocalTranslation().z = -50; // move it back from 0
  InputControlledNode.attachChild(camNode);
}



and this is the potential code that could do the exact same thing:


private CameraNode camNode;

public void initPlayer() {
  camNode = new CameraNode("Camera Node", cam);
  Node model = null;

  try {
    URL model = Main.class.getClassLoader().getResource("com/data/models/player/player.jme");
    model = jbr.loadBinaryFormat(model.openStream());
  }catch (IOException ioe) {
  }

  model.getLocalTranslation().z = 50; // move it forward to be displayed

  camNode.attachChild(model);
  camNode.setPivotPoint(new Vector3f(0, 0, 50));
}



As you can see, the potential code can be understood better because the idea isn't vaguely in the code, its concrete. The code is neater, and less objects are instantiated.

But thats my view.

DP

actually, the first method doesn’t work. So my question changes to, how do you create a pivot point? Mojo, i tried using your way, it didn’t work.



Heres my code for the initing of the scene:



Player p = new Player("Player", torso, arms, new Md2Animation());

// set the location of the cameraNode
camNode.getLocalTranslation().z = -100;
camNode.getLocalTranslation().y = 10;

// attach the player and the cameraNode to a node
playerNode.attachChild(p);
playerNode.attachChild(camNode);

// attach the playerNode to the scene
sceneNode.attachChild(playerNode);



and heres me initing the input after initing the scene:


input = new NodeHandler(this, playerNode, "LWJGL");


DP

What is your definition of a pivot point? The origin of the rotation?

yes, where the spatials in a node revolve around.

would spherical coordinates help?

Ok, DP, explicitly setting a pivot point doesn’t make sense in terms of the scene graph itself. You should rotate about your parent, because that is the defined behavior of the scene graph (your local origin is your parent’s location). So, if you want to change your pivot, you’ll have to add a pivot node.

cool. Thx for the help mojo. Greatly appreciated



DP