How to make a geometry rotation around its own??
Try this:
http://code.google.com/p/jme-simple-examples/source/browse/JMESimpleExamples/src/MifthBasics/RotateNode2.java
http://code.google.com/p/jme-simple-examples/source/browse/JMESimpleExamples/src/MifthBasics/RotateNode.java
http://code.google.com/p/jme-simple-examples/source/browse/JMESimpleExamples/src/MifthBasics/SpatialMotionsLinear.java
http://code.google.com/p/jme-simple-examples/source/browse/JMESimpleExamples/src/MifthBasics/SpatialMotionsSmooth2.java
http://code.google.com/p/jme-simple-examples/source/browse/JMESimpleExamples/src/MifthBasics/SpatialMotionsNonLinear.java
i means that the geometry rotate around itself no matter how to move it.
for example, the geometry(at (0,0,0)) rotate around y axis—in other way ,it rotate around itself.
when i move it to (20,20,20) , what should i do to make it rotate around itselt as before.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies
That’s what local rotation always does. A spatial’s local rotation is always around its own local origin.
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingSphere;
import com.jme3.material.Material;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
public class turnDemo3 extends SimpleApplication {
public static void main(String[] args){
turnDemo3 app=new turnDemo3();
app.start();
}
private Sphere s;
private Node pivotNode;
private float angle=0;
private Quaternion rotQuat= new Quaternion();
private Vector3f axis = new Vector3f(0, 0, 1);
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(150);
s = new Sphere( 25, 25, 2);
Geometry sun=new Geometry("sun",s);
sun.setLocalTranslation(5, 5, -5);
Material sun_mat = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
sun_mat.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
sun.setMaterial(sun_mat);
sun.setModelBound(new BoundingSphere());
sun.updateModelBound();
pivotNode = new Node("PivotNode ");
pivotNode.attachChild(sun);
rootNode.attachChild(pivotNode);
Box box=new Box(Vector3f.ZERO,0.3f,0.3f,1);
Geometry box_geo=new Geometry("Box",box);
box_geo.setMaterial(sun_mat);
rootNode.attachChild(box_geo);
}
public void simpleUpdate(float tpf) {
if (tpf < 1) {
angle = angle + (tpf * 1);
if (angle > 360) {
angle = 0;
}
}
rotQuat.fromAngleAxis(angle , axis);
pivotNode.setLocalRotation(rotQuat);
}
}
[/java]
Where is a ball rotating around a box . what i want to do is making the ball rotate around itselt instead of rotating around the box.
How to set the LocalRotation()?? how to set the axis?
In the above code, you put the sun out 5,5,-5 underneath a node that you turn. So the sun will be orbitting out away from and around the pivot node. And the box will be rotating around the origin… since that’s where it’s located.
What is it that you expect to happen?
pspeed said:
In the above code, you put the sun out 5,5,-5 underneath a node that you turn. So the sun will be orbitting out away from and around the pivot node. And the box will be rotating around the origin... since that's where it's located.
What is it that you expect to happen?
I am sorry ,i am new here. i do not understand you ! i want to make the ball rotate from left to right around itself at (5,5,-5).What should i do?
by the way ,which software do you use to make .mesh.xml file.For example ,the Oto.mesh.xml file in HelloAnimation.
siyupy said:
I am sorry ,i am new here. i do not understand you ! i want to make the ball rotate from left to right around itself at (5,5,-5).What should i do?
Ok, what you've done is the equivalent of holding the ball at the end of your arm (that's the sun) and spinning yourself around (that's the pivotNode). If you want the sun to rotate then rotate the sun.
sun.setLocalRotation()
I think those meshes are made with the ogre exporter in blender. I'm not sure.
pspeed said:
Ok, what you've done is the equivalent of holding the ball at the end of your arm (that's the sun) and spinning yourself around (that's the pivotNode). If you want the sun to rotate then rotate the sun.
sun.setLocalRotation()
I think those meshes are made with the ogre exporter in blender. I'm not sure.
Yeah ,Yeah ,it works . thank you very much!!
no worries