Setting the center of mass(COM)

suryaatvellore

20-06-2012 10:48:23

In the GranTurismo demo the car seems to quite unstable..while turning it tumbles to the turning side..So is there any function in OgreODE by which i can set the COM of the car??

dermont

20-06-2012 14:52:30

In the GranTurismo demo the car seems to quite unstable..while turning it tumbles to the turning side..So is there any function in OgreODE by which i can set the COM of the car??

Look at the Media\subaru.ogreode config file and the OgreOdeDotLoader.cpp - Loader::parseVehicle.

suryaatvellore

22-06-2012 08:32:42

@dermont I looked at the damping and the friction variables for all the wheels but doesnt seem to be working.Does the solution have anything to do with the turn angle of the car as in a normal car?
whre are the keypresses for forward mvmnt and turning handled?I have also gone through the granturism.cpp file but couldnt find the code for the movement and turning..the only code is find is

_vehicle->setInputs(mKeyboard->isKeyDown(OIS::KC_J),
mKeyboard->isKeyDown(OIS::KC_L),
mKeyboard->isKeyDown(OIS::KC_I),
mKeyboard->isKeyDown(OIS::KC_K));
_vehicle->update(time);

where is the update function?
I have also overviewed the prefa vehicle file and couldnt gt to anything.
(I am really expecting code where the X-axis values are incremented)

dermont

22-06-2012 09:06:00


whre are the keypresses for forward mvmnt and turning handled?I have also gone through the granturism.cpp file but couldnt find the code for the movement and turning..the only code is find is

_vehicle->setInputs(mKeyboard->isKeyDown(OIS::KC_J),
mKeyboard->isKeyDown(OIS::KC_L),
mKeyboard->isKeyDown(OIS::KC_I),
mKeyboard->isKeyDown(OIS::KC_K));
_vehicle->update(time);

where is the update function?

Vehicle::setInputs in OgreOdeVehicle.cpp

@dermont I looked at the damping and the friction variables for all the wheels but doesnt seem to be working.Does the solution have anything to do with the turn angle of the car as in a normal car?


Take a look at the OgreOdeVehicle api and the setSwayForce* methods. I think that is what these methods are for though I'm not sure what the correct settings are.

Alternatively, if you can't get this working start off with applying a simple force to the wheels when turning, then work backwards using the setSwayForce* methods to create your own setSwayForce* methods,e.g:

_vehicle->getWheel(0)->getBody()->addForce( Ogre::Vector3(0,-1,0) * 5.0 );
..
The vehicle demo with OgreOde is only an example, it's pretty much up to you to implement your own using the demo as a template. You should look at other implementations for ideas/info:

http://www.asawicki.info/Mirror/Car%20P ... Games.html
http://www.mindcontrol.org/~hplus/carworld.html

suryaatvellore

22-06-2012 10:19:13

could you also tell me if the world in the GranTurism demo has been loaded via a mesh file or has it been created implicitly in the source code?if the latter then how have the textures been applied?and where can i find the PowerAtRPM,getDesiredRPM functions?

dermont

22-06-2012 11:13:08

could you also tell me if the world in the GranTurism demo has been loaded via a mesh file or has it been created implicitly in the source code?
I've already told you look at EntityInformer part of the code. PLEASE run through and read the ogre tutorials on the wiki so you understand the basics.


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->setUserAny(Ogre::Any(_track));

and where can i find the PowerAtRPM,getDesiredRPM functions?
Surprisingly enough in the same file I asked you to look at - OgreOdeVehicle.cpp. Does your IDE not have a search facility?

Real Vehicle::Engine::getDesiredRPM()
Real Vehicle::Engine::getPowerAtRPM(Real rpm)


if the latter then how have the textures been applied?
The scooby_body.mesh contains a reference to the material for each submesh. In this case the material is called scooby_body.material. If you want to see a readable representation of the mesh:

>>OgreXMLConverter scooby_body.mesh (creates scooby_body.xml)


You can do the same for the racingcircuit.mesh.

suryaatvellore

22-06-2012 12:21:43

mCamera->setPosition(Vector3(125,-14,8));
this line is responsible for changing how we look at the car.but this position is set with respect to some point.and if i want to create two cameras where do i mention the presence of two scene managers.

dermont

22-06-2012 17:42:20

