lewap
17-01-2007 12:35:36
Hello,
I'm using OgreOde_Prefab::Vehicle, with changed vehicle model.
I have a problem with driving a vehicle.
In demos when you press 'forward' button and than release it the car still goes further ( loosing speed ).
In my case when I do the same all wheels stuck and the car stops instantly.
What is more the break doesn't work at all.
I use setInputs funciton. Input works ok.
// bool right, left, forward, back;
m_World->m_CyCab->_vehicle->setInputs(right,left,forward,back);
Thank you for any help.
tuan kuranes
17-01-2007 12:54:06
And if you use your vehicle in OgreOde Demos ?
Dirso
17-01-2007 15:17:31
I'm having a few problems with vehicle class too. It was working fine with the old OgreOde version, but now that I updated it setinputs is not works as it should/did.
It takes a few seconds to start moving, unless I press right or left and the car looks like is over ice tracks and doesn't respond any good.
tuan kuranes
18-01-2007 12:41:53
Make sure it's not related to stepper use by trying other stepper or other stepper parameters.
Dirso
18-01-2007 19:34:51
The automatic stepper was making my car to hit the ground in slow motion.
void PlayState::enter()
{
// this line is dangerous
// remove it when the game is running
_canMove = false;
exitGame = false;
mRoot = Root::getSingletonPtr();
//init
_track = 0;
mSceneMgr = mRoot->createSceneManager(ST_GENERIC);
// Create the camera for player one
mCamera[0] = mSceneMgr->createCamera("PlayerCam");
mCamera[0]->setPosition(Vector3(125,-14,8));
mCamera[0]->lookAt(mCamera[0]->getPosition() + Vector3(0,0,1));
mCamera[0]->setNearClipDistance( 1 );
mCamera[0]->setFarClipDistance( 1000 );
// should I create the camera for the second player?
if(_idHumanPlayers[1] >= 0)
{
// Create the camera for player one
mCamera[1] = mSceneMgr->createCamera("PlayerCam2");
mCamera[1]->setPosition(Vector3(125 - DIF_SIDE_GRID,-14,8));
mCamera[1]->lookAt(mCamera[0]->getPosition() + Vector3(0,0,1));
mCamera[1]->setNearClipDistance( 1 );
mCamera[1]->setFarClipDistance( 1000 );
//adcionar os dois viewports
mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera[0], 0, 0.0, 0.0, 1.0, 0.5);
mViewportP2 = mRoot->getAutoCreatedWindow()->addViewport(mCamera[1], 1, 0.0, 0.5, 1.0, 0.5);
mCamera[0]->setAspectRatio((Real)mViewport->getActualWidth()/(Real)mViewport->getActualHeight());
mCamera[1]->setAspectRatio((Real)mViewportP2->getActualWidth()/(Real)mViewportP2->getActualHeight());
}
else
{
mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera[0]);
mCamera[0]->setAspectRatio((Real)mViewport->getActualWidth()/(Real)mViewport->getActualHeight());
mCamera[1] = 0;
}
// loading screen
mLoadingBar.start(mRoot->getAutoCreatedWindow(), 1, 1, 0.75);
mRoot->getAutoCreatedWindow()->update();
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
mSceneMgr->setSkyBox(true,_skyFile);
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// NB I could attach the light to a SceneNode if I wanted it to move automatically with
// other objects, but I don't
l->setPosition(20,800,50);
l->setSpecularColour(1,0.9,0);
l->setCastShadows(true);
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
mSceneMgr->setShadowColour(ColourValue(0.5,0.5,0.5));
_world = new OgreOde::World(mSceneMgr);
_world->setGravity(Vector3(0,-9.80665,0));
_world->setCFM(10e-5);
_world->setERP(0.8);
_world->setAutoSleep(true);
_world->setContactCorrectionVelocity(1.0);
// Create something that will step the world automatically
_world->setCollisionListener(this);
_ck.LoadFromFile(IATRACKSFOLDER + _trackFile + ".checkpoint");
SceneNode *track_node = mSceneMgr->getRootSceneNode()->createChildSceneNode("track");
Entity *track_mesh = mSceneMgr->createEntity("track","racingcircuit.mesh");
track_node->attachObject(track_mesh);
OgreOde::EntityInformer ei(track_mesh);
_track = ei.createStaticTriangleMesh(_world, _world->getDefaultSpace());
track_mesh->setUserObject (_track);
dotOgreOdeLoader = new OgreOde_Loader::DotLoader(_world);
const int _stepper_mode_choice = 2;
const int _stepper_choice = 3;
const Ogre::Real time_scale = Ogre::Real(1.0);
const Ogre::Real max_frame_time = Ogre::Real(1.0 / 4);
const Ogre::Real frame_rate = Ogre::Real(1.0 / 60);
StepHandler::StepModeType stepModeType;
switch(_stepper_mode_choice)
{
case 0: stepModeType = StepHandler::BasicStep; break;
case 1: stepModeType = StepHandler::FastStep; break;
case 2: stepModeType = StepHandler::QuickStep; break;
default: stepModeType = StepHandler::QuickStep; break;
}
_stepper = new OgreOde::ForwardFixedStepHandler(
_world, StepHandler::QuickStep, _time_step, max_frame_time, time_scale);
_stepper->setAutomatic( StepHandler::AutoMode_NotAutomatic, mRoot );
//_stepper->setAutomatic(OgreOde::StepHandler::AutoMode_PostFrame, mRoot);
//_stepper->setAutomatic(OgreOde::Stepper::AutoMode_PreFrame, root);
Root::getSingleton().setFrameSmoothingPeriod(5.0f);
// create all cars
// Move the vehicle
Vector3 v_pos = mCamera[0]->getPosition() + (mCamera[0]->getDirection() * 15.0);
Vector3 v_pos2 = v_pos;
v_pos2.x -= DIF_SIDE_GRID;
v_pos2.z -= DIF_1_2_GRID;
Vector3 v_pos3;
// start the vehicle
int i1 = (_idHumanPlayers[0] > NON_HUMAN)?_idHumanPlayers[0]:0;
int i2 = _idHumanPlayers[1];
_nCurrCam = 0;
mRoot->getAutoCreatedWindow()->update();
for ( int i = 0; i < _numOfCars; i++)
{
v_pos3 = (i%2)?v_pos2:v_pos;
_vehiclePlayer[i] = new VehiclePlayer();
v_pos3.y = -15.015;
_vehiclePlayer[i]->InitVehicle(v_pos3, _carNames[i] + ".ogreode",
_carNames[i],_vpt[i], (i == i1)?mCamera[0]:(i == i2)?mCamera[1]:0,
_ck.getCheckPointCount(), i, dotOgreOdeLoader, _carPlayers[i]);
if(i%2)
{
v_pos2.z -= DIF_PARS_GRID;
v_pos.z -= DIF_PARS_GRID;
}
// start its variables
#ifdef _USE_LOG_PISTA
if(i == i1)
{
_log = new CLogPista(_vehiclePlayer[i], _trackFile, "Dummy");
}
#endif // _USE_LOG_PISTA
mRoot->getAutoCreatedWindow()->update();
}
// set 2 human controls
if(_idHumanPlayers[1] > NON_HUMAN)
{
_vehiclePlayer[_idHumanPlayers[1]]->SetKeyCmd(Ogre::KC_NUMPAD8, Ogre::KC_NUMPAD2,
Ogre::KC_NUMPAD4, Ogre::KC_NUMPAD6);
}
_mainOverlay = new COverlayUSCRacing(_numOfLaps, _numOfCars);
_semafOverlay = new COverlayUSCSemaforo();
// start all overlays
_mainOverlay->UpdateOverlayInt(COverlayUSCRacing::UOT_Lap, 1);
// mostra as posicoes
for (int i = 0; i < _numOfCars; i++)
{
if ( i >= NUM_OF_PLAYER_LABELS ) break;
_mainOverlay->showPlayer(i, _vehiclePlayer[i]->getPlayerName(), i == _idHumanPlayers[0]);
}
mRoot->getAutoCreatedWindow()->update();
// create cegui
createGUI();
makeGUI();
_listOfPositions = new TPlayerPos[_numOfCars];
clearPosList();
#ifdef _USE_LOG_PISTA
_CurrFrame = 0;
#endif
mLoadingBar.finish();
// render it!
mRoot->startRendering();
}
bool PlayState::frameStarted(GameManager* game, const FrameEvent& evt)
{
Ogre::InputReader* id = InputManager::getSingletonPtr()->getInputDevice();
id->capture();
_stepper->step( time );
_world->synchronise();
if(!_stepper->isPaused())
{
// update all cars
int nHumans = 0;
Real _time_temp = CChronometer_PP::getSingletonPtr()->GetTime_Sec();
for (int i = 0; i < _numOfCars; i++)
{
if(_vehiclePlayer[i]->getVPT() == VehiclePlayer::VPT_Human)
{
if ((nHumans < game->getNumJoySticks()) && game->g_joys[nHumans]
&& (_idHumanPlayers[nHumans] == i))
{
game->g_joys[i]->capture();
const OIS::JoyStickState &joy = game->g_joys[i]->getJoyStickState();
Real steering = 0.0, rBreak = 0.0, rThrottle = 0.0;
int abx = joy.mAxes[0].abX, aby = joy.mAxes[0].abY;
if (abx < -2500)
{
//steering = -1.0;
if (abx < -16000)
{
steering = -1.0;
}
else
{
steering = -0.5;
}
}
else if (abx > 2500)
{
if (abx > 16000)
{
steering = 1.0;
}
else
{
steering = 0.5;
}
}
if (aby < -2500)
{
rThrottle = 1.0;
}
else if (aby > 2500)
{
rBreak = -1.0;
}
if(_canMove)
{
_vehiclePlayer[i]->ProcessKeyboard(steering, rBreak, rThrottle, time);
}
}
else
{
if(_canMove)
{
_vehiclePlayer[i]->ProcessKeyboard(id, time);
}
}
nHumans++;
}
_vehiclePlayer[i]->UpdateCameraPos();
Dirso
18-01-2007 19:41:57
That's the way I try to move the car. It was working fine with the old version.
void VehiclePlayer::ProcessKeyboard( Real steering, Real rBreak, Real rThrottle, unsigned long lTimeElapsed )
{
_ASSERT(m_bInit);
Real sqrSpeed = _vehicle->getBody()->getLinearVelocity().squaredLength();
if( rBreak && ( sqrSpeed <= 0.1 || !mDrivingForward ) && (!rThrottle) )
{
mDrivingForward = false;
rThrottle = -1.0;
_vehicle->setInputs( steering, rThrottle, 0.0);
} else
{
if (rBreak)
{
rThrottle = -1.0;
}
else if (rThrottle)
{
rThrottle = 1.0;
}
else
{
rThrottle = 0.0;
}
_vehicle->setInputs( steering, rThrottle);
mDrivingForward = true;
}
_vehicle->update(lTimeElapsed);
}
void VehiclePlayer::ProcessKeyboard( Ogre::InputReader *mID, unsigned long lTimeElapsed )
{
Real steering, rThrottle = mID->isKeyDown(m_cThrottle)?1.0:0.0,
rBreak = mID->isKeyDown(m_cBrake)?1.0:0.0;
if( mID->isKeyDown(m_cRight) )
{
steering = 1.0;
} else if( mID->isKeyDown(m_cLeft) )
{
steering = -1.0;
} else
{
steering = 0.0;
}
ProcessKeyboard(steering, rBreak, rThrottle, lTimeElapsed);
}
tuan kuranes
19-01-2007 12:39:06
And if you use your vehicle in OgreOde Demos ?
Dirso
20-01-2007 13:26:28
Actually my vehicle is the one from the ogreodedemos and now I'm using again the old version and it works great.
tuan kuranes
22-01-2007 12:10:16
If you need help to port to the new version, you'll have to be way more specific about what the problem is, difference between demo code and yours (best is to reproduce your bug in demo code), etc.