Final fix to accelerometer input

This commit is contained in:
pelya
2010-07-09 18:50:43 +03:00
parent fa534f2570
commit cad2c8ff2a
4 changed files with 19 additions and 13 deletions

View File

@@ -21,6 +21,7 @@
#include "SDL.h"
#include <stdlib.h>
#include "global.h"
#include "surfaceDB.h"
#include <android/log.h>
using namespace std;
@@ -67,6 +68,8 @@ SdlCompat_AcceleratedSurface *Video::init(){
SDL_ShowCursor(SDL_DISABLE);
__android_log_print(ANDROID_LOG_INFO, "Alien Blaster", "Initializing video done");
empty = surfaceDB.loadSurface(FN_ALIENBLASTER_INTRO);
return screen;
}
@@ -79,8 +82,9 @@ void Video::clearScreen() {
r.y = 0;
r.w = screen->w;
r.h = screen->h;
*/
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0) );
*/
SDL_BlitSurface(empty, NULL, screen, NULL);
}
void Video::toggleFullscreen() {

View File

@@ -32,6 +32,7 @@ class Video {
private:
SdlCompat_AcceleratedSurface *screen;
SdlCompat_AcceleratedSurface *empty;
public:
Video();

View File

@@ -92,18 +92,11 @@ static void updateOrientation ( float accX, float accY, float accZ )
{
// TODO: use accelerometer as joystick, make this configurable
// Currenly it's used as cursor + KP7/KP9 keys
static const float dx = 0.1, dy = 0.1, dz = 0.1;
static const float dx = 0.04, dy = 0.1, dz = 0.1;
static float midX = 0, midY = 0, midZ = 0;
static int pressLeft = 0, pressRight = 0, pressUp = 0, pressDown = 0, pressR = 0, pressL = 0;
static int count = 0;
count++;
if(count > 30)
{
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accel: %-1.3f %-1.3f %-1.3f : %-1.3f %-1.3f %-1.3f", accX, accY, accZ, midX, midY, midZ);
}
if( accX < midX - dx )
{
if( !pressLeft )
@@ -152,7 +145,7 @@ static void updateOrientation ( float accX, float accY, float accZ )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: press up, acc %f mid %f d %f", accY, midY, dy);
pressUp = 1;
SDL_SendKeyboardKey( SDL_PRESSED, SDL_SCANCODE_UP );
SDL_SendKeyboardKey( SDL_PRESSED, SDL_SCANCODE_DOWN );
}
}
else
@@ -161,7 +154,7 @@ static void updateOrientation ( float accX, float accY, float accZ )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: release up, acc %f mid %f d %f", accY, midY, dy);
pressUp = 0;
SDL_SendKeyboardKey( SDL_RELEASED, SDL_SCANCODE_UP );
SDL_SendKeyboardKey( SDL_RELEASED, SDL_SCANCODE_DOWN );
}
}
if( accY < midY - dy*2 )
@@ -173,7 +166,7 @@ static void updateOrientation ( float accX, float accY, float accZ )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: press down, acc %f mid %f d %f", accY, midY, dy);
pressDown = 1;
SDL_SendKeyboardKey( SDL_PRESSED, SDL_SCANCODE_DOWN );
SDL_SendKeyboardKey( SDL_PRESSED, SDL_SCANCODE_UP );
}
}
else
@@ -182,7 +175,7 @@ static void updateOrientation ( float accX, float accY, float accZ )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: release down, acc %f mid %f d %f", accY, midY, dy);
pressDown = 0;
SDL_SendKeyboardKey( SDL_RELEASED, SDL_SCANCODE_DOWN );
SDL_SendKeyboardKey( SDL_RELEASED, SDL_SCANCODE_UP );
}
}
if( accY > midY + dy*2 )
@@ -237,6 +230,12 @@ JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobjec
float normal = sqrt(accPosX*accPosX+accPosY*accPosY+accPosZ*accPosZ);
if(normal <= 0.0000001f)
normal = 1.0f;
static int count = 0;
count++;
if(count > 50)
{
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accel: %-1.3f %-1.3f %-1.3f", accPosX/normal, accPosY/normal, accPosZ/normal);
}
updateOrientation (accPosX/normal, accPosY/normal, 0.0f);
}

View File

@@ -48,12 +48,14 @@ class AccelerometerReader implements SensorListener {
v[2] = values[2];
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
/*
if( Globals.HorizontalOrientation )
{
v[0] = values[2];
v[1] = values[1];
v[2] = values[0];
}
*/
nativeAccelerometer(v[0], v[1], v[2]);
}
if (sensor == SensorManager.SENSOR_ORIENTATION) {