Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid min3D using touch to rotate around an object
    primarykey
    data
    text
    <p>I'm trying to rotate the camera around an object by using the touchscreen. The rotation around Y axis works fine (The X axis is disabled). Rotation around the X axis is really weird. when the Object (its a rocket) gets higher <code>rocket.position().y++ &amp; scene.camera().position.y++</code>, the rotation around the x axis gets bigger and weird. If the rockets stops <code>rocket.position().y = 500; &amp; scene.camera().position.y = 500;</code>, I can't rotate around x axis, I zoom in or out the object instead. With both axis enabled its weird as hell.</p> <p>In <code>initScene</code> I set the camera to look at the center of the rocket. </p> <p>Here's my code:</p> <pre><code>initScene: scene.camera().position.z = 90; scene.camera().target = raketeOBJ.position(); onTouchEvent: public boolean onTouchEvent(MotionEvent me) { if (me.getAction() == MotionEvent.ACTION_DOWN) { xpos = me.getX(); ypos = me.getY(); return true; } if (me.getAction() == MotionEvent.ACTION_UP) { xpos = -1; ypos = -1; touchTurn = 0; touchTurnUp = 0; return true; } if (me.getAction() == MotionEvent.ACTION_MOVE) { float xd = me.getX() - xpos; float yd = me.getY() - ypos; xpos = me.getX(); ypos = me.getY(); touchTurn = xd / -200f; touchTurnUp = yd / -200f; return true; } try { Thread.sleep(15); } catch (Exception e) { } return super.onTouchEvent(me); } UpdateScene: if (touchTurn != 0) { scene.camera().position.rotateY(touchTurn); touchTurn = 0; } if (touchTurnUp != 0) { scene.camera().position.rotateX(touchTurnUp); touchTurnUp = 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload