我想旋转从 min3d 中的 .obj 文件解析的对象。我需要使用从传感器获得的旋转矩阵。我知道如何在纯 OpenGL 中执行此操作,但我不知道该使用什么(可能是 min3d.core.Renderer?)以及如何在 min3d 中使用。
我喜欢 min3d,它可以很好地解析 .obj 文件,所以我真的不想放弃它并使用纯 openGL。我知道我可以使用 rotate() 方法,但它使用欧拉角,我需要使用旋转矩阵。这是代码:
public class HurleyLoading extends RendererActivity implements SensorEventListener{
private Object3dContainer hurleyModel;
private SensorManager sensorManager;
private Sensor sensorAcc;
private Sensor sensorMagnetic;
private float[] accelData = new float[3];
private float[] magnetData = new float[3];
private final float[] rotationMatrix = new float[16];
float[] orientation = new float[3];
@Override
public void onCreate(Bundle b){
super.onCreate(b);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
sensorAcc = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorMagnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
}
public void onResume()
{
super.onResume();
sensorManager.registerListener(this, sensorAcc, SensorManager.SENSOR_DELAY_GAME);
sensorManager.registerListener(this, sensorMagnetic, SensorManager.SENSOR_DELAY_GAME);
}
public void onStart()
{
super.onStart();
sensorManager.registerListener(this, sensorAcc, SensorManager.SENSOR_DELAY_GAME);
sensorManager.registerListener(this, sensorMagnetic, SensorManager.SENSOR_DELAY_GAME);
//this.onResume();
}
public void onPause()
{
super.onPause();
sensorManager.unregisterListener(this);
}
@Override
public void initScene() {
scene.lights().add(new Light());
scene.lights().add(new Light());
scene.lights().add(new Light());
scene.lights().add(new Light());
scene.lights().add(new Light());
scene.lights().add(new Light());
scene.lights().add(new Light());
IParser parser = Parser.createParser(Parser.Type.OBJ,
getResources(), "ie.tyndall.hurleyopengl:raw/hurley_obj", true);
parser.parse();
hurleyModel = parser.getParsedObject();
hurleyModel.scale().x = hurleyModel.scale().y = hurleyModel.scale().z = 1.4f;
hurleyModel.position().y = -1.8f;
hurleyModel.position().x = .4f;
scene.addChild(hurleyModel);
}
@Override
public void updateScene() {
/**some rotation code can go here but rotation() method has to use
* eulers angles (X/Y/Z euler rotation of object, using Euler angles.
* Units should be in degrees, to match OpenGL usage)which is no use for me
* as i need to use rotation matrix
**/
}
//@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
loadSensorData(event);
SensorManager.getRotationMatrix(rotationMatrix, null, accelData,
magnetData);
}
private void loadSensorData(SensorEvent event) {
final int type = event.sensor.getType();
if (type == Sensor.TYPE_ACCELEROMETER) {
accelData = event.values.clone();
}
if (type == Sensor.TYPE_MAGNETIC_FIELD) {
magnetData = event.values.clone();
}
}
}