Get the physics control from the spatial or the opposite

Hi, my program does something simple. You select an object clicking it, you move it dragging the mouse, and then you drop it clicking again in a location. While the object is dragged, it’s spatial is painted wireframe, as a form of feedback.

Now I want to add collisions, so you can’t drop an object where there’s already one. I know from the tutorial you have to add a PhysicsControl to the object, and you must call setPhysicsLocation() on the control instead of setLocalTranslation() on the spatial.

Currently, I have a “picked” spatial as a member of the simple application that is what I use to paint the dragged object. Now if I must use setPhysicsLocation() to move it, I must have also the control around.

Is there a way to only use one of them, and get one from the other? Or which approach do you suggest?

Not sure if it’s what you’re looking for but you can do.
spatial.getControl(PhysicsControl.class);
and
control.getSpatial();

Do you want it to block if its put somwhere wher eit should not or only to be like red wireframe for no not there?

I suggest using a ghost physic thing, it only gives you collision events, but does not actually collide.

<cite>@nehon said:</cite> Not sure if it's what you're looking for but you can do. spatial.getControl(PhysicsControl.class); and control.getSpatial();

spatial.getControl seems like it could work. But control.getSpatial() seems not to exist, at least on RigidBodyControl.

<cite>@Empire Phoenix said:</cite> Do you want it to block if its put somwhere wher eit should not or only to be like red wireframe for no not there?

I suggest using a ghost physic thing, it only gives you collision events, but does not actually collide.

The red wireframe when in collision would work fine, and a condition that do not let the object be dropped when collision. How does this ghost physic work? Is it like this? (I found that after writing the question).

<cite>@jmonillo said:</cite> spatial.getControl seems like it could work. But control.getSpatial() seems not to exist, at least on RigidBodyControl.
uh, you're right.... I could have bet on this. There is only the setSpatial.
<cite>@jmonillo said:</cite> How does this ghost physic work? Is it like this? (I found that after writing the question).

Thats a geometry collision.

Ghostcontrols are for physics collisions:
http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/jbullet/com/jme3/bullet/control/GhostControl.java?r=6629

Keep it mind that they use the Bounding box of the collisionshape

If you use physics collisions, the callback from physics includes the spatials that correspond to the physics objects that are colliding.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics_listeners

[java]
public void collision(PhysicsCollisionEvent event) {
if ( event.getNodeA().getName().equals(“player”) ) {
final Node node = event.getNodeA();
/** … do something with the node … /
} else if ( event.getNodeB().getName().equals(“player”) ) {
final Node node = event.getNodeB();
/
* … do something with the node … */
}
}

[/java]

Ok, many thanks for the answers.

Now I’m currently thinking about using physics collisions or simple triangle collisions. And I still have to analize your answers to fully understand them.

But I think we can consider that the question is solved, because my next doubts will be about the problem. Thanks, again.