### Author Topic: Move object3D by touch&drag  (Read 1271 times)

#### denzel

• byte
• • Posts: 22 ##### Move object3D by touch&drag
« on: May 11, 2012, 05:10:13 am »
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
Code: [Select]
`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

•     • • Posts: 11970 ##### Re: Move object3D by touch&drag
« Reply #1 on: May 11, 2012, 08:29:56 am »
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

• byte
• • Posts: 22 ##### Re: Move object3D by touch&drag
« Reply #2 on: May 11, 2012, 11:36:19 am »
Sorry i cannt catch your means.
To get the camera actual axis in world space:
Code: [Select]
`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?@@
« Last Edit: May 11, 2012, 11:39:12 am by denzel »

#### EgonOlsen

•     • • Posts: 11970 ##### Re: Move object3D by touch&drag
« Reply #3 on: May 11, 2012, 12:19:22 pm »
..you add them all to one.

What you implicitly do ATM is this:

Code: [Select]
`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.