fixed some bug:1.setDeviceOrientation, chipmunkDemo glOrthof

This commit is contained in:
dumganhar 2011-11-07 18:18:10 +08:00
parent 3b48a69d01
commit 0d6ea61b76
14 changed files with 84 additions and 85 deletions

View File

@ -48,6 +48,25 @@ static unsigned int _Hash(const char *key)
return (hash); return (hash);
} }
static string fullPathFromRelativePath(const char *pszRelativePath)
{
string strRet="";
int len = strlen(pszRelativePath);
if (pszRelativePath == NULL || len <= 0)
return NULL;
if (len > 1 && pszRelativePath[0] == '/')
{
strRet = pszRelativePath;
}
else
{
strRet = s_strResourcePath;
strRet += pszRelativePath;
}
return strRet;
}
class MyPlayerEventListener : class MyPlayerEventListener :
public IPlayerEventListener public IPlayerEventListener
{ {
@ -189,7 +208,7 @@ static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath, bool bLoo
} }
} }
string strFilePath = s_strResourcePath+pszFilePath; string strFilePath = fullPathFromRelativePath(pszFilePath);
// OpenFile must use synchronous param, for after that it will playing. // OpenFile must use synchronous param, for after that it will playing.
r = pPlayer->OpenFile(strFilePath.c_str(), false); r = pPlayer->OpenFile(strFilePath.c_str(), false);
if (IsFailed(r)) if (IsFailed(r))
@ -386,7 +405,7 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/*
long long curTick, oldTick; long long curTick, oldTick;
SystemTime::GetTicks(oldTick); SystemTime::GetTicks(oldTick);
result r = E_FAILURE; result r = E_FAILURE;
string strFilePath = s_strResourcePath+pszFilePath; string strFilePath = fullPathFromRelativePath(pszFilePath);
unsigned int nRet = _Hash(strFilePath.c_str()); unsigned int nRet = _Hash(strFilePath.c_str());
AppLog("play effect (%s)", pszFilePath); AppLog("play effect (%s)", pszFilePath);
preloadEffect(pszFilePath); preloadEffect(pszFilePath);
@ -452,7 +471,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{ {
BREAK_IF(! pszFilePath); BREAK_IF(! pszFilePath);
string strFilePath = s_strResourcePath+pszFilePath; string strFilePath = fullPathFromRelativePath(pszFilePath);
nRet = _Hash(strFilePath.c_str()); nRet = _Hash(strFilePath.c_str());
@ -482,7 +501,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
{ {
string strFilePath = s_strResourcePath+pszFilePath; string strFilePath = fullPathFromRelativePath(pszFilePath);
unsigned int nSoundId = _Hash(strFilePath.c_str()); unsigned int nSoundId = _Hash(strFilePath.c_str());
CCAudioOut*& pPlayer = s_List[nSoundId]; CCAudioOut*& pPlayer = s_List[nSoundId];
pPlayer->Reset(); pPlayer->Reset();

View File

@ -74,6 +74,7 @@ bool AppDelegate::initInstance() {
CCEGLView * pMainWnd = new CCEGLView(); CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320)); CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));
pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);
CCFileUtils::setResourcePath("/Res/"); CCFileUtils::setResourcePath("/Res/");
#endif // CC_PLATFORM_BADA #endif // CC_PLATFORM_BADA
@ -94,9 +95,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
// turn on display FPS // turn on display FPS
pDirector->setDisplayFPS(true); pDirector->setDisplayFPS(true);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this

View File

@ -24,7 +24,9 @@ THE SOFTWARE.
#include "CCAccelerometer_bada.h" #include "CCAccelerometer_bada.h"
#include "ccMacros.h" #include "ccMacros.h"
#include "CCEGLView_bada.h"
using namespace Osp::Ui;
using namespace Osp::Uix; using namespace Osp::Uix;
NS_CC_BEGIN; NS_CC_BEGIN;
@ -75,7 +77,18 @@ void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorDa
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Y, y); sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Y, y);
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Z, z); sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Z, z);
// only consider land postion, to be continued. /*
* Because the axes are not swapped when the device's screen orientation changes.
* So we should swap it here.
*/
Orientation orientation = CCEGLView::sharedOpenGLView().GetOrientation();
if (orientation == ORIENTATION_LANDSCAPE || orientation == ORIENTATION_LANDSCAPE_REVERSE)
{
float tmp = x;
x = -y;
y = tmp;
}
CCAcceleration AccValue; CCAcceleration AccValue;
AccValue.x = -x; AccValue.x = -x;
AccValue.y = -y; AccValue.y = -y;

View File

