我有一些使用android 3dmin库的代码。我想要实现的是在触摸手指点绘制我的3dObject。基本功能已经完成,但我有透视投影的问题。我的3dObject被绘制到远离中心的距离。这是我的代码:
private float X = 0;
private float Y = 0;
private int width;
private int height;
private void calculateCoordinates(float x, float y)
{
Log.d("touch", "x: "+Float.toString(((x-width/2)/5*0.01f)) +" " +
" y: "+Float.toString(y));
objModel.position().x=((x-width/2)/5*0.01f);
objModel.position().y=-((y-height/2)/5*0.01f);
\\convert 2d toch point to Number3d 3dObject point. 5 is a objModel.position().z,
\\0.01 is a constant. With setting scale at 0.09f and this constant at 0.03f i
\\achived desired effect, but why?
}
@Override
public void initScene() {
width= getResources().getDisplayMetrics().widthPixels;
height = getResources().getDisplayMetrics().heightPixels;
scene.lights().add(new Light());
scene.lights().add(new Light());
IParser parser = Parser.createParser(Parser.Type.OBJ, getResources(),
"com.example.min3dtest:raw/face_cube_obj", true);
parser.parse();
scene.lightingEnabled(true);
objModel = parser.getParsedObject();
objModel.scale().x = objModel.scale().y = objModel.scale().z = 0.03f;
objModel.colorMaterialEnabled(true);
objModel.texturesEnabled(true);
scene.addChild(objModel);
Log.d(TAG, "camera z = "+Float.toString(scene.camera().position.z));
this.glSurfaceView().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int a = event.getAction();
switch (a) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:{
X = event.getX();
Y = event.getY();
calculateCoordinates(X,Y);
Log.d("sdfs", "down");
}
break;
}
return true;
}
});
}
@Override
public void updateScene() {
objModel.rotation().x++;
objModel.rotation().y++;
objModel.rotation().z++;
}
}
它在某种程度上取决于我认为的规模。但我无法弄清楚为什么并找到好的方程式。
谢谢!