abdfairul / min3d2

Automatically exported from code.google.com/p/min3d
0 stars 0 forks source link

Use onTouchEvent #97

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi:

  I am new in writting Android, min3D helps me success loading .obj file. But now I want to use touchevent, I noticed that previous issue(ex.70 and 83) have discuss about it, but the ways they use seems different with the example I found in opengl ES (ex. rotate cube), please tell me what's wrong~~ thanks 

=======================================
package com.min3d_objloader;

import android.os.Bundle;
import android.view.MotionEvent;
import min3d.core.Object3dContainer;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import min3d.vos.Light;

public class Obj3DView extends RendererActivity {

private Object3dContainer faceObject3D;
private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
private float mPreviousX;
private float mPreviousY;
float yAngle=0;
float zAngle=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
}

@Override
public void initScene() {

    scene.lights().add(new Light());
    Light myLight = new Light();
    myLight.position.setZ(-100);
    scene.lights().add(myLight);

    IParser myParser = Parser.createParser(Parser.Type.OBJ, getResources(), "com.min3d_objloader:raw/face_obj",true);
    myParser.parse();

    faceObject3D = myParser.getParsedObject();
    faceObject3D.position().x = faceObject3D.position().y = faceObject3D.position().z = 0;
    faceObject3D.scale().x = faceObject3D.scale().y = faceObject3D.scale().z = 0.009f;
    scene.addChild(faceObject3D);

}

@Override 
public boolean onTouchEvent(MotionEvent e){
    float x = e.getX();
    float y = e.getY();
    switch (e.getAction()) {
    case MotionEvent.ACTION_MOVE:
        float dy = y - mPreviousY;
        float dx = x - mPreviousX;
        yAngle += dx * TOUCH_SCALE_FACTOR;
        zAngle += dy * TOUCH_SCALE_FACTOR;
    }
    mPreviousY = y;
    mPreviousX = x;
    return true;
}

}

Original issue reported on code.google.com by chenlire...@gmail.com on 10 Apr 2013 at 3:37

GoogleCodeExporter commented 9 years ago
Hello dude I solve that question chek:

@Override
    public boolean onTouchEvent(MotionEvent event){ 

        if (event.getAction() == MotionEvent.ACTION_DOWN)
        {

            touchedX = event.getX();
            touchedY = event.getY();

        } else if (event.getAction() == MotionEvent.ACTION_MOVE)
        {
            objModel.rotation().z -= (touchedX - event.getX())/2f;
            objModel.rotation().x -= (touchedY - event.getY())/2f;

            try {

                float ok=spacing(event);                
                planePosition += (event.getY() - touchedY) * 0.01f;

                if(planePosition <= maxScal){
                objModel.scale().x = objModel.scale().y = objModel.scale().z = planePosition;
                }else{
                    objModel.scale().x = objModel.scale().y = objModel.scale().z = 1f;
                }

                if(planePosition >= minScal){
                objModel.scale().x = objModel.scale().y = objModel.scale().z = planePosition;
                }else{                  
                    System.out.println("Se ha salido del rango");
                    objModel.scale().x = objModel.scale().y = objModel.scale().z = .1f;
                }               
            } catch (Exception e) {

            }

            touchedX = event.getX();
            touchedY = event.getY();

        }           
        return true;    
    }

    private float spacing(MotionEvent event) {
           float x = event.getX(0) - event.getX(1);
           float y = event.getY(0) - event.getY(1);
           return FloatMath.sqrt(x * x + y * y);
        }

In other class where you call RenderActivity.java you need to put this code and 
it works for me very well.

Original comment by Armando....@gmail.com on 1 May 2013 at 6:14

GoogleCodeExporter commented 9 years ago
Thanks for u answer!:)But i want to know the value of maxScal and minScal what 
u set.Now I set maxScal =20,minScal =10.

Original comment by anarki1...@gmail.com on 15 May 2013 at 10:01

GoogleCodeExporter commented 9 years ago
Hi , me i need to rotate more object in same time ,but not on its own axis, but 
if you have 3 items to revolve around an axis, for example the middle of those 
three items, can someone help me?

Original comment by braniste...@gmail.com on 25 Feb 2014 at 5:43