我發現的ARToolKit + jpct +安卓的改編:觸摸3D對象ArToolKitJpctBaseLib
https://github.com/plattysoft/ArToolKitJpctBaseLib
我有在屏幕上繪製各種3D對象。 但現在我有這個問題:我需要去觸摸 我看到這個教程:http://www.jpct.net/wiki/index.php?title=Picking 但我的課是不同的東西,是很抽象,簡單,我是一個新手..
這是mainClass,我不發現我的幀緩衝......
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import org.artoolkit.ar.jpct.ArJpctActivity;
import org.artoolkit.ar.jpct.TrackableLight;
import org.artoolkit.ar.jpct.TrackableObject3d;
import java.io.IOException;
import java.util.List;
public class RealidadAumentada extends ArJpctActivity{
private Object3D astronauta = null;
private TrackableObject3d cubo = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
/**
* Use the FrameLayout in this Activity's UI.
*/
@Override
protected FrameLayout supplyFrameLayout() {
return (FrameLayout)this.findViewById(R.id.mainLayout);
}
public void configureWorld(World world) {
world.setAmbientLight(150, 150, 150);
}
protected void populateTrackableObjects(List<TrackableObject3d> list) {
Object3D astronauta2 = null;
try {
cubo = new TrackableObject3d("single;Data/patt.hiro;80", getCube());
//astronauta2 = getAstronauta2());
astronauta = getAstronauta();
astronauta.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
} catch (IOException e) {
e.printStackTrace();
}
TrackableLight light = new TrackableLight();
light.setIntensity(0, 0, 255);
light.setPosition(new SimpleVector(0, 0, 100));
cubo.addLight(light);
cubo.addChild(astronauta);
list.add(cubo);
}
private Object3D getCube() throws IOException {
int scale = 40;
Object3D object3D = Primitives.getCube(scale);
// Cubes in jpct are rotated by 45 degrees when created.
object3D.rotateY((float) Math.PI/4);
object3D.setOrigin(new SimpleVector(0, 0, scale));
return object3D;
}
private Object3D getAstronauta() throws IOException {
int scale = 40;
Object3D[] astronaut = Loader.load3DS(getAssets().open("astronaut1.3ds"), 5);
astronaut[0].setOrigin(new SimpleVector(0, 0, 270));
return astronaut[0];
}
This method doesnt work
public boolean onTouchEvent(MotionEvent me) {
if (me.getAction() == MotionEvent.ACTION_DOWN) {
Toast.makeText(this, cubo.getXAxis().toString()+" "+String.valueOf(me.getX()),2000).show();
// Toast.makeText(this,String.valueOf(cubo.getCenter()),2000).show();
return true;
}
....
}
謝謝 我在努力。但是我發現這很困難,因爲在這些例子中代碼都是在一起的。 – andvazva
你用作起點的例子是70行代碼(包括導入),我沒有看到它應該如何或爲什麼不應該在一起。 該庫的目標是從樣板代碼中抽象出您在Android上設置ARToolkit,您不需要修改它。 – shalafi