我用 rajawali 框架加载了一个对象......我想用相机一起旋转它......
这是我的代码:
public Renderer(Context context) {
super(context);
setFrameRate(60);
this.context = context;
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mAccVals = new Number3d();
}
public void initScene() {
DirectionalLight light = new DirectionalLight(0, 0, 1);
light.setPower(4);
mCamera = new Camera();
LoaderOBJ objParser = new LoaderOBJ(mContext.getResources(), mTextureManager, R.raw.ship_obj);
try {
objParser.parse();
} catch (ParsingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mObjectGroup = objParser.getParsedObject();
mObjectGroup.setPosition(0, 0, 0);
mCamera.setPosition(10, 50, 150);
addCamera(mCamera);
addChild(mObjectGroup);
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}
public void onDrawFrame(GL10 glUnused) {
super.onDrawFrame(glUnused);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
return;
mAccVals.x = (float) (-event.values[1] * FILTERING_FACTOR + mAccVals.x
* (1.0 - FILTERING_FACTOR));
mAccVals.y = (float) (event.values[0] * FILTERING_FACTOR + mAccVals.y
* (1.0 - FILTERING_FACTOR));
double posx = mAccVals.x * .2f;
double posy = mAccVals.y * .2f;
mCamera.setPosition(posx, posy, 0);
double currentPosx = mCamera.getPosition().x;
double currentPosy = mCamera.getPosition().y;
mCamera.setLookAt(currentPosx, currentPosy, 0);
}
这是我的课:
public class Renderer extends RajawaliRenderer implements SensorEventListener {
}
我收到号码posx
并posy
输入onSensorChanged
但mCamera.setPosition(posx, posy, 0)
不起作用!