Page 1 of 2

Error when trying to set a target for the camera

Posted: Mon Jan 05, 2004 5:57 am
by RayOfAsh
Im trying to make a 3rd Person Camera.

This is the code to make the faerie.

Code: Select all

	// add a animated faeries.

	video::SMaterial material;
	material.Texture1 = driver->getTexture("../../media/faerie2.bmp");
	material.Lighting = true;

	scene::IAnimatedMeshSceneNode* node = 0;
	scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");
	scene::ISceneNode* faerienode = 0;

	if (faerie)
	{
		node = smgr->addAnimatedMeshSceneNode(faerie);
		node->setPosition(core::vector3df(0,30,0));
		node->setMD2Animation(scene::EMAT_RUN);
		node->getMaterial(0) = material;
	}

	material.Texture1 = 0;
	material.Lighting = false;

I have this after i make the faerie.

Code: Select all

	// set camera to faerie
	
	camera->setTarget(faerienode->getPosition);
If i place it before it tells me:

131 C:\irrlicht\projects\fps\main.cpp
`faerienode' undeclared (first use this function)

When i place it after i get:

153 C:\irrlicht\projects\fps\main.cpp
no matching function for call to `irr::scene::ICameraSceneNode::

Posted: Mon Jan 05, 2004 6:18 am
by DarkWhoppy
From what I see... "faerienode" should be "node". (not unless you have another SceneNode named "faerienode" )

Posted: Mon Jan 05, 2004 6:39 am
by RayOfAsh
What? Where?

That bit of code never used to be there, i put it there to try and make it a node (i dont know how to make something a node btw). Even if it isnt there i get the same error.

Re: Error when trying to set a target for the camera

Posted: Mon Jan 05, 2004 7:30 am
by DarkWhoppy

Code: Select all

// add a animated faeries.

	video::SMaterial material;
	material.Texture1 = driver->getTexture("../../media/faerie2.bmp");
	material.Lighting = true;

	scene::IAnimatedMeshSceneNode* node = 0;
	scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");
	scene::IAnimatedMeshSceneNode* faerienode = 0;

	if (faerienode)
	{
		faerienode = smgr->addAnimatedMeshSceneNode(faerie);
		faerienode->setPosition(core::vector3df(0,30,0));
		faerienode->setMD2Animation(scene::EMAT_RUN);
		faerienode->getMaterial(0) = material;
	}

	material.Texture1 = 0;
	material.Lighting = false;

Try using what I have...

Posted: Mon Jan 05, 2004 7:33 am
by DarkWhoppy
Ok i'll explain the "Mesh" to "Node" thing. . .

I've got a node...
ISceneNode* NODE;

Then I've got myself some mesh...
IAnimatedMesh* MESH;

To turn that mesh into a scenenode, i'd do this...

NODE = smgr->addAnimatedMeshSceneNode(MESH);

MESH would be the mesh I want to use and NODE would be what I call it. So from then on, to move/rotate/do anything the MESH just use its node name...

Posted: Mon Jan 05, 2004 1:56 pm
by saigumi
The one other thing to note is that getPosition is a function, so you need to add ().

camera->setTarget(faerienode->getPosition()); instead of camera->setTarget(faerienode->getPosition);

Posted: Mon Jan 05, 2004 9:38 pm
by RayOfAsh
Okay, now i have:

Code: Select all

	// add a animated faeries.

	video::SMaterial material;
	material.Texture1 = driver->getTexture("../../media/faerie2.bmp");
	material.Lighting = true;

	scene::IAnimatedMeshSceneNode* node = 0;
	scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");
	scene::IAnimatedMeshSceneNode* faerienode = 0;

	if (faerie)
	{
		node = smgr->addAnimatedMeshSceneNode(faerie);
		node->setPosition(core::vector3df(0,30,0));
		node->setMD2Animation(scene::EMAT_RUN);
		node->getMaterial(0) = material;
	}

	material.Texture1 = 0;
	material.Lighting = false;

	// set the cameras target to the faerie
	camera->setTarget(faerienode->getPosition());
And it gives me an illegal operation when it trys to load up. The console says:

Irrlicht Engine version 0.4
Loaded mesh:test1.bsp
Needed 1ms to create OctTree SceneNode.(1 nodes, 42 polys)
Needed 0ms to create OctTreeTriangleSelector.(1 nodes, 42 polys)
Loaded mesh:../../media/faerie.md2

Wich meens it crash's while trying to load the mesh.

After reading what Whoopy said i realised that it was just calling it "node", wich isnt good. So then after messing around i changed it to this:

Code: Select all

	// add a animated faeries.

	video::SMaterial material;
	material.Texture1 = driver->getTexture("../../media/faerie2.bmp");
	material.Lighting = true;

	scene::IAnimatedMeshSceneNode* faerienode = 0;
	scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");


	if (faerie)
	{
		faerienode = smgr->addAnimatedMeshSceneNode(faerie);
		faerienode->setPosition(core::vector3df(0,30,0));
		faerienode->setMD2Animation(scene::EMAT_RUN);
		faerienode->getMaterial(0) = material;
	}

	material.Texture1 = 0;
	material.Lighting = false;

	// set the cameras target to the faerie
	camera->setTarget(faerienode->getPosition());
Now it doesnt crash, but it doesnt seem to do anything either.

Posted: Mon Jan 05, 2004 9:49 pm
by RayOfAsh
YES I FIXED IT!

I put:

// set the cameras target to the faerie
camera->setTarget(faerienode->getPosition());

In the draw loop, and now it works fine. Now i need to figure out how to give the faerie collision detection, and get it moveing.


Edit: in case nobody knew, i was trying to make a 3rd person camera. And now its sorta third person, it doesnt lock onto the models back, but i havent set it to do that yet, mostly because i dont know how.

Posted: Tue Jan 06, 2004 11:06 am
by Keanu
The easiest way to make a 3rd person camera is to position the camera relatively to the player, then set the player as the parent of the camera. Next go in the main loop and update target: camera->setTarget(player->getPosition()); This works very well also if you attach a collisionResponseAnimator to the player: when it collides also the camera will stop. :idea:

Posted: Tue Jan 06, 2004 7:54 pm
by RayOfAsh
I knew that, but i dont know how. How do i set it relative to the player? And how do i set a parent?

Thanks in advance.

Posted: Tue Jan 06, 2004 7:59 pm
by Boogle
You can set the parent in the smgr->addSceneNode(...); call, or you can call node->setParent(playerNode);

Once you do this the object's position is its position relative to its parent. eg if you set its position to (-100,0,0) it will always be 100 units to the 'left' of the parent.

Posted: Wed Jan 07, 2004 3:08 am
by RayOfAsh
Cool, it works. But now how do i get the fearie to move. Shouldnt setting it as a parent do that?

And what about the collisionResponseAnimator ?

Posted: Wed Jan 07, 2004 3:55 am
by Boogle
Well, you can attach a collisionResponseAnimator to your faerie.. and also your camera to make sure it doesn't go inside terrain.

So far this thread has only talked about how to get the camera to watch the faerie. To get the faerie to move, you have to set up an event receiver and set your faerie's position based on key inputs.

Posted: Wed Jan 07, 2004 4:44 am
by RayOfAsh
I know, i tried it, no errors but it didnt move either.

Posted: Wed Jan 07, 2004 5:10 am
by keless
are you sure you were getting events to it properly? and not just letting the camera suck them all up?