Loading a IRR scene the apply collision to static objects...

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Loading a IRR scene the apply collision to static objects...

Post by christianclavet »

Hi,

Here is a full source for loading a IRRFile the parse it to get the Occtree from the scene and add them to the MetaSelector to be applied then to the Camera (FPS in this case) CollisionResponseAnimator.

Remember that your objects that you want to have collision must be OCCTREE in IRREDIT. All other types are not treated.

Also that code check for the first Camera Node then apply the Position to the FPS Camera. So you can define a Camera in IRRedit, and this code will retrieve it and position your FPS Camera accordingly.

Vitek helped me a lot on this code. It took me 1 hour to create that source, but 2-3 months to understand the Vitek source clearly.

I think this code could help a lots of new user to IrrLicht get their hands on the engine fast using IRREdit and test it under that source.

Here is the code:

Code: Select all

#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
#include <iostream>
#include <windows.h>

using namespace irr;
using namespace irr::core;
using namespace irr::scene;

IrrlichtDevice *intro = 0;
video::IVideoDriver* driver = 0;
scene::ISceneManager* smgr;
scene::IMetaTriangleSelector* metaSelector;
scene::ISceneNodeAnimatorCollisionResponse* anim;
ICameraSceneNode* camera = 0;

bool fin1;

void recursiveFillMetaSelector(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta )
{
  //
  // the following if is basically the same as ISceneNode_assignTriangleSelector
  //
  printf ("Node name is: %s \n",node->getName());
  printf ("Node id is: %d \n",node->getID());
  printf ("Node type:");
  //  printf ("Node type: %s=",smgr->getSceneNodeTypeName());
  if (node->getType() ==   ESNT_UNKNOWN) printf("Unknown mesh type \n\n");
  if (node->getType() ==   ESNT_MESH) printf("Standard Mesh \n\n");
  if (node->getType() ==   ESNT_ANIMATED_MESH) printf("Animated Mesh! \n\n");
  if (node->getType() ==   ESNT_SKY_BOX) printf("SkyBox! \n\n");
  if (node->getType() ==   ESNT_CAMERA_FPS) printf("Fps Camera! \n\n");
  if (node->getType() ==   ESNT_CAMERA_MAYA ) printf("Maya Camera! \n\n"); 
  if (node->getType() ==   ESNT_CAMERA ) 
  { printf("STD Camera! \n");
   printf ("The current position of this camera is: %f,%f,%f\n\n",node->getPosition().X,node->getPosition().Y,node->getPosition().Z);
   camera->setPosition(node->getPosition());
  } 
  if (node->getType() ==   ESNT_PARTICLE_SYSTEM ) printf("Particles! \n\n");
  if (node->getType() ==   ESNT_LIGHT  ) printf("Light! \n\n");
  if (node->getType() ==   ESNT_OCT_TREE)
  { 
      // Occ Trees are for land
      printf("Occtree! \n");
      io::IAttributes* attribs = intro->getFileSystem()->createEmptyAttributes(); 
      if (attribs) 
        {// get the mesh name out 
         node->serializeAttributes(attribs);
         core::stringc name = attribs->getAttributeAsString("Mesh"); 
         attribs->drop(); 
         // get the animated mesh for the object 
         scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str()); 
         if (mesh) 
         { 
            scene::ITriangleSelector* selector = 
            smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128); 
            node->setTriangleSelector(selector); 
            metaSelector->addTriangleSelector(selector);
            selector->drop(); 
         } 

     }
      
  }  
  // now recurse on children...
  core::list<scene::ISceneNode*>::Iterator begin = node->getChildren().begin();
  core::list<scene::ISceneNode*>::Iterator end   = node->getChildren().end();

  for (; begin != end; ++begin)
    recursiveFillMetaSelector(*begin, meta);
}


int main()
{
    // Get the full desktop size from Windows.H
    // First the width
    int nWidth = GetSystemMetrics(0); 
    // Second the Height
    int nHeight = GetSystemMetrics(1);
    intro = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 32, false, true, true);
    driver = intro->getVideoDriver();
    smgr = intro->getSceneManager();
    
    core::stringw str = "Level Demo";
	intro->setWindowCaption(str.c_str());

