How to make mesh penetrate through a j3o

Hi,
I am facing an issue with my project where I want to make a Line(com.jme3.scene.shape) penetrate into a j3o (Cylinder).
I imported a cylinder(j3o) created in blender. The model’s origin was set at the bottom (0,0,0) of the mesh as mentioned in (http://hub.jmonkeyengine.org/forum/topic/importing-animations-from-blender-2-62-using-ogre-xml-things-to-check-if-you-are-getting-problems/).
From the following code I see that the line is connected to the bottom of both of the cylinders which is fine.
[java]
Vector3f start = cylinder1.getLocalTranslation();
Vector3f end = cylinder2.get:LocalTranslation();
Line line = new Line(start, end);
[/java]

When I want the line to penetrate into the the cylinders, I increased the y component of start and end thinking that the line will move up and it should look like the Line is starting and ending inside the cylinders and not below the cylinders.
But by increasing the y component, the line is still connected to the bottom of the cylinders and looks like the cylinders have moved up.

Is it a limitation or is this the way the j3o works?

If y direction is the direction you want to move in depends on the location of the objects. You have to move the line along its axis and not alongthe y-axis.

@shrikantkhapare said: [java] Vector3f start = cylinder1.getLocalTranslation(); Vector3f end = cylinder2.get:LocalTranslation(); Line line = new Line(start, end); [/java]

When I want the line to penetrate into the the cylinders, I increased the y component of start and end thinking that the line will move up and it should look like the Line is starting and ending inside the cylinders and not below the cylinders.
But by increasing the y component, the line is still connected to the bottom of the cylinders and looks like the cylinders have moved up.

Is it a limitation or is this the way the j3o works?

No. But you will have to show us your code if you want us to properly help you. So far this is more like “I’m holding a piece of string and it’s fuzzy and made of wool. I used to have a 10 cm string but this one is nothing like that can you tell me how long it is?”

Otherwise, we spend lots of time playing “guess the issue” instead of solving the issue.

For example, from your description I could believe that you’ve incremented the y value directly from what you got from getLocalTranslation()… which means you inadvertently may have moved the cylinders, too. I can’t tell because I can’t see the code with the problem. You’ve only showed us the code that works.

Below is the code which does not work.

[java]
Vector3f start = cylinder1.getLocalTranslation();
Vector3f end = cylinder2.get:LocalTranslation();
start.y += 0.5f;
end.y += 0.5f;
Line line = new Line(start, end);
[/java]

I have just incremented the y value of start and end.

As I said, that code will only work in special cases, best brush up your vector math a bit:
(sorry, no link to “jME Math for Dummies” as the forum post field misses the help link bin)

@shrikantkhapare said: Below is the code which does not work.

[java]
Vector3f start = cylinder1.getLocalTranslation();
Vector3f end = cylinder2.get:LocalTranslation();
start.y += 0.5f;
end.y += 0.5f;
Line line = new Line(start, end);
[/java]

I have just incremented the y value of start and end.

…yes, and you’ve moved the cylinders at the same time since you are modifying their translation vectors directly.

What happens if you do?
[java]
Vector3f start = cylinder1.getLocalTranslation().clone();
Vector3f end = cylinder2.get:LocalTranslation().clone();
start.y += 0.5f;
end.y += 0.5f;
Line line = new Line(start, end);
[/java]

@pspeed you were right, I was moving the cylinder also. Fixed the bug in my code. Now it works fine. Thanks for the pointer :slight_smile:

@shrikantkhapare said: @pspeed you were right, I was moving the cylinder also. Fixed the bug in my code. Now it works fine. Thanks for the pointer :)

Apparently I’m really good at guessing the lengths of string without ever seeing them. :wink: