OpenGl Devloperの新機能です。OpenGlの3Dモデルをレンダリングしたいので、min3dフレームワークライブラリを選択してください。ズームをパンする方法min3dの機能を縮小する
私は女性の3dmodelを持っていると私は、スケールなしのいずれかのソリューションを彼女の顔をズームアウトしたい、のように私はmin3d
でズームアウトでカメラのズームのように、私のモデル用ズームアウト機能にパン、ズームしたいですオブジェクト?
OpenGl Devloperの新機能です。OpenGlの3Dモデルをレンダリングしたいので、min3dフレームワークライブラリを選択してください。ズームをパンする方法min3dの機能を縮小する
私は女性の3dmodelを持っていると私は、スケールなしのいずれかのソリューションを彼女の顔をズームアウトしたい、のように私はmin3d
でズームアウトでカメラのズームのように、私のモデル用ズームアウト機能にパン、ズームしたいですオブジェクト?
カメラの位置を変更する必要があります。パンをしたいので、いくつかの追加のパラメータcenter
とdistance
を定義することをお勧めします。
ズームジェスチャーを使用している場合は、距離がdistance *= scale
(または実装によってはdistance = originalDistance*scale
)にズームスケールを適用するだけです。
center
を距離center.x += (newXOnScreen-oldXOnScreen)*speedFactor
とcenter.y += (newYOnScreen-oldYOnScreen)*speedFactor
に移動するだけで簡単に移動できます。速度係数はここでは一定であるかもしれませんが(それでちょっと遊んでください)、ズームの倍率で乗算するのが最も良いかもしれませんので、非常に近いと中心が動かなくなります。
これで2つのパラメータをカメラに適用する必要がありました。あなたは(0,0,0)
でモデル位置を持っていると仮定すると:
scene.camera.position = {center.x, center.y, center.z-distance}
scene.camera.target = {center.x, center.y, center.z}
scene.camera.up = {0, 1, 0}
こんにちは、newYonscreenとnewXonScreenを取得する方法とoriganldistanceを取得する方法。 on touchイベント –
あなたは通常、(newXOnScreen、newYOnScreen)あなたが(oldXOnScreen、oldYOnScreen)に保存する指の位置を取得するドラッグイベントを追跡します。次のイベントでは、2を減算して、実際に指が動いてこれをパンに適用しました。元の距離は、ユーザーがズームを開始する前に使用している距離です。最初に適用する任意の値で、モデルの最適なビューを表示します。 –
Number3d number3d =新しいNumber3d(event.getX(0)、event.getY(0)、scene.camera()。position.z-0.5f); scene.camera()。position = number3d; scene.camera()。target = number3d; scene.camera()。upAxis.y = 1; :私はこのコードを書いていて、私のモデルは表示されません –
次のコードスニペットは、私のために働きました。これは完全なコードではありませんが、私はちょうどピンチズームと3dオブジェクトのドラッグをmin3dフレームワークで行う部分を追加しました。私はmin3Dをinitalizingためhereとアプリケーション
//import statements
public class threedviewActivity extends RendererActivity {
private Object3dContainer Object3D;
private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f,mLastTouchX,mLastTouchY,mPosX,mPosY;
private int mActivePointerId = INVALID_POINTER_ID,flag;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mScaleDetector = new ScaleGestureDetector(threedviewActivity.this, new ScaleListener());
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
// Let the ScaleGestureDetector inspect all events.
mScaleDetector.onTouchEvent(ev);
final int action = MotionEventCompat.getActionMasked(ev);
switch (action) {
case MotionEvent.ACTION_DOWN: {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float y = MotionEventCompat.getY(ev, pointerIndex);
mLastTouchX = x;
mLastTouchY = y;
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
updateScene();
break;
}
case MotionEvent.ACTION_MOVE: {
// Find the index of the active pointer and fetch its position
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float y = MotionEventCompat.getY(ev, pointerIndex);
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;
mPosX += dx;
mPosY += dy;
// Remember this touch position for the next move event
mLastTouchX = x;
mLastTouchY = y;
flag = 1;
updateScene();
break;
}
case MotionEvent.ACTION_UP: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_POINTER_UP: {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
break;
}
}
return true;
}
@Override
public void initScene()
{
//this is where you initialize your 3d object. Check below for links for tutorials on that.
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
// Don't let the object get too small or too large.
mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f));
Object3D.scale().x = Object3D.scale().y = Object3D.scale().z = mScaleFactor*1.5f;
flag = 0;
updateScene();
return true;
}
}
@Override
public void updateScene()
{
if(flag == 1)
{
Object3D.position().x = mPosX/100;
Object3D.position().y = -mPosY/100;
}
}
}
に従ってください、あなたはルックアット行列へのアクセス権を持っていますか?通常は、目の位置を受け入れるlookAtプロシージャを適用するビュー行列を使用します。中心は、視線がベクトルを見上げる方向です。少しの計算で、ズーム、パン、回転の機能を簡単に適用することができます。 –
私はイベントに触れたいので、これで私はこのコードを書いています。このコードはGLU.gluLookAt(Shared.renderer()。gl()、 scene.camera()。position.x、scene.camera()です。 position.y、scene.camera()。position.z、 scene.camera()。target.x + 1、scene.camera()。target.y + 1、scene.camera()。target.z + 1 、 scene.camera()。upAxis.x、scene.camera()。upAxis.y、scene.camera()。upAxis.z);あなたはコードを与えることができます..? –