// Define the Keyboard to use for the camera moves
    SKeyMap keyMap[9];
    keyMap[0].Action = EKA_MOVE_FORWARD;
	keyMap[0].KeyCode = KEY_UP;
	keyMap[1].Action = EKA_MOVE_FORWARD;
	keyMap[1].KeyCode = KEY_KEY_W;

	keyMap[2].Action = EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode = KEY_DOWN;
	keyMap[3].Action = EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode = KEY_KEY_S;

	keyMap[4].Action = EKA_STRAFE_LEFT;
	keyMap[4].KeyCode = KEY_LEFT;
	keyMap[5].Action = EKA_STRAFE_LEFT;
	keyMap[5].KeyCode = KEY_KEY_A;

	keyMap[6].Action = EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode = KEY_RIGHT;
	keyMap[7].Action = EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode = KEY_KEY_D;

	keyMap[8].Action = EKA_JUMP_UP;
	keyMap[8].KeyCode = KEY_SPACE ;

                // Setup the ZIP file "MyLevel.pk3" to be read directly
    	intro->getFileSystem()->addZipFileArchive("levels/MyLevel.pk3");
                // Load the scene file from the archive
	smgr->loadScene("MyLevel.irr");
	
	camera = smgr->addCameraSceneNodeFPS(0, 120.0f, 120.0f, -1, keyMap, 9, true,0.25f);
	    camera->setRotation(core::vector3df(0,135,0));
	    camera->setFarValue(11000.0);
	    camera->setAspectRatio(16/10);
	    camera->setFOV(PI/2.5);
    metaSelector = smgr->createMetaTriangleSelector();
	recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
	// DEfine the collision reponse for the FPS Camera
	anim = smgr->createCollisionResponseAnimator(	metaSelector, camera, core::vector3df(10,26,10),
		//metaSelector, camera, core::vector3df(10,26,10),
		core::vector3df(0,-1.0f,0),
		core::vector3df(0,24,0));
	camera->addAnimator(anim);
	anim->drop();
    metaSelector->drop();
	 while(intro->run() and fin1==false)
	{
		if (intro->isWindowActive())
		{
			driver->beginScene(true, true, video::SColor(0,0,0,0));
			smgr->drawAll();
			driver->endScene();
		}
	}
	intro->closeDevice();
    return 0;
}
Notes:
A) I've put a little code in there to get the desktop width and height and get them. The variable are there but not applied (If you would like that it take your full desktop resolution, it's in there (Variables: nWidth, nHeight).
Since the codes for getting the desktop resolution is windows only, Linux users should remove the "windows.h" and the 2 variables definitions and it should work also fine.
B) This code should run fine in IrrLicht 1.2 and 1.3.1 but not in 1.3. In 1.3 there is a bug that prevent one of the function there to operate correctly.

EDIT: Here is a modified version of the code that should work in 1.4, 1.5 version of IRRlicht:

Code: Select all

#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
#include <iostream>
#include <windows.h>

using namespace irr;
using namespace irr::core;
using namespace irr::scene;

IrrlichtDevice *intro = 0;
video::IVideoDriver* driver = 0;
scene::ISceneManager* smgr;
scene::IMetaTriangleSelector* metaSelector;
scene::ISceneNodeAnimatorCollisionResponse* anim;
ICameraSceneNode* camera = 0;

bool fin1;

void recursiveFillMetaSelector(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta )
{
  //
  // the following if is basically the same as ISceneNode_assignTriangleSelector
  //
  printf ("Node name is: %s \n",node->getName());
  printf ("Node id is: %d \n",node->getID());
  printf ("Node type:");
  //  printf ("Node type: %s=",smgr->getSceneNodeTypeName());
  if (node->getType() ==   ESNT_UNKNOWN) printf("Unknown mesh type \n\n");
  if (node->getType() ==   ESNT_MESH) printf("Standard Mesh \n\n");
  if (node->getType() ==   ESNT_ANIMATED_MESH) printf("Animated Mesh! \n\n");
  if (node->getType() ==   ESNT_SKY_BOX) printf("SkyBox! \n\n");
  if (node->getType() ==   ESNT_CAMERA_FPS) printf("Fps Camera! \n\n");
  if (node->getType() ==   ESNT_CAMERA_MAYA ) printf("Maya Camera! \n\n"); 
  if (node->getType() ==   ESNT_CAMERA ) 
  { printf("STD Camera! \n");
   printf ("The current position of this camera is: %f,%f,%f\n\n",node->getPosition().X,node->getPosition().Y,node->getPosition().Z);
   camera->setPosition(node->getPosition());
  } 
  if (node->getType() ==   ESNT_PARTICLE_SYSTEM ) printf("Particles! \n\n");
  if (node->getType() ==   ESNT_LIGHT  ) printf("Light! \n\n");
  if (node->getType() ==   ESNT_OCT_TREE)
  { 
      // Occ Trees are for land
      printf("Occtree! \n");
      io::IAttributes* attribs = intro->getFileSystem()->createEmptyAttributes(); 
      if (attribs) 
        {// get the mesh name out 
         node->serializeAttributes(attribs);
         core::stringc name = attribs->getAttributeAsString("Mesh"); 
         attribs->drop(); 
         // get the animated mesh for the object 
         scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str()); 
         if (mesh) 
         { 
            scene::ITriangleSelector* selector = 
            smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128); 
            node->setTriangleSelector(selector); 
            metaSelector->addTriangleSelector(selector);
            selector->drop(); 
         } 

     }
      
  }  
  // now recurse on children...
  core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
  core::list<scene::ISceneNode*>::ConstIterator end   = node->getChildren().end();

  for (; begin != end; ++begin)
    recursiveFillMetaSelector(*begin, meta);
}