mCamera->setPosition(Vector3(125,-14,8));
this line is responsible for changing how we look at the car.but this position is set with respect to some point.and if i want to create two cameras where do i mention the presence of two scene managers.


Look at GranTurismOgreFrameListener::frameStarted mCamera->lookAt(.....

http://www.ogre3d.org/tikiwiki/tiki-ind ... Tutorial+2

Why do you wan't to create two scene managers? Why more than one camera unless you are doing Render To Texture/ have multiple viewports or something similar. You should do a search on the main forum.

Here is the doxygen file for generating the apis. There isn't much in the way of
comments from the header files but it may help you in navigating through the classes.
https://docs.google.com/open?id=0B9FUpA ... 3pOMzZnTGM

Create doc directory under your ogreode directory and copy OgreOde.cfg to that dir.
>> cd doc
>> doxygen OgreOde.cfg
You can load the api via your browser from doc/html/index.html

suryaatvellore

23-06-2012 06:15:34

I need multiple cameras because i need to enable the user to view the car from the driver seat as well as from the back just as in a normal racing game.

suryaatvellore

23-06-2012 09:52:41

I tried creating a new camera by this code



void Vehicle::changeCamera()
{
mCamera = mSceneMgr->createCamera("PlayerCam1");
mCamera->setPosition(Vector3(125,-14,8));
mCamera->lookAt(mCamera->getPosition() + Ogre::Vector3(0,0,1));
mCamera->setNearClipDistance( 1 );
mCamera->setFarClipDistance( 1000 );

}



if(mKeyBoard->isKeyDown(OIS::KC_Z))
{
changeCamera();

}



first of all it says not declared in the scope error and i have included the prototype in the .h file of GT.second even if it works wouldnt th enew camera mask the older one.I want different viewports.

dermont

23-06-2012 10:07:45

I tried creating a new camera by this code



void Vehicle::changeCamera()
{
mCamera = mSceneMgr->createCamera("PlayerCam1");
mCamera->setPosition(Vector3(125,-14,8));
mCamera->lookAt(mCamera->getPosition() + Ogre::Vector3(0,0,1));
mCamera->setNearClipDistance( 1 );
mCamera->setFarClipDistance( 1000 );

}



if(mKeyBoard->isKeyDown(OIS::KC_Z))
{
changeCamera();

}



first of all it says not declared in the scope error and i have included the prototype in the .h file of GT.second even if it works wouldnt th enew camera mask the older one.I want different viewports.


You are double posting the same topics on the main forum as here, you shouldn't be doing that.

I've already pointed you to the code where the camera orientation/position is set/manipulated. You do not need two cameras for what you are doing just a bit of math. For example to switch camera to front of the vehicle.


// Thanks to Ahmed!
static Ogre::Real followFactor = 0.2;
static Ogre::Real camHeight = 2.0;
static Ogre::Real camDistance = 7.0;
static Ogre::Real camLookAhead = 8.0;

....

if ((mKeyboard->isKeyDown(OIS::KC_2))) {
if (mTimeUntilNextToggle <= 0) {
camDistance = 7.0;
mTimeUntilNextToggle = 0.5;
} }

if ((mKeyboard->isKeyDown(OIS::KC_1))) {
if (mTimeUntilNextToggle <= 0) {
camDistance = 0.0;
mTimeUntilNextToggle = 0.5;
}}



<edit>
And by the way your scope error I'm guessing is due to the fact it should be.

GranTurismOgreFrameListener::changeCamera()


You should really look at the material on the wiki (Where can I learn how to program in C++?)
http://www.ogre3d.org/tikiwiki/tiki-ind ... ng+Started
</edit>

suryaatvellore

25-06-2012 12:31:21

if(mKeyboard->isKeyDown(OIS::KC_3))
{

mCamera->setPosition(90,30,90);
}
if(mKeyboard->isKeyDown(OIS::KC_4))
{
mCamera->setPosition(80,-10,60);
}

this coding toggles the camera but if i want to make the cameras stay at a particular position then do i need to define seperate cameras?and using similar coding can u still provide me the coding for a driver view..i have tried and although i get the view..the car rushes forward and the view is disturbed(we r back to back view)..could you provide the solution for this?

dermont

26-06-2012 11:26:08

if(mKeyboard->isKeyDown(OIS::KC_3))
{

mCamera->setPosition(90,30,90);
}
if(mKeyboard->isKeyDown(OIS::KC_4))
{
mCamera->setPosition(80,-10,60);
}

this coding toggles the camera but if i want to make the cameras stay at a particular position then do i need to define seperate cameras?and using similar coding can u still provide me the coding for a driver view..i have tried and although i get the view..the car rushes forward and the view is disturbed(we r back to back view)..could you provide the solution for this?


I've already told you where to look for the camera manipulation code in the demo. This is it, see the mCamera->move(...) moves the camera relative to the vehicle, to ensure it follows the vehicle.

Quaternion q = _vehicle->getSceneNode()->getOrientation();
Vector3 toCam = _vehicle->getSceneNode()->getPosition();

toCam.y += camHeight;
toCam.z -= camDistance * q.zAxis().z;
toCam.x -= camDistance * q.zAxis().x;
->-> mCamera->move( (toCam - mCamera->getPosition()) * followFactor );
mCamera->lookAt(_vehicle->getSceneNode()->getPosition() + ((_vehicle->getSceneNode()->getOrientation() * Ogre::Vector3::UNIT_Z) * camLookAhead));



When you set the camera it will also "snap back" to the camera following the vehicle at a certain distance.

As a simpe test to keep the camera at a certain position you can set followFactor to 0.0 and back to 0.2 when you want the current view. If you want something more sophisticated then it's is up to you to implement your own camera tracking/view switching behaviour. I already provide you links that you can look at.

if(mKeyboard->isKeyDown(OIS::KC_4))
{
mCamera->setPosition(80,-10,60);
followFactor=0.0f;
}

suryaatvellore

26-06-2012 11:31:05

Thanks dermont worked it out by introducing a new camera,...thanks a lot for the help...but could you still look at a new problem posted by me..tnks a lot..

dermont

27-06-2012 17:26:53

You asked in a previous correspondence regarding vehicle reverse, not too sure where so I'll post here. It's probably more complex than this but hopefully it will give you some idea where to start.

src/OgreOdeVehicle.cpp

< void Vehicle::Wheel::update(Real power_force,Real desired_rpm,Real brake_force,bool reverse)
---
> void Vehicle::Wheel::update(Real power_force,Real desired_rpm,Real brake_force)
173,177c173
< if (reverse)
< _joint->setParameter(Joint::Parameter_MotorVelocity,-desired_rpm,2);
< else
< _joint->setParameter(Joint::Parameter_MotorVelocity,desired_rpm,2);
<
---
> _joint->setParameter(Joint::Parameter_MotorVelocity,desired_rpm,2);
230,231c226
< _swayForceLimit (0),
< _reverse(false)
---
> _swayForceLimit (0)
352c347
< void Vehicle::setInputs(bool left,bool right,bool throttle,bool brake, bool reverse)
---
> void Vehicle::setInputs(bool left,bool right,bool throttle,bool brake)
354c349
< if (left || right || throttle || reverse)
---
> if (left || right || throttle)
362,364d356
< _reverse = reverse;
< if (_reverse)
< throttle = true;
412d403
<
443c434
< (*i)->update(power, desired_rpm, brake, _reverse);
---
> (*i)->update(power, desired_rpm, brake);



include/OgreOdeVehicle.h

109c109
< void update(Ogre::Real power_force, Ogre::Real desired_rpm, Ogre::Real brake_force,bool reverse=false);
---
> void update(Ogre::Real power_force, Ogre::Real desired_rpm, Ogre::Real brake_force);
161c161
<
---
>
164c164
< void setInputs(bool left, bool right, bool throttle, bool brake, bool reverse);
---
> void setInputs(bool left, bool right, bool throttle, bool brake);
243d242
< bool _reverse;




GranTurismOgre.cpp (h for reverse)
_vehicle->setInputs(mKeyboard->isKeyDown(OIS::KC_J),
mKeyboard->isKeyDown(OIS::KC_L),
mKeyboard->isKeyDown(OIS::KC_I),
mKeyboard->isKeyDown(OIS::KC_K),
mKeyboard->isKeyDown(OIS::KC_H));

SimpleScenes_Buggy.h
vehicle->setInputs(input->isKeyDown(OIS::KC_J),input->isKeyDown(OIS::KC_L),input->isKeyDown(OIS::KC_I),input->isKeyDown(OIS::KC_K),input->isKeyDown(OIS::KC_K));