This is my class file which use to load 3d model . i am using jpct lib for loading 3d object . i want to apply pinch zoom to GLSurfaceView can any one tell me how to do ? i didnt found any tut/code for zoom ..
public class Model extends Activity {
// Used to handle pause and resume...
private static Model master = null;
ProgressDialog pDialog;
private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
static World world = null;
// private RGBColor back = new RGBColor(0, 50, 100);
Connection_Detector cd = new Connection_Detector(this);
private float touchTurn = 0;
private float touchTurnUp = 0;
private float xpos = -1;
private float ypos = -1;
private Object3D cube = null;
private int fps = 0;
private Light sun = null;
Camera mCamera;
SurfaceView mPreview;
String company, model, pid, reponse;
TextView name;
RelativeLayout call, info, email, tryit;
private AsyncTask<Void, Void, Void> details;
boolean IsInternetPresent;
TextureManager tm;
SharedPreferences atPrefs;
ProgressBar pb;
ScaleGestureDetector mScaleDetector;
protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
if (master != null) {
copy(master);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.model);
Bundle bundle = getIntent().getExtras();
ActionBar ab = getActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f9564b")));
ab.setDisplayHomeAsUpEnabled(true);
atPrefs = PreferenceManager.getDefaultSharedPreferences(Model.this);
mGLView = (GLSurfaceView) findViewById(R.id.glsurfaceview);
mGLView.setZOrderOnTop(true);
mScaleDetector = new ScaleGestureDetector(getApplicationContext(),
new ScaleListener());
// set bg
mGLView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mGLView.getHolder().setFormat(PixelFormat.RGBA_8888);
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
pb = (ProgressBar) findViewById(R.id.progressBar1);
// pb.setVisibility(View.VISIBLE);
name = (TextView) findViewById(R.id.name);
call = (RelativeLayout) findViewById(R.id.callrel);
info = (RelativeLayout) findViewById(R.id.inforel);
email = (RelativeLayout) findViewById(R.id.emailrel);
tryit = (RelativeLayout) findViewById(R.id.tryel);
name.setText(company + " " + model);
call.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
email.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
info.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
tryit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
}
// public Model() {
// // TODO Auto-generated constructor stub
// mScaleDetector = new ScaleGestureDetector(getApplicationContext(),
// new ScaleListener());
@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}
@Override
protected void onStop() {
super.onStop();
}
private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
float mScaleFactor = detector.getScaleFactor();
// Don't let the object get too small or too large.
mScaleFactor = Math.max(1.0f, Math.min(mScaleFactor, 10.0f));
// pass it to your renderer
renderer.setZoom(mScaleFactor);
Log.d("SCALE", Float.toString(mScaleFactor));
return true;
}
}
public boolean onTouchEvent(MotionEvent me) {
mScaleDetector.onTouchEvent(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 / -100f;
// touchTurnUp = yd / -100f;
// return true;
// }
try {
Thread.sleep(15);
} catch (Exception e) {
}
return super.onTouchEvent(me);
}
protected boolean isFullscreenOpaque() {
return true;
}
class MyRenderer implements GLSurfaceView.Renderer {
private long time = System.currentTimeMillis();
public MyRenderer() {
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(gl, w, h);
if (master == null) {
world = new World();
world.setAmbientLight(20, 20, 20);
sun = new Light(world);
sun.setIntensity(250, 250, 250);
File sdRoot = Environment.getExternalStorageDirectory();
File imgFile = new File(sdRoot + "/folder/1.obj");
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
File imgFile = new File(sdRoot + "/folder/1.jpg");
cube = Object3D.mergeAll(Loader.loadOBJ(inputStream, null, 5f));
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile
.getAbsolutePath());
tm = TextureManager.getInstance();
Texture test = new Texture(myBitmap);
tm.addTexture("text", test);
// load text
TextureInfo ti = new TextureInfo(TextureManager.getInstance()
.getTextureID("text"));
cube.setTexture(ti);
cube.build();
cube.strip();
myBitmap.recycle();
world.addObject(cube);
//
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
//
// pb.setVisibility(View.GONE);
//
// }
// });
SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();
if (master == null) {
Logger.log("Saving master Activity!");
master = Model.this;
}
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
cube.rotateY(touchTurn);
touchTurn = 0;
}
if (touchTurnUp != 0) {
cube.rotateX(touchTurnUp);
touchTurnUp = 0;
}
// fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}
public void setZoom(float scale) {
cube.setScale(scale);
}
}
@Override
public void onBackPressed() {
Intent back = new Intent(getApplicationContext(), HomeScreen.class);
startActivity(back);
// reset 3d model data and text
master = null;
tm.removeTexture("text");
finish();
super.onBackPressed();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.opengl.GLSurfaceView
android:id="@+id/glsurfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</android.opengl.GLSurfaceView>
use scale listener on ImageTarget.java
get the float value in ImageTargetsRenderer.java and set it to the object
thats it you can zoom in and zoom out object .. hope thats wat you want ..