int main()
{
    // Get the full desktop size from Windows.H
    // First the width
    int nWidth = GetSystemMetrics(0); 
    // Second the Height
    int nHeight = GetSystemMetrics(1);
    intro = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 32, false, true, true);
    driver = intro->getVideoDriver();
    smgr = intro->getSceneManager();
    
    core::stringw str = "Level Demo";
	intro->setWindowCaption(str.c_str());

// Define the Keyboard to use for the camera moves
    SKeyMap keyMap[9];
    keyMap[0].Action = EKA_MOVE_FORWARD;
	keyMap[0].KeyCode = KEY_UP;
	keyMap[1].Action = EKA_MOVE_FORWARD;
	keyMap[1].KeyCode = KEY_KEY_W;

	keyMap[2].Action = EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode = KEY_DOWN;
	keyMap[3].Action = EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode = KEY_KEY_S;

	keyMap[4].Action = EKA_STRAFE_LEFT;
	keyMap[4].KeyCode = KEY_LEFT;
	keyMap[5].Action = EKA_STRAFE_LEFT;
	keyMap[5].KeyCode = KEY_KEY_A;

	keyMap[6].Action = EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode = KEY_RIGHT;
	keyMap[7].Action = EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode = KEY_KEY_D;

	keyMap[8].Action = EKA_JUMP_UP;
	keyMap[8].KeyCode = KEY_SPACE ;

                // Setup the ZIP file "MyLevel.pk3" to be read directly
    	intro->getFileSystem()->addZipFileArchive("levels/MyLevel.pk3");
                // Load the scene file from the archive
	smgr->loadScene("MyLevel.irr");
	
	camera = smgr->addCameraSceneNodeFPS(0, 120.0f, 120.0f, -1, keyMap, 9, true,0.25f);
	    camera->setRotation(core::vector3df(0,135,0));
	    camera->setFarValue(11000.0);
	    camera->setAspectRatio(16/10);
	    camera->setFOV(PI/2.5);
    metaSelector = smgr->createMetaTriangleSelector();
	recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
	// DEfine the collision reponse for the FPS Camera
	anim = smgr->createCollisionResponseAnimator(	metaSelector, camera, core::vector3df(10,26,10),
		//metaSelector, camera, core::vector3df(10,26,10),
		core::vector3df(0,-1.0f,0),
		core::vector3df(0,24,0));
	camera->addAnimator(anim);
	anim->drop();
    metaSelector->drop();
	 while(intro->run() and fin1==false)
	{
		if (intro->isWindowActive())
		{
			driver->beginScene(true, true, video::SColor(0,0,0,0));
			smgr->drawAll();
			driver->endScene();
		}
	}
	intro->closeDevice();
    return 0;
}

Enjoy...
Last edited by christianclavet on Sat Mar 14, 2009 8:20 pm, edited 1 time in total.
horvim
Posts: 11
Joined: Thu Aug 30, 2007 2:08 pm
Location: Hungary

Post by horvim »

How to fix your code to run in SVN?
It has an error:
"conversion from `irr::core::list<irr::scene::ISceneNode*>::ConstIterator' to non-scalar type `irr::core::list<irr::scene::ISceneNode*>::Iterator' requested"

Thanks a lot!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You write ConstIterator instead of Iterator.
fireside
Posts: 158
Joined: Thu Dec 01, 2005 10:55 pm

Post by fireside »

Thanks. I'm currently working on a project in another engine and waiting to use Irrlicht, but I've read the many questions concerning Irr files and collision. It seems like it would be simplest to just include this code with the example for Irr files in Irrlicht.
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Post by nomis »

