How to get originator object in the custom control

HiAll,

I have a main class A(extends simplegame) , a class B

I initialise class B in class A

[java] private void createObjects(){

    float xInit = currentWorld.getLocalTranslation().x;
    float xExtent = ((BoundingBox) currentWorld.getWorldBound()).getXExtent();

    // b=new Box(Vector3f.ZERO,1,1,1);
    //blue = new Geometry("Box", b);
    //Material mat1 = new Material(assetManager, 
    //   "Common/MatDefs/Misc/Unshaded.j3md");
    //mat1.setColor("Color", ColorRGBA.Blue);
    //blue.setMaterial(mat1);
    //blue.move(-(xInit+xExtent),0.5f,0); 
    tempS = c.getCar(currentWorld, assetManager);
    rootNode.attachChild(tempS);

}

private void initializeObjects() {
    //Vector3f newObjectVector=currentWorld.getLocalTranslation();
    c=new Car();        
}[/java]

In class B i add a custom control to the object

[java]Spatial getCar(Spatial currentWorld, AssetManager assetManager ) {

    this.currentWorld = currentWorld;
    //myControl=new myControl();
    System.out.println("Am i here? really?");
    float xInit = currentWorld.getLocalTranslation().x;
    float xExtent = ((BoundingBox) currentWorld.getWorldBound()).getXExtent();

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    Geometry blue = new Geometry("Box", b);
    Material mat1 = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.Blue);
    blue.setMaterial(mat1);
     blue.move(-(xInit+xExtent),0.5f,0); 
     
    blue.addControl(new myControl());
    return blue;

}[/java]

Now in the custom control UPDATE loop i need to get one variable(Node) to check collision. Or at least i need to get the controlled object class variable ( Car c in this case)

is it possible? if yes how?

PS I tried passing some object in custom control constructor but it doesnt work.

If the want the Spatial the control belongs to, there is a member variable called: spatial
They u can use

Nope the spatial is created in a custom class and added control in a method. I want to access that custom class. The idea for searching is that i want to remove the custoem objects from rootNode when the player(char) passes them.

I also have a query what happen to any object when it is removed from rootNode?

PS I tried passing some object in custom control constructor but it doesnt work.

This should work fine:

[java]new myControl (this);[/java]

or implement Savable, and pass it as UserData to the spatial.

Or the other 100 ways to do this :slight_smile:

@aniket0 said: Nope the spatial is created in a custom class and added control in a method. I want to access that custom class. The idea for searching is that i want to remove the custoem objects from rootNode when the player(char) passes them.

I also have a query what happen to any object when it is removed from rootNode?

I’m still not really clear what you are trying to do. Can you show us in pseudo code how you mean?