@ -27,13 +27,7 @@ CCApplication::~CCApplication()
CCApplication::Orientation CCApplication::setOrientation(CCApplication::Orientation orientation) CCApplication::Orientation CCApplication::setOrientation(CCApplication::Orientation orientation)
{ {
// swap width and height return orientation;
CCEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
if (pView)
{
return (Orientation)pView->setDeviceOrientation(orientation);
}
return (Orientation)CCDirector::sharedDirector()->getDeviceOrientation();
} }
CCRect CCApplication::statusBarFrame(CCRect * rect) CCRect CCApplication::statusBarFrame(CCRect * rect)

View File

@ -183,7 +183,6 @@ CCEGLView::CCEGLView()
, m_fScreenScaleFactor(1.0) , m_fScreenScaleFactor(1.0)
, m_bCaptured(false) , m_bCaptured(false)
, m_pEGL(NULL) , m_pEGL(NULL)
, m_nowOrientation(ORIENTATION_PORTRAIT)
{ {
m_pTouch = new CCTouch; m_pTouch = new CCTouch;
m_pSet = new CCSet; m_pSet = new CCSet;
@ -261,19 +260,11 @@ void CCEGLView::setContentScaleFactor(float contentScaleFactor)
m_fScreenScaleFactor = contentScaleFactor; m_fScreenScaleFactor = contentScaleFactor;
} }
static int badaOrientation[4] = { int CCEGLView::setDeviceOrientation(Orientation eOritation)
ORIENTATION_PORTRAIT,
ORIENTATION_PORTRAIT_REVERSE,
ORIENTATION_LANDSCAPE,
ORIENTATION_LANDSCAPE_REVERSE
};
int CCEGLView::setDeviceOrientation(int eOritation)
{ {
m_nowOrientation = (Orientation)badaOrientation[eOritation]; SetOrientation(eOritation);
SetOrientation(m_nowOrientation);
if (m_nowOrientation == ORIENTATION_PORTRAIT || m_nowOrientation == ORIENTATION_PORTRAIT_REVERSE) if (eOritation == ORIENTATION_PORTRAIT || eOritation == ORIENTATION_PORTRAIT_REVERSE)
{ {
int width = MIN(m_sSizeInPixel.width, m_sSizeInPixel.height); int width = MIN(m_sSizeInPixel.width, m_sSizeInPixel.height);
m_sSizeInPixel.height = MAX(m_sSizeInPixel.width, m_sSizeInPixel.height); m_sSizeInPixel.height = MAX(m_sSizeInPixel.width, m_sSizeInPixel.height);
@ -295,7 +286,6 @@ int CCEGLView::setDeviceOrientation(int eOritation)
} }
return m_eInitOrientation; return m_eInitOrientation;
// return eOritation;
} }
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h) void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)

View File

@ -57,7 +57,7 @@ public:
bool canSetContentScaleFactor(); bool canSetContentScaleFactor();
void setContentScaleFactor(float contentScaleFactor); void setContentScaleFactor(float contentScaleFactor);
int setDeviceOrientation(int eOritation); int setDeviceOrientation(Osp::Ui::Orientation eOritation);
void setViewPortInPoints(float x, float y, float w, float h); void setViewPortInPoints(float x, float y, float w, float h);
void setScissorInPoints(float x, float y, float w, float h); void setScissorInPoints(float x, float y, float w, float h);

View File

@ -30,7 +30,7 @@ using namespace std;
NS_CC_BEGIN; NS_CC_BEGIN;
// record the resource path // record the resource path
static string s_strResourcePath = "/Res/"; static string s_strResourcePath = "";
void CCFileUtils::setResourcePath(const char* pszResourcePath) void CCFileUtils::setResourcePath(const char* pszResourcePath)
{ {
@ -40,19 +40,15 @@ void CCFileUtils::setResourcePath(const char* pszResourcePath)
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{ {
int len = strlen(pszRelativePath);
if (pszRelativePath == NULL || len <= 0)
return NULL;
CCString * pRet = new CCString(); CCString * pRet = new CCString();
pRet->autorelease(); pRet->autorelease();
if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':') if (len > 1 && pszRelativePath[0] == '/')
|| pszRelativePath[0] == '/')
{ {
pRet->m_sString = pszRelativePath; pRet->m_sString = pszRelativePath;
} }
else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/')
{
char szDriver[3] = {s_strResourcePath[0], s_strResourcePath[1], 0};
pRet->m_sString = szDriver;
pRet->m_sString += pszRelativePath;
}
else else
{ {
pRet->m_sString = s_strResourcePath; pRet->m_sString = s_strResourcePath;

View File

@ -79,6 +79,7 @@ bool AppDelegate::initInstance()
CCEGLView * pMainWnd = new CCEGLView(); CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320)); CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));
pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);
CCFileUtils::setResourcePath("/Res/"); CCFileUtils::setResourcePath("/Res/");
#endif // CC_PLATFORM_BADA #endif // CC_PLATFORM_BADA
@ -93,9 +94,7 @@ bool AppDelegate::applicationDidFinishLaunching()
// initialize director // initialize director
CCDirector *pDirector = CCDirector::sharedDirector(); CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
// pDirector->enableRetinaDisplay(true); // pDirector->enableRetinaDisplay(true);

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# set params # set params
ANDROID_NDK_ROOT=/home/laschweinski/android/android-ndk-r5/ ANDROID_NDK_ROOT=/cygdrive/e/android/android-ndk-r5
COCOS2DX_ROOT=/home/laschweinski/git/cocos2d-x COCOS2DX_ROOT=/cygdrive/f/Project/dumganhar/cocos2d-x
TESTS_ROOT=$COCOS2DX_ROOT/tests/test.android TESTS_ROOT=$COCOS2DX_ROOT/tests/test.android
# make sure assets is exist # make sure assets is exist

