Problem with understanding rotation conception

Hello Guys!

I know, that this theme was discribed a lot of times (I spent more then month for this and also read a lot of forum topics about this), but nothing can help me to understand.

My goal is to rotate a spatial (which locates in (0,2,0), for example) around the line that starts from cam.getLocation() and finishes in cam.getLocation().add(getDirection()). And all that I try, in result, performs rotation around a vector which starts in (0,0,0) and finishes in cam.getLocation().add(getDirection()). Like this:
[java]rotVector = cam.getLocation().add(cam.getDirection());
Quaternion quat = new Quaternion();
quat.fromAngleAxis(FastMath.QUARTER_PI, rotVector);
node.rotate(quat);[/java]
I know, that my question is very stupid, but I already have no strength for this. My nerves are on edge! I really need your help. That’s forced me to write on this forum.

Thanks in advance

P.S. And also sorry for my poor english! So it was very difficult for me to write this post (in all senses), also because this is my first note on this forum! :slight_smile:

1 Like

You started with a unit vector… turned it into not a unit vector and then tried to use it as a unit vector.

Try:
[java]quat.fromAngleAxis(FastMath.QUARTER_PI, cam.getDirection());[/java]

And also for understanding 3D conception:
How can I operate the vectors, which starts not in origin (0,0,0)? Or what kind of transformation I have to perform with «regular» vectors (or spatials) to manipulate (rotation, translation) in this style?

@pspeed said: You started with a unit vector... turned it into not a unit vector and then tried to use it as a unit vector.

Try:
[java]quat.fromAngleAxis(FastMath.QUARTER_PI, cam.getDirection());[/java]

In this case rotation also performs around the vector which starts in origin, with direction relative to my view point. For example:

That’s because your rotVector starts in (0,0,0) as all vectors do. As far as I know, you can’t set the starting location of a vector.

You need to try to bring your object to (0,0,0), then perform the rotation to it, then calculate the new position and reposition the object again.

I am not sure if there is a method to rotate an object around an axis other then it’s own which does all this for you.

@husky said: That's because your rotVector starts in (0,0,0) as all vectors do. As far as I know, you can't set the starting location of a vector.

You need to try to bring your object to (0,0,0), then perform the rotation to it, then calculate the new position and reposition the object again.

I am not sure if there is a method to rotate an object around an axis other then it’s own which does all this for you.

I have no idea how to implement it, particularly regarding the calculation of the new position (for reposition) after rotation :frowning:

Normally, any object do rotate around its origin. If you want to rotate around some point, you need to add a node to that point, attach your object (child of that node) and then rotate the node.

The only other way would be to alter the mesh directly, but this may not be what you’re looking for either…

How about

  1. Create a vector of objects original location
  2. Subtract the getLocation from this and store in new vector tempVec (to get a vector from object to camera location)
  3. Move object to (0,0,0)
  4. Rotate object with required rotation
  5. Rotate tempVec with required rotation (to calculate objects new position when rotated around camera axis)
  6. Add tempVec to getLocation and move object to there

This is just on top if my head so I am not sure if it works, but I think you have to go this direction.

1 Like

@husky: this is what you need to do if you want to transform the mesh.

Nodes are the tools provided to do this to be honest, no need to do all the steps husky suggests. Just attach the model with a local translation to a node. Rotate that node to move the model in a circle. Rotate the model inside its node to face it where you want.

The scene graph for dummies tutorial has examples which covers this case if you combine them…

Yeah, but then you still have to move the node to the camera axis. But indeed, creating a node at the camera location, adding the object as a child, rotating the newly created node (after moving it to (0,0,0)?) and moving it back to the camera location should work.

Or could you perform only a local rotation of the object, once it is attached to the new node? Will it then rotate around the new nodes position?

No need to move the node to 0. Just rotate it.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

Slide 18 onwards, in particular slide 29 and 33 although you should read the proceeding slides for it to make sense.

1 Like

Hi, Guys!

I have one more question to you:
I have a model which I have exported from Blender (through OgreXML script). It looks like:

This model contains a group of meshes (human body parts) which were organized in Blender (according to human anatomy). When I imported this model into my JME project (and also added into my Scene Graph), I got a node with GlobalTranslation (0,0,0), but the meshes are still organized like it was in Blender. So, how can I get its “real” coordinates (like it looks like on a screen)?

Take a look at the geometries inside the node. You can use the scene explorer to do that…

@woodley said: Hi, Guys!

I have one more question to you:
I have a model which I have exported from Blender (through OgreXML script). It looks like:
[snipped]

