(C++) simple steering (waypoint demo for download)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

(C++) simple steering (waypoint demo for download)

Post by Acki »

Hi,
in the beginers forum I had the idea for a simple steering system by only using Irrlicht possibilities...
After this I created a simple path finding system by using waypoints !!!
The source is a little bit to big for posting here, so I made a download avilable...
demo + source: SimpleSteering.zip

And this is the really simple steering demo !!!
There is one enemy that always faces the player (camera) and moves straight to him...

Code: Select all

// !!! define here your Irrlicht media directory !!!
#define irrMediaDir "C:/CodeBlocks/AB-AddOn/Media/Irrlicht"

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main(){
  IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(800, 600));
  IVideoDriver* driver = device->getVideoDriver();
  ISceneManager* smgr = device->getSceneManager();

  // create a ground (just for optic)
  ISceneNode* ground = smgr->addTestSceneNode(10);
  ground->setScale(vector3df(500, 1, 500));
  ground->setMaterialTexture( 0, driver->getTexture(irrMediaDir"/wall.bmp") );
  ground->setMaterialFlag(EMF_LIGHTING, false);

  // create enemy
  ICameraSceneNode* camEnemy = smgr->addCameraSceneNodeFPS();
  camEnemy->setPosition(vector3df(0, 45, 0));
  IAnimatedMesh* mesh = smgr->getMesh(irrMediaDir"/faerie.md2");
  IAnimatedMeshSceneNode* nodeEnemy = smgr->addAnimatedMeshSceneNode(mesh, camEnemy);
  nodeEnemy->setMaterialTexture( 0, driver->getTexture(irrMediaDir"/faerie2.bmp") );
  nodeEnemy->setMaterialFlag(EMF_LIGHTING, false);
  nodeEnemy->setMD2Animation(EMAT_RUN);
  // rotation offset for faerie, because she's looking to the side
  nodeEnemy->setRotation(vector3df(0, -90, 0));
  // position offset to get faerie to the ground
  nodeEnemy->setPosition(vector3df(0, -16, 0));

  // create player camera
  ICameraSceneNode* camPlayer = smgr->addCameraSceneNodeFPS(0, 100.0f, 500.0f, -1, 0, 0, true);
  camPlayer->setPosition(vector3df(0, 45, -150));
  device->getCursorControl()->setVisible(false);

  while(device->run()){
    driver->beginScene(true, true, SColor(255,100,100,150));
    smgr->drawAll();
    driver->endScene();

    // update enemy rotation
    camEnemy->setTarget(camPlayer->getPosition());
    camEnemy->updateAbsolutePosition();
    // move enemy
    line3d<f32> line;
    line.start = camEnemy->getPosition();
    line.end = line.start + (camPlayer->getPosition() - line.start).normalize() * 0.1;
    camEnemy->setPosition(line.end);
  }
  device->drop();
  return 0;
}
Last edited by Acki on Wed Feb 23, 2011 10:24 pm, edited 2 times in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Maybe I mistunderstood this method a bit.

You want to set up an enemy to update his rotation towards a player when you for example walk near him and rotation should be updated all time ?

Hmm wouldn't it be simplier to make a node ->

Code: Select all

enemyNode->setRotation(vector3df(playercamera->getRotation().x,playercamera->getRotation().y-180,playercamera->getRotation().z))
And it should be updated all time. (maybe Im not too good atm with thinking because its above 30 degrees + here and Im thrilly hot atm )

This method also would depend on the enemy's model default rotation.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

No, I don't think so...
You rotate the node like the camera is rotated...
This is automatically done by the parent/child relationship !!!

This is a really simple steering demo.
There is an enemy (faery) that always faces the camera (player) and walks always straight to the position of the player cam...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Hi,
I just released a simple waypoint-steering demo !!! 8)
(please read main thread)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

can you reupload this ? i wanna see it :D
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

paulorr29 wrote:can you reupload this ? i wanna see it :D
try the link of the mp again... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

thanks !!
it's awesome o_o !!!! nice job
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
Post Reply