Hi christianclavet,

Am trying to use your code so I can walk on a level i've made in Maya3D but can't get it to work - I just fall through..

Scene was made in Maya3D, exported to *.obj, OctTree'd into IrrEdit, saved as .irr. It compiles but I simply fall through the level.. It is a static mesh.

Here's what's printed out:

Code: Select all

Irrlicht Engine version 1.2
Microsoft Windows XP Service Pack 2 (Build 2600)
Using renderer: OpenGL 2.0.1
GeForce Go 7700/PCI/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
Node name is:
Node id is: -1
Node type:Unknown mesh type

Node name is:
Node id is: -1
Node type:Fps Camera!

Node name is:
Node id is: -1
Node type:Light!

Node name is:
Node id is: -1
Node type:Fps Camera!

**loads textures**

Loaded mesh: files/level2.obj
Needed 15014ms to create OctTree SceneNode.(545 nodes, 27830 polys)



Here's the code.


Code: Select all

/*
This Tutorial shows how to move and animate SceneNodes. The
basic concept of SceneNodeAnimators is shown as well as manual
movement of nodes using the keyboard.

As always, I include the header files, use the irr namespace,
and tell the linker to link with the .lib file.*/

#include <stdio.h>
#include <wchar.h>
#include <irrlicht.h>
#include <ISceneNodeAnimatorCollisionResponse.h> 

#include <iostream>
#include <windows.h>

#pragma comment(lib, "Irrlicht.lib")


using namespace irr;
using namespace irr::core;
using namespace irr::scene;


IrrlichtDevice* device = 0;
video::IVideoDriver* driver = 0;
scene::ISceneManager* smgr;
scene::ICameraSceneNode* camera = 0;	
scene::ISceneNodeAnimatorCollisionResponse* anim;
scene::IMetaTriangleSelector* metaSelector;
//scene::IAnimatedMeshSceneNode* node = 0;
scene::ISceneNode* player_light[2];





void recursiveFillMetaSelector(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta )
{
  //
  // the following if is basically the same as ISceneNode_assignTriangleSelector
  //
  printf ("Node name is: %s \n",node->getName());
  printf ("Node id is: %d \n",node->getID());
  printf ("Node type:");
  //  printf ("Node type: %s=",smgr->getSceneNodeTypeName());
  if (node->getType() ==   ESNT_UNKNOWN) printf("Unknown mesh type \n\n");
  if (node->getType() ==   ESNT_MESH) printf("Standard Mesh \n\n");
  if (node->getType() ==   ESNT_ANIMATED_MESH) printf("Animated Mesh! \n\n");
  if (node->getType() ==   ESNT_SKY_BOX) printf("SkyBox! \n\n");
  if (node->getType() ==   ESNT_CAMERA_FPS) printf("Fps Camera! \n\n");
  if (node->getType() ==   ESNT_CAMERA_MAYA ) printf("Maya Camera! \n\n");
  if (node->getType() ==   ESNT_CAMERA )
  { printf("STD Camera! \n");
   printf ("The current position of this camera is: %f,%f,%f\n\n",node->getPosition().X,node->getPosition().Y,node->getPosition().Z);
   camera->setPosition(node->getPosition());
  }
  if (node->getType() ==   ESNT_PARTICLE_SYSTEM ) printf("Particles! \n\n");
  if (node->getType() ==   ESNT_LIGHT  ) printf("Light! \n\n");
  if (node->getType() ==   ESNT_OCT_TREE)
  {
      // Occ Trees are for land
      printf("Occtree! \n");
      io::IAttributes* attribs = device->getFileSystem()->createEmptyAttributes();
      if (attribs)
        {// get the mesh name out
         node->serializeAttributes(attribs);
         core::stringc name = attribs->getAttributeAsString("Mesh");
         attribs->drop();
         // get the animated mesh for the object
         scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
         if (mesh)
         {
            scene::ITriangleSelector* selector =
            smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
            node->setTriangleSelector(selector);
            metaSelector->addTriangleSelector(selector);
            selector->drop();
         }

     }
     
  } 
  // now recurse on children...
  core::list<scene::ISceneNode*>::Iterator begin = node->getChildren().begin();
  core::list<scene::ISceneNode*>::Iterator end   = node->getChildren().end();

  for (; begin != end; ++begin)
    recursiveFillMetaSelector(*begin, meta);
}