The above statements suggest your first problem has been solved. I do understand how nice it feels to have things working after you’ve worked hard and failed and ask for a bit of help and got a solution (and hopefully an understanding of the problem and its solution). Problem here is if you’re not updating others on your progress and how it was solved, then nobody can benefit.

Anyway. Long story short, do everyone a favor and tell us which solution worked for you so if someone else has a similar problem your solution can be found by the search engine.

That is all.

1 Like
@madjack said: The above statements suggest your first problem has been solved. I do understand how nice it feels to have things working after you've worked hard and failed and ask for a bit of help and got a solution (and hopefully an understanding of the problem and its solution). Problem here is if you're not updating others on your progress and how it was solved, then nobody can benefit.

Dear madjack,
I’m still in the process of resolving my problem and my second question relates directly to the problem.
According to zarch’s post, I understand, that I have to:

  1. Move «rotatable» node to the point of ratation

  2. Move «rotatable» spatial back to the original location

  3. Perform node rotation
    Now, I have to determine point of ratation (on the line) where I have to translate my node. To do this, I define a triangle:

    Where A — center of the spatial, that I have to rotate, BC — line, around which I have to rotate, AD — altitude of the ABC triangle, D - point of rotation.
    I define a method, that gets coordinates of the triangle vertex and returns altitude coordinates
    [java]
    public static Point3d getAltitude (Point3d a, Point3d b, Point3d c) {
    double Xa, Ya, Za, Xb, Yb, Zb, Xc, Yc, Zc;
    double S,sideBC,sideAD,sideBD, altitudeX, altitudeY, altitudeZ,t1,t2,t3,t4;
    Point3d altitude;

     Xa = a.x;
     Ya = a.y;
     Za = a.z;
     Xb = b.x;
     Yb = b.y;
     Zb = b.z;
     Xc = c.x;
     Yc = c.y;
     Zc = c.z;
    
     S = Math.sqrt(Math.pow(((Yb-Ya)*(Zc-Za)-(Zb-Za)*(Yc-Ya)),2) + Math.pow(((Xb-Xa)*(Zc-Za)-(Xc-Xa)*(Zb-Za)),2) + Math.pow(((Xb-Xa)*(Yc-Ya)-(Yb-Ya)*(Xc-Xa)),2))/2;
     sideBC=Math.sqrt(Math.pow((Xc-Xb),2)+Math.pow((Yc-Yb),2)+Math.pow((Zc-Zb),2));
     sideAD=2*S/Math.abs(sideBC);
     
     t1 = Math.pow(Math.abs(Xa-Xb),2);
     t2 = Math.pow(Math.abs(Ya-Yb),2);
     t3 = Math.pow(Math.abs(Za-Zb),2);
     t4 = Math.pow(Math.abs(sideAD),2);
     sideBD=Math.sqrt(Math.abs(t1 + t2 + t3 - t4));
     
     altitudeX=(sideBD / sideBC)*(Xc-Xb)+Xb;
     altitudeY=(sideBD / sideBC)*(Yc-Yb)+Yb;
     altitudeZ=(sideBD / sideBC)*(Zc-Zb)+Zb;
     return altitude = new Point3d(altitudeX, altitudeY, altitudeZ);
    

    }
    [/java]
    To solve this task (find D point coordinates), I need coordinates of the triangle vertex.
    There is no problem for me to get B and C points coordinates, but now I need coordinates of the A point.

That’s why I wrote second post. :slight_smile:

@zarch said: Take a look at the geometries inside the node. You can use the scene explorer to do that...
When I try to do this, I still get (0,0,0): [java] for (Spatial currentChild : selected.getChildren()) { System.out.println(currentChild.getName()); System.out.println(currentChild.getClass()); Geometry geometry = (Geometry) currentChild; System.out.println(geometry.getWorldTranslation()); System.out.println(geometry.getLocalTranslation()); } [/java] Output: Head-geom-1 class com.jme3.scene.Geometry (0.0, 0.0, 0.0) (0.0, 0.0, 0.0)

Thats probably because all your meshes have origin at (0, 0, 0). Move them in blender

@wezrule said: Thats probably because all your meshes have origin at (0, 0, 0). Move them in blender

Can you explain in more detail?
I cant understand, why on a screen it looks like an objects with some coordinates different from each other (and not in (0,0,0)), but getLocalTranslation/getWorldTranslation returns me an origin!? Can I get a coordinates “like it looks like”?

Sorry for my stupidity! :slight_smile:

We are only guessing because we don’t know your scene graph setup and haven’t seen that code.