Error when trying to set a target for the camera

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.
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Error when trying to set a target for the camera

Post 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::
Image
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

From what I see... "faerienode" should be "node". (not unless you have another SceneNode named "faerienode" )
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Post 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.
Image
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

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

Post 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...
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post 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...
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post 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);
Crud, how do I do this again?
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Post 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.
Image
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Post 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.
Image
Keanu
Posts: 13
Joined: Sun Jan 04, 2004 11:10 am
Location: Italy
Contact:

Post 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:
P4 2.53MHz 256MB GeForce4Mx VC++6.0
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Post 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.
Image
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post 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.
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Post 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 ?
Image
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post 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.
RayOfAsh
Posts: 56
Joined: Wed Dec 24, 2003 4:08 am
Location: San Diego
Contact:

Post by RayOfAsh »

I know, i tried it, no errors but it didnt move either.
Image
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

are you sure you were getting events to it properly? and not just letting the camera suck them all up?
a screen cap is worth 0x100000 DWORDS
Post Reply