failed to apply gravity to my scene nodes

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
trueleowdeo
Posts: 6
Joined: Mon Apr 26, 2010 7:09 am

failed to apply gravity to my scene nodes

Post by trueleowdeo »

i am trying to apply gravity to the models in tutorial 7 (- collision detection )instead of setting their position on the floor manually

1. first i commented out these lines

Code: Select all

//selector->drop(); // As soon as we're done with the selector, drop it
//node->setPosition(core::vector3df(-70,-15,-120)); // Put its feet on the floor(commented out for faerie.md2)

2.Then i tried to apply gravity to the faerie.md2 by

Code: Select all

scene::ISceneNodeAnimator* anim2 = smgr->createCollisionResponseAnimator(
                        selector, node); //node is ISceneNode *  for faerie.md2

                 node->addAnimator(anim2);
                anim2->drop();
But this did not apply gravity to faerie.md2. Can anyone help me??

Thanks in advance :)
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

Post by freetimecoder »

This is because you did not give the Animator the parameter for gravity.
http://irrlicht.sourceforge.net/docu/cl ... 6a78f002be

~edit~ Sorry, seems to be a default parameter, my fault. You need to post more code.

greetings
trueleowdeo
Posts: 6
Joined: Mon Apr 26, 2010 7:09 am

Post by trueleowdeo »

here is the full source code (copy and pasted)

Code: Select all

#include<irrlicht.h>

using namespace irr;

using namespace video;

using namespace io;

using namespace scene;

using namespace core;



int main()

{

	IrrlichtDevice * device= createDevice(video::EDT_OPENGL);

	if(!device) return 1;



	device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");

	

	IVideoDriver * driver = device->getVideoDriver();

	ISceneManager * sceneManager = device->getSceneManager();



	IAnimatedMesh * mesh= sceneManager->getMesh("20kdm2.bsp");

	//declare triangle selector and scene node

	ISceneNode * node;

	ITriangleSelector * selector;//needed for collision detection





	if(mesh)

	{

		node = sceneManager->addMeshSceneNode(mesh->getMesh(0));

		node->setPosition(core::vector3df(-1300,-144,-1249));

		selector = sceneManager->createOctreeTriangleSelector(mesh->getMesh(0),node);

		node->setTriangleSelector(selector);

	}





	ICameraSceneNode * nodeCamera = sceneManager->addCameraSceneNodeFPS();





	ISceneNodeAnimator * collisionAnimator =sceneManager->createCollisionResponseAnimator(selector,nodeCamera,vector3df(30,30,30),

													vector3df(0,-10,0),vector3df(0,3,0));

	nodeCamera->addAnimator(collisionAnimator);

	collisionAnimator->drop();



	IAnimatedMesh * meshFairy = sceneManager->getMesh("../../media/faerie.md2");

	IAnimatedMeshSceneNode * nodeFairy = sceneManager->addAnimatedMeshSceneNode(meshFairy);

	

	//now its skin

	SMaterial materialFairy;

	materialFairy.setTexture(0,driver->getTexture("../../media/faerie5.bmp"));

	materialFairy.Lighting= false;



	nodeFairy->getMaterial(0)=materialFairy;

	nodeFairy->setMD2Animation(scene::EMAT_WAVE);

	nodeFairy->setAnimationSpeed(23);

	//nodeFairy->setScale(vector3df(2,2,2));

	//trying to apply gravity to the fairy

	//ITriangleSelector * fairySelector = sceneManager->createTriangleSelector(nodeFairy);

	nodeFairy->setTriangleSelector(selector);

	ISceneNodeAnimator * collisionAnimatorFairy= sceneManager->createCollisionResponseAnimator(selector,

																							   nodeFairy);

	nodeFairy->addAnimator(collisionAnimatorFairy);

	collisionAnimatorFairy->drop();

	





	while(device->run())

	{

		if(device->isWindowActive())

		{

			driver->beginScene();

			sceneManager->drawAll();

			driver->endScene();

		}

		else

		{

			device->yield();

		}

	}

	device->drop();

	return 0;

}


Post Reply