[SOLVED] Jme3 Beginner: Understanding the rotation Concept

so if u have a spatial created at (0,0,0) if you rotate 180 degrees around the y axis using something like

spatial.rotate(0,3.14,0) the spatial turns around in 180 degrees.

Now if that spatial is created at (5,0,0) , and using the same rotation function it will rotate around the same y axis in a circular motion around it. How do I go about making the spatial rotate around itself (i.e. staying at the same location but rotating in 180 degrees like its located at 0,0,0 )?

You could translate the box to the origin, perform the rotation and translate back to it’s position.



Or you could have a node attached to the origin (center) of the box and perform the rotation.

Tried both no luck… can’t tell what i’m doing wrong. I do prefer the 2nd option tho



so now working on the rotation translation and l would do something like:



[java]spatial.setLocalTranslation(5,0,0);

spatial.rotate(0,(float) 1.1,0);

spatial.setLocalTranslation(-5,0,0); [/java]



won’t do it , still rotates in a circular way, what am I doing wrong?

Can you post the rest of the code you’re working with? I think something else is getting fudged up… I’m actually getting the rotation around the origin of the cube without extra translation or having to attach an extra node.

Here’s what I have based off of simpleapplication:



NOTE: Even using your method of rotation, I get a rotation about the origin of the box

[java]package mygame;

import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Matrix3f;

import com.jme3.math.Vector3f;

import com.jme3.math.Quaternion;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {

    Box b;

    Geometry geom;

    Material mat;

    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }

    @Override

    public void simpleInitApp() {

    b = new Box(Vector3f.ZERO, 1, 1, 1);

    geom = new Geometry("Box", b);

    geom.setLocalTranslation(5,0,0);

    geom.updateModelBound();

    mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

    mat.setColor("m_Color", ColorRGBA.Blue);

    geom.setMaterial(mat);

    rootNode.attachChild(geom);

    }

    @Override

    public void simpleUpdate(float tpf) {

    //TODO: add update code

    Quaternion quatA = new Quaternion();

    quatA = quatA.fromAngleAxis(FastMath.HALF_PI * tpf, Vector3f.UNIT_Y);

    geom.rotate(quatA);

    }

    }

    [/java]

weird…

This is where I create my spatials first spatial model[0] is 0,0,0 and 2nd one model[1] is 5,0,0

[java]

public void create3dObjects(AnimationEvent[] eArray) {

for (int i=0; i<= spatialsNumber - 1; i++)

{

Box d_unit = new Box(new Vector3f(eArray.x, eArray.y, eArray.z), 1, .25f, .5f);

model = new Geometry(eArray.id, d_unit );

if(assetManager == null)

{

System.out.println("WARNING: Asset Manager is null");

}

AssetManager assetManager = null;

assetManager = JmeSystem.newAssetManager(Thread.currentThread().getContextClassLoader().getResource("com/jme3/asset/Desktop.cfg"));

Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

mat1.setColor("Color", ColorRGBA.Orange);

model.setMaterial(mat1);

rootNode.attachChild(model);

}

}

[/java]

and here is when I am attempting the rotation

[java]

float[] rotation = {0, 3, 0};

cinematic.addCinematicEvent(4, new RotationTrack(model[1], rotation, 1));[/java]

this will rotate aorund the main Y axis (circular and not around itself)

I tried nodes and translation same thing

as i said in the other post, create the box at 0,0,0 then translate the geometry.



the thing is new Box(new Vector3f(eArray.x, eArray.y, eArray.z), 1, .25f, .5f); offsets the vertices of the mesh according to the given center, but it’s not the center of the geometry.

I admit this is quite confusing, i never understood why the box constructor takes the “center” as a parameter.

1 Like

Great! Thanks