Chase Camera for Demo5 Car [HELP]

swakdaddy

22-05-2006 04:47:55

Ok, I've had enough and I'm finally going to ask for help.
I've spent at least 10+ hours fiddling with this today and I'm pretty tired of trying on my own.

QUESTION: How the heck do you get a 3rd person chase/follow camera to follow an ogreNewt object? In particular, the demo5 SimpleVehicle.

I have the camera sitting nicely behind the car but I have tried everything I can find to make it follow.

This guy had the closest solution: http://www.ogre3d.org/phpBB2addons/view ... plevehicle
But, the setOrientation() method does not accept his Vector3 value that his get method returns.

I was hoping to simply use the attachObject() method, but of course that NEVEr works in anything I ever try.

Any suggestions on how to do this?
Some original code or methods would be very refreshing...


* (Please do not send me to Kencho's 3rd person camera tutorial as I have already been there.)
* (Please do not send me to a Quaternion tutorial, as I have been there also.)
* (I've likely been to that forum topic you are thinking of pasting in here as well.)

me_go_fast

22-05-2006 06:59:55

I know how you feel! It took me a little bit to find out how to set up a chase camera. Add the following code to the makeSimpleBox function after box1Node->setScale.

Ogre::SceneNode* camNode = box1node->createChildSceneNode(Ogre::Vector3(box1node->getPosition().x - 2, box1node->getPosition().y + 2, box1node->getPosition().z), Ogre::Quaternion(Ogre::Quaternion(sqrt(0.5),0,-sqrt(0.5),0)));
camNode->attachObject(mCamera);


Before the previous code will work you are going to need to modify the simpleVehicle class constructor to include the camera. (in both the .h and .cpp files)

in the .h file, do this as follows:
Change this:
SimpleVehicle(Ogre::SceneManager* mgr, OgreNewt::World* world, Ogre::Vector3& position, Ogre::Quaternion& orient);
to this:
SimpleVehicle(Ogre::SceneManager* mgr, OgreNewt::World* world, Ogre::Vector3& position, Ogre::Quaternion& orient, Ogre::Camera* cam);

In the .cpp file, do this:
Change this:
SimpleVehicle::SimpleVehicle(Ogre::SceneManager* mgr, OgreNewt::World* world, Ogre::Vector3& position, Ogre::Quaternion& orient) : OgreNewt::Vehicle()
To This:
SimpleVehicle::SimpleVehicle(Ogre::SceneManager* mgr, OgreNewt::World* world, Ogre::Vector3& position, Ogre::Quaternion& orient, Ogre::Camera* cam) : OgreNewt::Vehicle()

Next in the private section of the SimpleVehicle class add the following variable: Ogre::Camera* mCamera;

Now in the .cpp file, add this: mCamera = cam; underneath this: mWorld = world; which is under the constructor. Now just change this:

mCar = new SimpleVehicle( mSceneMgr, m_World, Ogre::Vector3(0,-0.5,0), Ogre::Quaternion(Ogre::Quaternion::IDENTITY) );
To this:
mCar = new SimpleVehicle( mSceneMgr, m_World, Ogre::Vector3(0,-0.5,0), Ogre::Quaternion(Ogre::Quaternion::IDENTITY),mCamera );
That should do it! Take note that this is based off my code and may need a little tweeking to work with the demo. For example, I am not sure which camera you need to send mCamera or msnCam. Other than that, I named the variables for you (or made an attempt to!).

swakdaddy

23-05-2006 03:00:36

WOW! IT WORKS!

That is by far the absolute most detailed and well thought out reply I have ever gotten on ANY forum! Thank you!

I had to comment this line out:
msnCam->attachObject( mCamera ); in the OgreNewtonApplication.cpp file because when it ran, it complained that the camera was already attached to something.

Oh yeah, for others wishing to move the camera behind the car, here you go:

// position camera
msnCam = mSceneMgr->getRootSceneNode()->createChildSceneNode();
//msnCam->attachObject( mCamera );
mCamera->setPosition(0.0, 0.0, 0.0);

//put the camera behind the car and point it at it
msnCam->setPosition(-20.0, 5.0, 0.0);
msnCam->setDirection(20, 0.0, 0.0);


You can actually leave this part out if you follow me_go_fast's directions as msnCam isn't used (also, your dirtballs will be originating from msnCam and not the camera following the car - be warned.)

Too bad I want to replace the car someday with a person, but at least this is a start..maybe I'll just go ahead and make a car game to learn other things (AI, sound, etc.)

Thanks!

syedhs

25-05-2006 01:14:21

If you want to see the alternative camera chasing vehicle, look at LandScapedemo in the OgreOde distribution. The camera chasing is fantastic, very much like there is a rubberband between the camera and the vehicle.

walaber

25-05-2006 03:13:22

there is a similar camera system in Stunt Playground, which I released the source to a few days ago.