mirror of https://github.com/axmolengine/axmol.git
Merge pull request #459 from minggo/iss643
[android] swap axes according to the orientation
This commit is contained in:
commit
5e5151b41e
|
@ -1,10 +1,13 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,11 +40,27 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
|
||||
return;
|
||||
}
|
||||
|
||||
onSensorChanged(event.values[0], event.values[1], event.values[2], event.timestamp);
|
||||
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE){
|
||||
float tmp = x;
|
||||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,11 +40,27 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
|
||||
return;
|
||||
}
|
||||
|
||||
onSensorChanged(event.values[0], event.values[1], event.values[2], event.timestamp);
|
||||
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE){
|
||||
float tmp = x;
|
||||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,11 +40,27 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
|
||||
return;
|
||||
}
|
||||
|
||||
onSensorChanged(event.values[0], event.values[1], event.values[2], event.timestamp);
|
||||
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE){
|
||||
float tmp = x;
|
||||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -322,7 +322,9 @@ void RenderTextureSave::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
|||
m_pBrush->setRotation(rand() % 360);
|
||||
float r = (float)(rand() % 50 / 50.f) + 0.25f;
|
||||
m_pBrush->setScale(r);
|
||||
m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));
|
||||
/*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
|
||||
// Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
|
||||
m_pBrush->setColor(ccc3(rand() % 127 + 128, 255, 255));
|
||||
// Call visit to draw the brush, don't call draw..
|
||||
m_pBrush->visit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue