Hi everyone, I want an object to be rotated according to the horizontal movements of the body.
The idea is as follow, if it moves to the right the object rotates clockwise and if it moves to the left it rotates counterclockwise.
Every single step of rotation is of 90º, so the idea behind is that if I move 2 steps the object should rotate 180º, if I move 3 steps, 270º, etc.
I want to achieve that the angle of rotation changes discretely along the movement, ie. according the person is moving the object rotates.
The amount of rotations is given for the amount of the body displacement (center of mass).
My approaches were the following (for sure there are better solutions):
being pos_ant and pos_cur the previous and current position, of the X coordinate of the center of mass, between frame to frame I do
pos_curr - pos_ant /threshold
It gives me how many rotations I have to do. threshold is how long a step is. The sign gives the sense of the rotation.
I divided the screen into several spots along the x axis, according to how many x spots the user went through from one frame to another I get the amount of rotations.
The problem with those approaches is that per one step the user makes the object to rotate several times…almost it is spining!, and I want it to rotate discretely. One step - one rotation.
I need it rotate more than once, but discretely and synchronously with the user movement.
Basically, how is the better way to detect a step to make the object rotate accordingly?
I highly appreciate any suggestion.
Are you doing the motion through openCV?
If you’re using the ofxOpenCV you can have a look at
getPixelsAsFloats(); so you can get the motion from the cv images that you create as float values. Then you can work out the average direction.
You can do this in a loop adding the motion to a total motion for each axis.
totalX += axisX
totalY += axisY
Then you can create an average of the values
avgX = totalX / numOfEntries;
avgY = totalY / numOfEntries;
Then combine them
ofPoint avgDir = ofPoint(avgX, avgY);
Then you could rotate by the average direction.
But it sounds like you want to be more specific. You could look at machine learning - Wekinator to map your motion to specific areas. This may help you better specify the rotation. For example, you can say if you want the rotation to be at this point if the x-axis value is this. There are some tutorial videos on there to help you out.
Hope that helps.
@elliot, thanks for your response, actually I get the body’s centre of mass by using ofxOpenNI ( I am going to shift to openNI2 though).
Actually I need the angle of rotation to be 90º per movement. looking at your method I think I need to rotate when I reach the numOfEntries (correct me if I am wrong)
numOfEntries depends on the number of frames ? or is it just a kind of threshold set by me?
I know what wekinator is, I don’t know if its suitable for my purposes. If you meant by specific areas certain zones of the screen in pixels (the method 2 I mentioned above), yes, there are areas.
Later I will have my hands on this project and I will try your idea or a something derivative from it.