Rotation

I change a little bit the testRotateAboutPoint take a look.


public static void main(String[] args) {
    TestRotateAboutPoint app = new TestRotateAboutPoint();
    app.setConfigShowMode(ConfigShowMode.AlwaysShow);
    app.start();
  }

  protected void simpleUpdate() {
    if (tpf < 1) {
      angle = angle + (tpf * 1);
      if (angle > 360) {
        angle = 0;
      }
    }
    rotQuat1.fromAngleAxis(angle, axis);
    pivotNode1.setLocalRotation(rotQuat1);
   
    rotQuat2.fromAngleAxis(angle * 2, axis);
    pivotNode2.setLocalRotation(rotQuat2);
    s.setLocalRotation(rotQuat2);
    SceneMonitor.getMonitor().updateViewer(tpf);
   
  }

  /**
   * builds the trimesh.
   * @see com.jme.app.SimpleGame#initGame()
   */
  protected void simpleInitGame() {
    display.setTitle("jME - Rotation About a Point");

    //Planet
    s = new Sphere("Planet", 25, 25, 25);
    s.setModelBound(new BoundingSphere());
    s.setLocalTranslation(20,0,0);
    s.updateModelBound();
    rootNode.attachChild(s);
   
    //Moons
    moon1 = new Sphere("Moon 1",25, 25, 10);
    moon1.setModelBound(new BoundingSphere());
    moon1.updateModelBound();
    moon1.setLocalTranslation(40, 0, 0);
    pivotNode1 = new Node("PivotNode 1");
   [u] pivotNode1.setLocalTranslation(40,0,0);[/u]
    pivotNode1.attachChild(moon1);
   
    moon2 = new Sphere("Moon 2",25, 25, 7.5f);
    moon2.setModelBound(new BoundingSphere());
    moon2.updateModelBound();
    moon2.setLocalTranslation(60, 0, 0);
    pivotNode2 = new Node("PivotNode 2");
    pivotNode2.attachChild(moon2);
   
    rootNode.attachChild(pivotNode1);
    rootNode.attachChild(pivotNode2);
    SceneMonitor.getMonitor().registerNode(rootNode, "Root Node");
    SceneMonitor.getMonitor().showViewer(true);
}


protected void simpleRender()
{
   SceneMonitor.getMonitor().renderViewer(display.getRenderer());
}
}




in this code I want to moon1 rotate about its own axis. I supposed that but it is somehow rotating another axis.what is the lack of my oppinion??
I have a big trouble with rotation :S in these days.

if you want to rotate the moon around its own axis, you cant translate the moon itself.



moon1.setLocalTranslation(40, 0, 0);



You need to attach the moon to a moonNode.

Then attach the moonNode to the planetNode.

Now translate the moonNode.



If you now rotate the planet node, the moon will move around the planet.

If you rotate the Moon it will rotate around its own axis.

hello this is a code which I wroto poorly.



in this code, the model(saddle) composed of two part. I just want that this parts rotate their own axis. But I cannot figure out.



I used a lot of different ways, but it always rotating about (0,0,0). can anybody explain this is why?

model file is here.

http://www.ceng.metu.edu.tr/~e1449065/saddlee.3ds


public class eyer extends SimpleGame
{
   private static final Logger logger = Logger.getLogger(eyer.class
            .getName());
   
    public static void main(String[] args) {

        eyer app = new eyer();
        if (args.length > 0) {
            app.setModelToLoad(args[0]);
        }
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }

    private URL modelToLoad = null;

    private void setModelToLoad(String string) {
        try {
            modelToLoad = (new File(string)).toURI().toURL();
        } catch (MalformedURLException e) {
        }
    }

