123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- package app.mar.activities;
- import android.support.v4.view.MotionEventCompat;
- import android.os.Bundle;
- import android.view.MotionEvent;
- import android.view.View;
- import android.widget.Button;
- import android.widget.FrameLayout;
- import android.widget.TextView;
- import app.mar.utils.FontChangeCrawler;
- import app.mar.game.Resource;
- import app.mar.utils.geometry.Point;
- import min3d.core.Object3d;
- import min3d.core.RendererActivity;
- import min3d.vos.CameraVo;
- import min3d.vos.Light;
- import min3d.vos.LightType;
- public class ModelViewerActivity extends RendererActivity implements View.OnTouchListener {
- private Resource mResource;
- private Button mInfo;
- private TextView mTitle;
- private FrameLayout mFrameLayout;
- protected float mPreviousX;
- protected float mPreviousY;
- protected float mPreviousDist=0;
- protected CameraVo mCamera = new CameraVo();
- protected boolean mIsZooming = false;
- protected boolean mIsMoving = false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_model_viewer);
- mInfo = (Button) findViewById(R.id.info);
- mFrameLayout = (FrameLayout) findViewById(R.id.frame_viewer);
- mTitle = (TextView) findViewById(R.id.title);
- if(getIntent().hasExtra("resource"))
- {
- mResource = (Resource) getIntent().getSerializableExtra("resource");
- if(mResource!=null) setTitle(mResource.getTitle());
- mFrameLayout.addView(_glSurfaceView);
- mTitle.setText(mResource.getTitle());
- }else
- {
- mTitle.setText("Error: Res not found");
- }
- FontChangeCrawler.setFont(this);
- }
- public void onClickInfo(View v)
- {
- }
- public void initScene()
- {
- scene.backgroundColor().setAll(0x00000000);
- Light myLight = new Light();
- myLight.position.setZ(0);
- myLight.position.setY(0);
- myLight.type(LightType.POSITIONAL);
- scene.lights().add(myLight);
- Object3d oo = mResource.get3DModel(this);
- oo.position().z=mResource.getPosition().z;
- oo.position().y=mResource.getPosition().y;
- oo.position().x=mResource.getPosition().x;
- oo.position().z-=20;
- mCamera.frustum.zFar(0.1f);
- mCamera.frustum.zFar(1000);
- scene.addChild(mResource.get3DModel(this));
- }
- @Override
- public void updateScene() {
- }
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- float x = motionEvent.getX();
- float y = motionEvent.getY();
- final int action = motionEvent.getAction()%256;
- int index = MotionEventCompat.getActionIndex(motionEvent);
- if (motionEvent.getPointerCount() > 1) {
- switch (action) {
- case MotionEvent.ACTION_MOVE:
- {
- if(!mIsZooming) break;
- Point a = new Point(motionEvent.getX(0), motionEvent.getY(0));
- Point b = new Point(motionEvent.getX(1), motionEvent.getY(1));
- double d = a.getDistanceWith(b);
- double delta = d - mPreviousDist;
- mCamera.position.z+=delta/2;
- mPreviousDist = (float)a.getDistanceWith(b);
- scene.camera(mCamera);
- break;
- }
- case MotionEvent.ACTION_POINTER_DOWN:
- case MotionEvent.ACTION_DOWN: {
- Point a = new Point(motionEvent.getX(0), motionEvent.getY(0));
- Point b = new Point(motionEvent.getX(1), motionEvent.getY(1));
- mPreviousDist = (float)a.getDistanceWith(b);
- mIsZooming=true;
- break;
- }
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_POINTER_UP:
- case MotionEvent.ACTION_CANCEL:
- mIsZooming=false;
- mIsMoving=false;
- break;
- }
- }
- else {
- mIsZooming=false;
- switch (motionEvent.getAction()) {
- case MotionEvent.ACTION_MOVE:
- {
- if(!mIsMoving) break;
- float dx = x - mPreviousX;
- float dy = y - mPreviousY;
- Object3d oo = mResource.get3DModel(this);
- oo.rotation().y += dx / 3;
- oo.rotation().x += dy / 3;
- _glSurfaceView.requestRender();
- break;
- }
- case MotionEvent.ACTION_DOWN:
- mIsMoving=true;
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- mIsMoving=false;
- mIsZooming=false;
- break;
- }
- mPreviousX = x;
- mPreviousY = y;
- }
- return true;
- }
- }
|