A proper way to translate AIS_InteractiveObject (AIS_Shape actually. It's polymorphism)

Hello. I'd like to translate a AIS_InteractiveObject on button press on a certain distance relative to it's position. 

I have came with the following code:

std::vector<Handle(AIS_InteractiveObject)> privateSimpleRig;

void performTestTranslocationOfCylinder(double xc, double yc, double zc)
{
    gp_Trsf secondTransformation;
    secondTransformation.SetTranslation(gp_Vec(xc, yc, zc));
    privateAISContext->SetLocation(privateSimpleRig[2], secondTransformation);
    privateAISContext->Redisplay(privateSimpleRig[2],true);
}

And button handler code fragment is:

            case 'W': {
                performTestTranslocationOfCylinder(0.0, 10.0, 0.0);
                
                break;
            }
            case 'S': {
                performTestTranslocationOfCylinder(0.0, -10.0, 0.0);
                
                break;
            }

Location is changed, but figure moves only to 10 points from starting location on btn press. I'd like to make it "travel" over the scene, translate AIS_InteractiveObject with relation to its current location each time button is pressed by a given amount.

I may store a position of figure on scene in a separate variable, but I suppose that this position is stored in ais_shape instance. Probably I should use gp_Trsf in some other way?

Ivan P's picture

I have this code:

    TopoDS_Shape theShape = privateSimpleRig[2]->Shape();
    gp_Trsf secondTransformation;
    secondTransformation.SetTranslation(gp_Vec(xc, yc, zc));    
    privateAISContext->SetLocation(privateSimpleRig[2], secondTransformation);
    
    theShape.Move(secondTransformation);
    privateSimpleRig[2]->SetShape(theShape);
    privateAISContext->Redisplay(privateSimpleRig[2],true);

But the first time the I call it with

performTestTranslocationOfCylinder(0.0, 10.0, 0.0);

it jumps for 30 units! Further it runs for 10 units. But when I change direction - it translates a figure on a wrong distance.

Ivan P's picture

Removed the line

privateAISContext->SetLocation(privateSimpleRig[2], secondTransformation);

and it's moving like it should