IrrNewt - FPS Camera (Controller)

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
lukrop
Posts: 27
Joined: Wed Aug 29, 2007 10:28 am
Location: Vienna, Austria

IrrNewt - FPS Camera (Controller)

Post by lukrop »

Hi,

i want to implement a FPS Camera wich has collision detection with my map. ok i got the map (octree, bsp) in newton and collision detection works fine with testcubes. I also added a camera and a character controller but i don't really understand how they work. I think I'm doing it completely false because I don't understand the principle which stands behind the concept. I got the code from the IrrNewt character controller example.

If I do nothing after the map shows up, the camera goes on the ground (because of the gravity) but when I move (arrow-keys) it seems like the camera "leaves" the newton primitve and it can fly through walls and is not affected by gravity. If I'm lucky I can get into the primitve again (which hasn't moved) and it's affected by gravity or testcubes which hit the camera. I don't know how to make the camera stick in the newton primitve or how to make the primitve a child of the camera.

maybe someone can give me some hints on how I get this thing working or some simple tutorials which are focused on this problem. I think this is a well known question because who doesn't want a fps camera which does collision detection but i couldn't find anything useful on google or the board search, IrrNewt seems kind of "dead".

Thanks in advance,
lukrop

here's the code I'm using

Code: Select all

    scene::IAnimatedMesh* mapMesh = core->getSmgr()->getMesh("maps/20kdm2.bsp");
    scene::ISceneNode* mapNode = core->getSmgr()->addOctTreeSceneNode(mapMesh->getMesh(0));
    mapNode->setPosition(core::vector3df(mapPosition));

    scene::ISceneNode* camera = core->getSmgr()->addCameraSceneNodeFPS(0,80.0f,200.0f,-1);
//    camera->setPosition(core::vector3df(camPosition));
    
    nWorld = irr::newton::createPhysicsWorld(core->getDevice());
    
    irr::newton::Hidden::SetDevice(core->getDevice());
    
    newton::SBodyFromNode mapData;
    mapData.Node = mapNode;
    mapData.Mesh = mapMesh->getMesh(0);
    nMapNode = (irr::newton::ITreeBody*) nWorld->createBody(mapData);
    
    newton::SBodyFromNode cameraData;
//    irr::newton::ICameraBodyFPS* newtonCam = nWorld->createCameraFPS(cameraData);
//    newtonCam->addForceContinuous(core::vector3df(0, -30.0f, 0));
//    newtonCam->setPosition(camPosition);
    cameraData.Type = newton::EBT_PRIMITIVE_CAPSULE;
    cameraData.Node = camera;
    
    charControl =   nWorld->createCharacterController(nWorld->createBody(cameraData));
    charControl->setRotationUpdate(false);
    charControl->setContinuousCollisionMode(true);
    
    nWorld->getUtils()->avoidRotationOnAllAxes(charControl);
    
    irr::newton::IMaterial* cameraMaterial;
    irr::newton::IMaterial* mapMaterial;
    
    cameraMaterial = nWorld->createMaterial();
    mapMaterial = nWorld->createMaterial();
    
    charControl->setMaterial(cameraMaterial);
    nMapNode->setMaterial(mapMaterial);
    
    cameraMaterial->setElasticity(mapMaterial, 0.0f);
    cameraMaterial->setFriction(mapMaterial, 0.0f, 0.0f);
    cameraMaterial->setSoftness(mapMaterial, 1.0f);
    
    charControl->setClimbStairForce(core::vector3df(0,4,0));
    charControl->setStairMaxHeight(40);
    
    charControl->addForceContinuous(core::vector3df(0,-30.0f,0));
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

Code: Select all

   // Irrlicht collision [FOR MAP] 
   selector = smgr->createOctTreeTriangleSelector(map->getMesh()->getMesh(0), map, 128);
   map->setTriangleSelector(selector); // set the map's collision tri grabber
   selector->drop(); // drop it as we wont need it anymore

   // Irrlicht collision [FOR P1]
   ISceneNodeAnimator* anim = 
    smgr->createCollisionResponseAnimator(selector, p1->getNode(), core::vector3df(30,2,30),
      core::vector3df(0,-4,0),
      core::vector3df(0,0,0));
   p1->getNode()->addAnimator(anim); // add the gravity/collision response animator
   anim->drop(); // we dont need the animator anymore
lukrop
Posts: 27
Joined: Wed Aug 29, 2007 10:28 am
Location: Vienna, Austria

Post by lukrop »

dudMaN wrote:

Code: Select all

   // Irrlicht collision [FOR MAP] 
   selector = smgr->createOctTreeTriangleSelector(map->getMesh()->getMesh(0), map, 128);
   map->setTriangleSelector(selector); // set the map's collision tri grabber
   selector->drop(); // drop it as we wont need it anymore

   // Irrlicht collision [FOR P1]
   ISceneNodeAnimator* anim = 
    smgr->createCollisionResponseAnimator(selector, p1->getNode(), core::vector3df(30,2,30),
      core::vector3df(0,-4,0),
      core::vector3df(0,0,0));
   p1->getNode()->addAnimator(anim); // add the gravity/collision response animator
   anim->drop(); // we dont need the animator anymore
do I need the irrlicht collisionResponseAnimator if I want to do the collision with Newton (IrrNewt)?
Post Reply