How do you call cameras following the player from behind?

Problems building or running the engine, queries about how to use features etc.
Post Reply
lucky7456969
Gremlin
Posts: 156
Joined: Tue Sep 18, 2012 3:43 am

How do you call cameras following the player from behind?

Post by lucky7456969 »

I am wondering if I hard code the up vector as 0,1,0
and position is behind the characters.
And I will cross produce a right vector
With all these vectors, how do I build a Camera out of them in Ogre3D?
I understand that it uses position and lookat and fov etc
how do I "convert" the various vectors into pos, lookat and fov?
Thanks
Jack
lucky7456969
Gremlin
Posts: 156
Joined: Tue Sep 18, 2012 3:43 am

Re: How do you call cameras following the player from behind

Post by lucky7456969 »

humm, this is no good

Code: Select all

Ogre::Vector3 newCamPos = WorkerPos + Ogre::Vector3(0.0f, 5.0f, 5.0f);
lookAt = WorkerPos-newCamPos;
mCamera->setPosition(newCamPos);
mCamera->lookAt(lookAt);
It's looking at the opposite direction.
tried to exchange the order of subtraction.... no good..
I even negate the lookAt vector to no avail
Any quick fix for me please? :)
Jack

update:
Whoops.. lookAt target is the position itself not a directional vector.
But I am getting serious object occlusion....

Update2:
How can I make the Camera watch the agents back automatically?

Code: Select all

#include "DollyCam.h"
#include <Ogre.h>

DollyCamera::DollyCamera(Ogre::SceneManager *sceneMgr,
		Ogre::Viewport* viewport, Ogre::RenderWindow* rw, 
		OgreBites::SdkCameraMan* cammgr) :
		mSceneMgr(sceneMgr), mViewport(viewport), mWindow(rw),
		mCameraMan(cammgr)
{
	 
	

}

void DollyCamera::Create(Ogre::String name) {
	mCamera = mSceneMgr->createCamera(name.c_str());	 
	 
}

 

void DollyCamera::update(float dt, Ogre::Vector3 newPos) {
	Ogre::Vector3 newCamPos = newPos + Ogre::Vector3(0.0f, 5.0f, 5.0f);	 
	mCamera->setPosition(newCamPos);
	mCamera->lookAt(newPos);
	mWindow->removeViewport(0);
	Ogre::Radian R = Ogre::Math::ATan(Ogre::Math::Tan(Ogre::Degree((float)45/2))/mCamera->getAspectRatio())*2;
	mCamera->setFOVy(R);	 
	mViewport = mWindow->addViewport( mCamera );

	if (mCameraMan) {
		delete mCameraMan;
		mCameraMan = NULL;
	}
	mCameraMan = new OgreBites::SdkCameraMan(mCamera);
	
	

}
Thanks
Jack
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: How do you call cameras following the player from behind

Post by amartin »

I think what you are looking for is the third person camera
Post Reply