void createCamera()
{
	// Key map for the FPS camera
	SKeyMap keyMap[10];
	keyMap[0].Action=EKA_MOVE_FORWARD;
	keyMap[0].KeyCode=KEY_UP;
	keyMap[1].Action=EKA_MOVE_FORWARD;
	keyMap[1].KeyCode=KEY_KEY_W;

	keyMap[2].Action=EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode=KEY_DOWN;
	keyMap[3].Action=EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode=KEY_KEY_S;

	keyMap[4].Action=EKA_STRAFE_LEFT;
	keyMap[4].KeyCode=KEY_LEFT;
	keyMap[5].Action=EKA_STRAFE_LEFT;
	keyMap[5].KeyCode=KEY_KEY_A;

	keyMap[6].Action=EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode=KEY_RIGHT;
	keyMap[7].Action=EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode=KEY_KEY_D;

	// Create camera
	camera = smgr->addCameraSceneNodeFPS(
		0,											// Parent node
		100.0f,										// Rotate speed
		500.0f,										// Movement speed
		-1,											// ID
		keyMap,										// Key map array
		8,											// Key map size
		true										// No vertical movement
		);

       camera->setRotation(core::vector3df(0,135,0));
       camera->setFarValue(11000.0);
       camera->setAspectRatio(16/10);
       camera->setFOV(PI/2.5);
}


//receive inputs
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
	
		return false;
	}
};

int main()
{
	MyEventReceiver receiver;

	device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1024, 768),
		16, false, false, false, &receiver);

	driver = device->getVideoDriver();
	smgr = device->getSceneManager();

	camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 10.0f);

	device->getCursorControl()->setVisible(false);


	player_light[0] = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
	video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);

	createCamera();

	metaSelector = smgr->createMetaTriangleSelector();
	recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
	// Define the collision reponse for the FPS Camera
	anim = smgr->createCollisionResponseAnimator(   metaSelector, camera, core::vector3df(10,26,10),
		core::vector3df(0,-1.0f,0),
		core::vector3df(0,24,0));
	camera->addAnimator(anim);
	anim->drop();
    metaSelector->drop();

	player_light[0]->setPosition(core::vector3df(0,24,0));


	// level 2
	smgr->loadScene("files/level2.irr"); 


	int lastFPS = -1;
 
	while(device->run())
	{
		driver->beginScene(true, true, video::SColor(255,113,113,133));

		smgr->drawAll(); // draw the 3d scene
	//	device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			//wchar_t tmp[1024];
			//swprintf(tmp, 1024, L"Library Model");

			//device->setWindowCaption(tmp);
			lastFPS = fps;
		}
	}

	//In the end, delete the Irrlicht device.

	device->closeDevice();
	
	return 0;
}



Can you see something that i'm doing wrong?

I believe the problem might be the "Node type:Unknown mesh type" bit so it doesn't start up the actual collision detection as it doesn't think it's needed but I've tried giving the level id's and named in irredit but it never shows them..

Any help would be greatly appreciated!!
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi. No the "Node type:Unknown mesh type" is the root node.

There is some things I've remarked.

- The output didnt print "Node type: Occtree!" (So the current scene didnt have an octree)

