Changes to camera methods

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
cjpaver
Posts: 8
Joined: Mon Feb 07, 2011 8:43 pm

Changes to camera methods

Post by cjpaver »

I need to change the way that a camera created with ICameraSceneNode rotates.

I've been able to successfully overwrite the methods in the IEventReceiver from the other posts and tutorials to create my own event handler.

I run into a problem when I try to do this the same way for the camera.

If I:

Code: Select all

class DiffCamera : public ICameraSceneNode
{
public:
	void setRotation(const core::vector3df& rotation)
	{
		//something different
	}
};
it will only call setRotation if I am creating an instance of DiffCamera. However, I cannot seem to create an instance of DiffCamera unless I overwrite the ISceneManager with something like:

Code: Select all

class DiffSceneManager : public ISceneManager
{
public:
		virtual DiffCamera* addCameraSceneNode(ISceneNode* parent = 0,
		const core::vector3df& position = core::vector3df(0,0,0),
		const core::vector3df& lookat = core::vector3df(0,0,100),
		s32 id=-1, bool makeActive=true) = 0;
};
since the standard ISceneManager will not add a camera of my type. But if I do that, then the IrrlichtDevice won't return my scene manager type unless I override that one as well.

Creating a variation of IrrlichtDevice isn't working. What can I do so that I may change that single function to do my own thing?
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Just use the new keyword to create an instance of your camera
cjpaver
Posts: 8
Joined: Mon Feb 07, 2011 8:43 pm

Post by cjpaver »

I'm sorry, I don't understand how that helps. Using the new keyword creates an instance of a camera that Irrlicht still doesn't know how to use.

Code: Select all

int main()
{
		IrrlichtDevice *device;

		device = createDevice( EDT_DIRECT3D9, dimension2d<u32>(800, 600), 16, false, false, false, &receiver);

		IVideoDriver* driver = device->getVideoDriver();
		ISceneManager* smgr = device->getSceneManager();

		IGUIEnvironment* env = device->getGUIEnvironment();

		ICameraSceneNode * camera = smgr->addCameraSceneNode(0,core::vector3df(0,10,0), core::vector3df(0,6,15));
		camera->bindTargetAndRotation(true);

        while(device->run())
        {
			driver->beginScene(true, true, Color(255,100,101,140));
			smgr->drawAll();
			env->drawAll();
			driver->endScene();
			env->clear();
        }
		device->drop();

        return 0;
}
Using what was in my original post, how would I use the new operator in this snippet to replace the ICameraSceneNode so that DiffCamera can be used with the existing ISceneManager smgr?
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

The scene manager doesn't have to create the node to be able to use it in your application, it'd be pretty stupid if you had to modify the engine each time you wanted to add a custom scene node

Why are you intent on replacing the existing camera creation method anyway?
cjpaver
Posts: 8
Joined: Mon Feb 07, 2011 8:43 pm

Post by cjpaver »

I want to overwrite it for an assignment to write my own calculations. I know they exist already in Irrlicht, but it's about the coding experience, I guess.

So, in tutorial 003 I found:

Code: Select all

class DiffCamera : public scene::ICameraSceneNode
{
public:
	DiffCamera (scene::ICameraSceneNode* parent, scene::ISceneManager* mgr, s32 id,
			const core::vector3df& position = core::vector3df(0,0,0),
			const core::vector3df& rotation = core::vector3df(0,0,0),
			const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f))
			: ICameraSceneNode(parent, mgr, id, position, rotation, scale) {}

	void setRotation(const core::vector3df& rotation)
	{
		std::cout << "This is a test" << std::endl;
	}
};
and attempted to alter it to fit my needs. Like I said before, I am trying to overwrite just that setRotation() so I want to use the rest of it. It doesn't give me any syntax errors before running with this ^ section, but inside main() I have another problem.

Code: Select all

int main()
{
...
...
		DiffCamera * kcam = new DiffCamera(smgr->getRootSceneNode(), smgr, 666, camPos, camRot, CamSca);
...
...
}
as it was done in the tutorial, gives an error of "object of abstract class type DiffCamera is not allowed." Is this because of the way something is declared in ICameraSceneNode or something that I can simply fix with what I have already done? What's got to get done differently to get new DiffCamera(...) to work?
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

that means you didn't define some pure virtual functions. since you are deriving from the camera scene node.

i think this is covered in oop tuts.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

ChaiRuiPeng wrote:i think this is covered in oop tuts.
Even when you preface that with some explanation, this sounds like:

"[to a 9th grader] No, you did it wrong. I think it's covered in 3rd grade."

A good way to end a conversation, tough. :lol:
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, this half-complete implementation is even not enough for any scene node, but especially not for a camera scene node. You must implement all pure virtual methods of the interfaces you use.
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

agamemnus wrote:
ChaiRuiPeng wrote:i think this is covered in oop tuts.
Even when you preface that with some explanation, this sounds like:

"[to a 9th grader] No, you did it wrong. I think it's covered in 3rd grade."

A good way to end a conversation, tough. :lol:
what? anyways, the error you are getting should tell you that you are not implementing all the pure virtual methods of the inherited classes. That is if you read some c++ tutorials maybe!!?! We're frank, but we are giving you the solution, no need to get upset.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
cjpaver
Posts: 8
Joined: Mon Feb 07, 2011 8:43 pm

Post by cjpaver »

hybrid wrote:Well, this half-complete implementation is even not enough for any scene node, but especially not for a camera scene node. You must implement all pure virtual methods of the interfaces you use.
Thanks, I didn't know that I had to do all of the pure virtuals. I thought I only had to alter the one I wanted done differently, and the others would carry over as normal. This was the explanation I was looking for.
ChaiRuiPeng wrote:what? anyways, the error you are getting should tell you that you are not implementing all the pure virtual methods of the inherited classes. That is if you read some c++ tutorials maybe!!?! We're frank, but we are giving you the solution, no need to get upset.
He didn't ask the question you helped to answer, I did. Some things come from experience, and that may be where you got this understanding. Anything I've ever seen hasn't stated that each virtual had to be implemented. Unfortunately, I didn't know enough to know what I didn't know and needed to look up.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

cjpaver wrote:
hybrid wrote:Well, this half-complete implementation is even not enough for any scene node, but especially not for a camera scene node. You must implement all pure virtual methods of the interfaces you use.
Thanks, I didn't know that I had to do all of the pure virtuals. I thought I only had to alter the one I wanted done differently, and the others would carry over as normal. This was the explanation I was looking for.
They don't carry over simply because theres nothing to carry over, they are pure virtual without any 'function body'.
Working on game: Marrbles (Currently stopped).
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Post by aanderse »

I think what the original poster is missing is that ICameraSceneNode is simply an interface, not an implementation.

The ICameraSceneNode class does almost nothing... it is the CCameraSceneNode class (a PRIVATE implementation which you do not have access to) that you are interested in copying+modifying.
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

Using what was in my original post, how would I use the new operator in this snippet to replace the ICameraSceneNode so that DiffCamera can be used with the existing ISceneManager smgr?
Also, after putting the copied/modified CCameraSceneNode in a place where your compiler can find it, to use it you'll need to addSceneNode() and setActiveCamera() after creating the MyCameraSceneNode with new.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Post Reply