    protected void simpleInitGame() {
        if (modelToLoad == null) {
            modelToLoad = eyer.class.getClassLoader().getResource(
                    "deneme1/saddlee.3ds");
        }
        try {
            MaxToJme C1 = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            C1.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
            Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            r1.setLocalScale(30f);
//            if (r1.getChild(0).getControllers().size() != 0)
//                r1.getChild(0).getController(0).setSpeed(20);
           
            Quaternion temp = new Quaternion();
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            rootNode.setLocalRotation(temp);
            Node ust =  new Node("ustNode");
            Node alt = new Node("altNode");
            Spatial a = ((Node)r1.getChild(0)).detachChildAt(0);
            Spatial b = ((Node)r1.getChild(0)).detachChildAt(0);
            a.setLocalTranslation(0,0,0);
           
            a.setModelBound(new BoundingSphere());
            b.setModelBound(new BoundingSphere());
            a.updateModelBound();
            b.updateModelBound();
           
            alt.attachChild(b);
            ust.setLocalScale(30);
            alt.setLocalScale(30);
//            a.setLocalTranslation(0,0,0);
           
Vector3f vect = a.getWorldBound().getCenter();
System.out.println("iste bu" +vect.toString());
ust.setLocalTranslation(0,0,0);
ust.attachChild(a);
Sphere s = new Sphere("Planet", 25, 25, 5);
            s.setModelBound(new BoundingSphere());
            s.updateModelBound();
            s.setLocalTranslation(0,0,0);
          Node pivot = new Node("pivot"); 
            Quaternion q = new Quaternion();
            q.fromAngleAxis(FastMath.DEG_TO_RAD*90, new Vector3f(0,1,0));
//            a.setLocalRotation(q);
            pivot.attachChild(ust);
            pivot.attachChild(alt);
            pivot.attachChild(r1);
            pivot.attachChild(s);
            pivot.setLocalTranslation(0,0,0);
           // rootNode.updateWorldVectors();
            rootNode.attachChild(pivot);
           
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Failed to load Max file", e);
        }
       
        SceneMonitor.getMonitor().registerNode(rootNode, "Root Node");
        SceneMonitor.getMonitor().showViewer(true);
    }
   
    protected void simpleUpdate()
    {
       SceneMonitor.getMonitor().updateViewer(tpf);
   }

   @Override
   protected void simpleRender() {
      SceneMonitor.getMonitor().renderViewer(display.getRenderer());
   }
   
   @Override
   protected void cleanup() {
      
      SceneMonitor.getMonitor().unregisterNode(rootNode);
   }

}

i don't have time to try it out myself right now.



But i see you do funny things with the loaded 3ds model, detach childs of it and attach them to new nodes and stuff.

Is that really needed?

Maybe splitting the model into separate parts and loading them separately would be easier.

I see your point, but I am not a modeler. importing and exporting is the just I know about the modeling. (I know I must learn some thing about that).



furthermore, if I seperate this model two parts, how I know the where I put these.(I am talking about the exact place). in the modeling tools it easier I think. if I put these parts scene togather, I just aim that changing their parts location and then put back their old place(like a little bit animation).



do you have a clue about that.

I want to show a screenshot and a code.



as you can see in the below code I just import a model to the scene and I locate it to the (0,0,0).



and just create a sphere at the (0,0,0).



I think it is strange that these are in the different location. this must be my problem? (is this a bug or some thing I figure out)



thanks.



the screenshot



and the code


public class saddle extends SimpleGame
{
   private static final Logger logger = Logger.getLogger(saddle.class
            .getName());
   
    public static void main(String[] args) {

        saddle app = new saddle();
        if (args.length > 0) {
            app.setModelToLoad(args[0]);
        }
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }

    private URL modelToLoad = null;

    private void setModelToLoad(String string) {
        try {
            modelToLoad = (new File(string)).toURI().toURL();
        } catch (MalformedURLException e) {
        }
    }

    protected void simpleInitGame() {
        if (modelToLoad == null) {
            modelToLoad = saddle.class.getClassLoader().getResource(
                    "saddle/saddlee.3ds");
        }
        try {
            MaxToJme C1 = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            C1.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
            Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            //Node r = new Node("parent stuff");
            //r.attachChild(C1.get(new BufferedInputStream(modelToLoad.openStream()), BO));
            //r.setLocalScale(.1f);
            r1.setLocalScale(50f);
            if (r1.getChild(0).getControllers().size() != 0)
                r1.getChild(0).getController(0).setSpeed(20);
            Sphere s = new Sphere("sp",25,25,5);
            s.setLocalTranslation(0,0,0);
            Quaternion temp = new Quaternion();
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            //rootNode.setLocalRotation(temp);
            r1.setLocalTranslation(new Vector3f(0,0,0));
            //rootNode.attachChild(r);
            r1.setModelBound(new BoundingSphere());
            r1.updateModelBound();
            rootNode.attachChild(r1);
            rootNode.attachChild(s);
//            System.out.println("eyer merkez " + (r1.getWorldBound().getCenter()).toString());
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Failed to load Max file", e);
        }
    }

}

ah, then it seems that the 3d model was not centered when it got exported.

You need to load the model in a 3d modeler and re-center it somehow, then export it again.

Core-Dump is correct. It's a common problem with poorly-crafted models, especially characters that stand above the earth because the extent of their model goes beyond what you can see.