- You should position your camera using a standard camera in IRRedit or modify the code. In IRREdit 7.01, we only had standard camera. If not, then position manually your camera in your code (I don't see any code for positionning your camera). The camera need to be over your mesh a little.

- You seem to load the scene AFTER the check is made. You need to load your scene BEFORE doing the metaselector. I think most of your problem is there.

Do it like this:

Code: Select all

smgr->loadScene("files/level2.irr");
recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
Your OBJ need to be loaded as an OCCTREE in IRREdit. Does it display ok in IRRedit? If yes, then the collision should work.

Please check for those details.
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Post by nomis »

Thank you for your reply! Did all that and got it reading fine, then the main problem I had was the scale of the level, it was tiny! Needed to make it 10x bigger, the collision of the level/camera smaller and tadaa it works!

Many thanks for your code and comments, would have been in a whole lot of trouble without them!
nano
Posts: 25
Joined: Mon May 07, 2007 1:12 pm

Post by nano »

Using this code i can't get it to jump. Any ideas?

Code: Select all

// Key map for the FPS camera
	SKeyMap keyMap[9];
	keyMap[0].Action=EKA_MOVE_FORWARD;
	keyMap[0].KeyCode=KEY_UP;
	keyMap[1].Action=EKA_MOVE_FORWARD;
	keyMap[1].KeyCode=KEY_KEY_W;

	keyMap[2].Action=EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode=KEY_DOWN;
	keyMap[3].Action=EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode=KEY_KEY_S;

	keyMap[4].Action=EKA_STRAFE_LEFT;
	keyMap[4].KeyCode=KEY_LEFT;
	keyMap[5].Action=EKA_STRAFE_LEFT;
	keyMap[5].KeyCode=KEY_KEY_A;

	keyMap[6].Action=EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode=KEY_RIGHT;
	keyMap[7].Action=EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode=KEY_KEY_D;

	keyMap[8].Action = EKA_JUMP_UP;
    keyMap[8].KeyCode = KEY_SPACE;

	// Create camera
	camera = smgr->addCameraSceneNodeFPS(
		0,											// Parent node
		100.0f,										// Rotate speed
		20.0f,										// Movement speed
		-1,											// ID
		keyMap,										// Key map array
		9,											// Key map size
		false,										// No vertical movement
		2											// Jump Speed
		);
as far as i know that's all i need to do to make jump work, but it seems nothing at all happens when i press the space bar =/

Would it have anything to do with the gravity perhaps? Gravity is only set to -0.1 anyway.

Code: Select all

anim = smgr->createCollisionResponseAnimator(   metaSelector, camera, core::vector3df(1.0,10.0,1.0),
		core::vector3df(0,-0.1f,0),
		core::vector3df(0,24,0));
Thanks in advance for any help anyone can give.
Obeleh
Posts: 28
Joined: Tue Oct 02, 2007 7:46 am

Post by Obeleh »

Hi I tried your code and it works good.

I've altered it a bit so that the functions are in a different file.
I've tried to do the same with the keymaps but that didnt work.


Now my keymaps are still in main() but jump doesnt work. Is it because were using a camera instead of a model?
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi, I'm happy that it's useful! :D

for the JUMP functionality. This is in the main FPS camera definition:

Define the camera as I've done. It's the LAST argument. (My jump High is .25, try a big value like 100 first, If you jump very high, then it work :D )

Also you've got to enable VERTICAL movement... :)

Code: Select all

camera = smgr->addCameraSceneNodeFPS(0, 120.0f, 120.0f, -1, keyMap, 9, true,0.25f); 


Also, if the keymap is not working try using "J" on the keyboard it's the default value is the JUMP feature is enabled (Greater than 0 value);

If "J" or "SPACE" is not working then the JUMP feature is not enabled.
If "J" is working and "SPACE" is not then you got to check your keymap definition for the CAMERA.

EDIT: Forgot this detail: check that your version is 1.3.1. Not sure it was implemented in 1.2
Obeleh
Posts: 28
Joined: Tue Oct 02, 2007 7:46 am

Post by Obeleh »

Thanks. Jumping now works. It seems that the keymap size and the jumpspeed both werent right. But I thought I simply copied it from your original example.
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

Code: Select all

irr::io::IAttributes* attribs = device->getFileSystem()->createEmptyAttributes(); 

if (attribs)
{ 
node2->serializeAttributes(attribs);
core::stringc name = attribs->getAttributeAsString("Mesh");
attribs->drop();
scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
if (mesh)
         {
         printf("\n I'm here! \n");
            scene::ITriangleSelector* selector =
            smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node2, 128);
            node2->setTriangleSelector(selector);
            metaSelector->addTriangleSelector(selector);
            selector->drop();
            
            scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, node1, core::vector3df(15,50,20),
		core::vector3df(0,-3,0),core::vector3df(0,-50,-5),0.002);
        node1->addAnimator(anim);
        anim->drop();
         }
Using Irrlicht 1.3.1 -> can't get the mesh. Application is crashing bcs of

node2->serializeAttributes(attribs);
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi. This problem occur with 1.3.

Are you sure you are running the 1.3.1 library?
Vedrus
Posts: 2
Joined: Sat Nov 22, 2008 1:53 am

Post by Vedrus »

Hello, all.

I try load "terrain.irr" with this code, but The chamber falls downwards. When has put gravitation equal 0, and has tried to pass through walls is it was possible. What I do not so?
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Vedrus wrote:Hello, all.

I try load "terrain.irr" with this code, but The chamber falls downwards. When has put gravitation equal 0, and has tried to pass through walls is it was possible. What I do not so?
The current code does only account if your meshes are loaded in IRRedit as OCTREES. Terrains nodes are not OCCTREES.

You would have to update the code to account for terrain mesh collision.
Adding the terrain triangleselectors to the metaSelector, so the collision response animator would work
Post Reply