View File

@ -1,11 +1,2 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target. # Project target.
target=android-7 target=android-8

View File

@ -1,26 +1,26 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY. /* AUTO-GENERATED FILE. DO NOT MODIFY.
* *
* This class was automatically generated by the * This class was automatically generated by the
* aapt tool from the resource data it found. It * aapt tool from the resource data it found. It
* should not be modified by hand. * should not be modified by hand.
*/ */
package org.cocos2dx.tests; package org.cocos2dx.tests;
public final class R { public final class R {
public static final class attr { public static final class attr {
} }
public static final class drawable { public static final class drawable {
public static final int icon=0x7f020000; public static final int icon=0x7f020000;
} }
public static final class id { public static final class id {
public static final int test_demo_gl_surfaceview=0x7f050001; public static final int test_demo_gl_surfaceview=0x7f050001;
public static final int textField=0x7f050000; public static final int textField=0x7f050000;
} }
public static final class layout { public static final class layout {
public static final int test_demo=0x7f030000; public static final int test_demo=0x7f030000;
} }
public static final class string { public static final class string {
public static final int app_name=0x7f040000; public static final int app_name=0x7f040000;
} }
} }

View File

@ -57,7 +57,7 @@ void AccelerometerTest::didAccelerate(CCAcceleration* pAccelerationValue)
// } // }
// //
// m_fLastTime = fNow; // m_fLastTime = fNow;
CCLog("acc x = %f, y=%f, z=%f", pAccelerationValue->x, pAccelerationValue->y, pAccelerationValue->z);
CCDirector* pDir = CCDirector::sharedDirector(); CCDirector* pDir = CCDirector::sharedDirector();
CCSize winSize = pDir->getWinSize(); CCSize winSize = pDir->getWinSize();

View File

@ -486,7 +486,7 @@ void ChipmunkTestLayer::onEnter()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE || CC_TARGET_PLATFORM == CC_PLATFORM_BADA) #if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
// portraint // portraint
//glOrthof(-320/factor, 320/factor, -480/factor, 480/factor, -1.0f, 1.0f); //glOrthof(-320/factor, 320/factor, -480/factor, 480/factor, -1.0f, 1.0f);
// landscape // landscape

View File

@ -9,7 +9,6 @@ CCLayer* restartDirectorTestCase();
static int sceneIdx=-1; static int sceneIdx=-1;
static ccDeviceOrientation s_currentOrientation = CCDeviceOrientationPortrait; static ccDeviceOrientation s_currentOrientation = CCDeviceOrientationPortrait;
static ccDeviceOrientation s_oldOrientation = CCDeviceOrientationPortrait;
CCLayer* createTestCaseLayer(int index) CCLayer* createTestCaseLayer(int index)
{ {
@ -216,13 +215,12 @@ void DirectorTestScene::runThisTest()
s_currentOrientation = CCDeviceOrientationPortrait; s_currentOrientation = CCDeviceOrientationPortrait;
CCLayer* pLayer = nextDirectorTestCase(); CCLayer* pLayer = nextDirectorTestCase();
addChild(pLayer); addChild(pLayer);
s_oldOrientation = CCDirector::sharedDirector()->getDeviceOrientation();
CCLog("s_oldOri = %d", s_oldOrientation);
CCDirector::sharedDirector()->replaceScene(this); CCDirector::sharedDirector()->replaceScene(this);
} }
void DirectorTestScene::MainMenuCallback(CCObject* pSender) void DirectorTestScene::MainMenuCallback(CCObject* pSender)
{ {
CCDirector::sharedDirector()->setDeviceOrientation(s_oldOrientation); CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationPortrait);
TestScene::MainMenuCallback(pSender); TestScene::MainMenuCallback(pSender);
} }