rotate camera node != rotate FOV

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SuperElectric
Posts: 19
Joined: Fri May 13, 2005 7:20 am
Location: New York, NY

rotate camera node != rotate FOV

Post by SuperElectric »

I just discovered that rotating a camera node doesn't change its field of vision. Is there a way to get it to behave in the expected manner? What I'm trying right now is to write a subclass of ICameraSceneNode that checks its absolute rotation during OnPostRender and changes its FOV accordingly using setTarget, but if I'm missing some easier way to do it, perhaps without having to extend the API.

Thanks,
-- Matt
SuperElectric
Posts: 19
Joined: Fri May 13, 2005 7:20 am
Location: New York, NY

one solution

Post by SuperElectric »

So, here's my subclass of CCameraSceneNode that rotates its point of view when you rotate the node.

MountableCamera.h:

Code: Select all

#include "irrlicht.h"
#include "CCameraSceneNode.h"

// Like the standard ICameraSceneNode, except when this node rotates, 
// so does its view direction. Hence, it's "mountable".
class MountableCamera: public irr::scene::CCameraSceneNode {
	
private:
	
	irr::core::vector3df initialTarget_;
		
public:

	MountableCamera(	irr::scene::ISceneNode* parent, 
						irr::scene::ISceneManager* mgr, 
						irr::s32 id, 
						const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0), 
						const irr::core::vector3df& lookat = irr::core::vector3df(0, 0, 100) )
	:CCameraSceneNode(parent, mgr, id, position, lookat)
	{
		initialTarget_ = getTarget();	
	}
						
	virtual void OnPostRender( irr::u32 currTimeMs );	
	
	virtual void setTarget( const irr::core::vector3df& target );

};

MountableCamera.cpp:

Code: Select all


#include "MountableCamera.h"
#include <iostream>
#include <cmath>

using namespace std;
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;


void 
MountableCamera::setTarget( const core::vector3df& target ){
	CCameraSceneNode::setTarget(target);
	initialTarget_ = getTarget();	
}

void
MountableCamera::OnPostRender( u32 currTimeMs ){
	matrix4 tx = getAbsoluteTransformation();
	vector3df target = initialTarget_;

	tx.transformVect(target);
	CCameraSceneNode::setTarget(target);
	CCameraSceneNode::OnPostRender();
}

Post Reply