Move object3D by touch&drag

Started by denzel, May 11, 2012, 05:10:13 AM

Previous topic - Next topic

denzel

Which i need is to move an model along the screen X-AXIS and Y-AXIS but never Z-AXIS by drag
Now I can get the model in the screen which is been touched, and i can move them by drag with this code
SimpleVector simpleVector = Interact2D.reproject2D3D(camera, frameBuffer, x, y).normalize();
if(collition != null){
SimpleVector cPosition = camera.getPosition();
int cz = (int) cPosition.z;
int a = (int) (z_plane - cz / simpleVector.z);
int xx = (int) (cPosition.x + a * simpleVector.x);
int yy = (int)(cPosition.y + a * simpleVector.y);
simpleVector = new SimpleVector(xx, yy, z_plane);
collition.clearTranslation();
collition.translate(simpleVector);
}

But it donot go well if the camera has a rotation, i think it's about the z_plane i always support it to 10
What should i do to fix this?

EgonOlsen

You can get the actual axes of the camera in world space from it. Try to multiply that with your xx,yy,...values (i would use floats instead of ints btw) and translate by that. If that doesn't work, try the same with an inverted camera matrix.

denzel

#2
Sorry i cannt catch your means.
To get the camera actual axis in world space:
SimpleVector cPosition = camera.getPosition();
SimpleVector cXA = camera.getXAxis();
SimpleVector cXAA = new SimpleVector(cPosition.x * cXA.x, cPosition.y * cXA.y, cPosition.z * cXA.z);

That's the camera's actual X axis?
And when i get the y-axis, z-axis and multiply with xx,yy,zz,there are there SimpleVectors,how to translate the model?@@

EgonOlsen

..you add them all to one.

What you implicitly do ATM is this:


SimpleVector xAxis=new SimpleVector(1f,0,0);
SimpleVector yAxis=new SimpleVector(0,-1f,0);
SimpleVector zAxis=new SimpleVector(0,0,1f);

xAxis.scalarMul(xx);
yAxis.scalarMul(yy);
zAxis.scalarMul(zz);

SimpleVector trsn=new SimpleVector(xAxis);
trsn.add(yAxis);
trsn.add(zAxis);


Just because your are working with the untransformed axes, you can simplify this to what you have in your code. But the actual operation is the one above. Now simply replace the creation of the SimpleVectors with the get?Axis()-methods from the camera matrix.