Rotate Cylinder to point to a vector3f

how do i rotate a cylinder to point to a vector3f() coordinate specific in jmonkey engine…

In very general terms, your cylinder is a node in the scene graph, and you can do Node.lookAt( … ).

The SDK tutorials, docs, and videos (start here) help alot in this type of situation - explaining parameters and their meanings, etc.

Good luck :slight_smile:

1 Like

Yep, also just to add that if its aligned vertically in model space and you want the top to point somewhere then you can also use spatial.rotateUpTo()

thx guys a lot. It Worked!. Just one more question: how do I alter a geometry center? because my cylinder is rotating in its middle and i wish it rotate its bottom. also in a way that after i alter it. if i move localTransition or move its still relative to its bottom. How do i do that? sry anything because i am new in jMonkey.

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

My ideia is: create 2 sphere then connect them using a cylinder and i need to do in way that i can alter it all time… because I’ll read new positions, move the spheres to its new positions and reconnect them with a cylinder. How do i do that?

I created both spheres + cylinder, but i dont know how to do a cylinder connecting them.

I guess you are Brazilian, so I’m going to talk to you in portuguese :slight_smile:

portuguese:
“Você quer criar um cilindro com 2 esferas nos pólos? Você precisa ter noções de vetores, quaternions, e scenegraph, então:”

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

e

@pspeed said: Perhaps this helps: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

Portuguese:

Eu não posso. Eu to usando o Kinect. É projeto de faculdade. Eu leio as coordenadas das juntas do kinect, posiciono as juntas que seriam as esferas e depois eu crio um cilindro ligando elas. Por isso que eu preciso fazer isso de uma forma que dado as coordenas das 2 esferas eu consigo criar um cilindro ligando elas.

English:

I can’t. I am using kinect. It’s a university project. I read kinect’s joints coordinates, create 2 sphere in the joints’ coordinates, and draw a cylinder connecting them. That’s why i have to do that: given the spheres’ coordinates i can create a cylinder connecting them

And that would involve setting up the scene graph hierarchy properly and giving things the proper offsets and rotations. Thus the links provided.

it would be doing something like Material.getAdditionalRenderState().setPolyOffset()?

i am not familiar with 3D world… i am very very noob really hahaha… Its my first 3D advanture. and in jMonkey…

how can i setting up the scene graph hierarchy properly and giving things the proper offsets and rotations?

Add the cylinder to a node. setLocalTranslation() on the cylinder. Rotate the node.

i tried to add the cylinder to a node setLocalTranslation() to half its size (to center its bottom) and use lookAt(). But that did not worked. I am trying to adapt Andrew Davison Skeletal Tracking to jMonkey Engine and later adapt it to use a 3D model from Blender 3D.

Attach the cylinder to a node. Attach it to a node. It will be the child of a node. setLocalTranslation() on the Geometry. On the Geometry you will call setLocalTranslation(). You will adjust the offset by calling setLocalTranslation() on the Geometry. Rotate the Geometry by 90 degrees so that it looks down the Z-axis.

Then you rotate the node, use lookAt() on the node. The node is the thing you rotate. Rotate the node and not the geometry.

To summarize:

  1. Attach the Geometry to a Node.
  2. Rotate the Geometry 90 degrees to point down the Z-axis.
  3. Translate the Geometry by half it’s height.
  4. Rotate the NODE to lookAt() the other sphere.

Short of writing the code for you there is not much else we can tell you.

I wrote this as you said. But my cylinder did not alighed to my 2 spheres

Geometry sphere1 = createSphere("Sphere1",ColorRGBA.Brown,5); Geometry sphere2 = createSphere("Sphere2",ColorRGBA.Blue,5); Geometry cylinder = createCylinder("Cylinder",ColorRGBA.Red,1.0f,20f);
    sphere1.setLocalTranslation(new Vector3f(10,1,0));
    sphere2.setLocalTranslation(new Vector3f(-10,10,10));
    Node pivot = new Node();
    pivot.attachChild(cylinder);
    cylinder.setLocalTranslation(new Vector3f(10,10,0));
    Quaternion pitch90 = new Quaternion();
    pitch90.fromAngleAxis(FastMath.PI / 2, new Vector3f(0,0,1));
    cylinder.setLocalRotation(pitch90);
    pivot.lookAt(sphere2.getLocalTranslation(), Vector3f.ZERO);

    rootNode.attachChild(sphere1);
    rootNode.attachChild(sphere2);
    rootNode.attachChild(pivot);</blockquote>

I tried all options for 2 parameter in lookAt() nothing worked so…

any ideia? sorry man… i am really noob … and not lazy haha… =D

will it work if one of my sphere is down in y axis? i mean: will it work in any position my 2 sphere might be?

Sometimes it helps to break things down one at a time to see if they are really doing what you think they are.

For example, this is not what you want:
pitch90.fromAngleAxis(FastMath.PI / 2, new Vector3f(0,0,1));

It will rotate around the z axis… ie: the cylinder will be aligned with the X axis. You need to rotate around the x-axis if you want to point down Z.

If it’s a University project, I wonder how much help we are really supposed to be giving versus letting your professor teach you.

he just gave me a book. and went abroad. I am on my own… :D.

About 2 year ago I did my thesis with kinect too, and I did the things easier. I created a model in blender with armatures, with lots of spheres, where each sphere represented a joint. Then I exported it into jme, and created a mocap control to it, based on jme ragdoll control. Moral of the story: creating models programmatically is a lot more difficult than using a model editor, mainly for newbies.