Page 1 of 1

Make Cursors for camera in a simple way

Posted: Thu Nov 24, 2005 8:24 am
by r3i
If you must make a cursor you can attach a scenenode at the camera, then set its position with vector3df(0,0,1) and so you have a nice cursor!

But remember: cursor doesn't follow the precise movement of the camera when you "shake" her with sudden movements...

P.S: bt seems that crashes! Nikooooooooo!! I've done some mistake?
---
ILightSceneNode* nodoLuce;
ICameraSceneNode * camera = inizializzaVideoCamera( smgr );
ITextSceneNode * nodoCursore;
IGUIFont * carattere = guienv->getBuiltInFont();
if( camera )
{
eventManager.registraTelecamera( camera );
//impostazioni sul colore e la luce dell'ambiente
nodoLuce = smgr->addLightSceneNode( camera, vector3df(0,10,0.0f), SColorf(1.0f, 1.0f, 1.0f ), 200, -1 );
if( carattere )
{ nodoCursore = smgr->addTextSceneNode(carattere, L"x", SColor(100,255,0,0), camera, vector3df(0,0,1) ); }
}

Posted: Fri Nov 25, 2005 6:15 pm
by Abraxas
Hi,

I do not know if I exactly understood your intention, but I did something similar by attaching a billboard to the camera as a child (after postitioned the billboard into the right "depth". There I can use every picture I like for the billboard (here as a crosshair-texture):

Code: Select all

      scene::ISceneNode* crosshair = 0;
	
      crosshair = smgr->addBillboardSceneNode(crosshair,   
      core::dimension2d<f32>(50, 50));
      crosshair->setMaterialFlag(video::EMF_LIGHTING, false);
      crosshair->setMaterialTexture(0, driver->getTexture  
                                               ("c:/key/crosshair.png"));	
      crosshair->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
      crosshair->setPosition(core::vector3df(0,0,150));
	
      scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
      camera->setPosition(core::vector3df(-50,50,-150));
      camera->addChild(crosshair);
This doesn't crash. Maybe you have to initialize the billboard within the scene is drawn to let it be in the foreground, I don't know how to get this.

To do this with a text line as in your example, I had a closer look at the magic "font.bmp": Realise there are pics of the letters inbetween yellow and red points. I choose a letter I will not use in the game (the "@" e.g.),
and then draw an own picture (of a crosshair) instead of the letter.
The result looks better than an "x". There was no need to attach it to the camera, because it helds it's position.

Posted: Fri Nov 25, 2005 7:28 pm
by dhenton9000
An issue might be if something comes between the camera and the crosshair billboard (such as an attached weapon). I had that problem when I attached a billboard for a muzzle flash effect.

Posted: Fri Nov 25, 2005 8:10 pm
by MikeR
Abraxas code works perfectly.
How about attaching the crosshair as a child of the weapon node? That would solve it from getting in the way.

Posted: Thu Dec 08, 2005 8:33 pm
by Pazystamo
Little addon :)

Code: Select all

      scene::ISceneNode* crosshair = 0;
	
      crosshair = smgr->addBillboardSceneNode(crosshair,   
      core::dimension2d<f32>(50, 50));
      crosshair->setMaterialFlag(video::EMF_LIGHTING, false);
      crosshair->setMaterialTexture(0, driver->getTexture  
                                               ("c:/key/crosshair.png"));	
      crosshair->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
      crosshair->setPosition(core::vector3df(0,0,150));
      //---NEW-----------
      crosshair->setMaterialFlag(video::EMF_ZBUFFER,false);
      //-------------------
      scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
      camera->setPosition(core::vector3df(-50,50,-150));
      camera->addChild(crosshair);
If you set this flag,then others objekts dont came between cursor and camera ;)
Or you can do this:

Code: Select all

      scene::ISceneNode* crosshair = 0;
	//change this to your mesh(animated hand or smf.)
      crosshair = smgr->addTestSceneNode();
      crosshair->setMaterialFlag(video::EMF_LIGHTING, false);
      crosshair->setMaterialTexture(0, driver->getTexture("media/texture.jpg"));	
      //disable transparent if you dont neet it in your mesh
      //crosshair->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
      crosshair->setPosition(core::vector3df(0,0,150));
     //rotate to look more interesting :)
     crosshair->setRotation(core::vector3df(45.0f,45.0f,0));
     //---NEW-----------
     crosshair->setMaterialFlag(video::EMF_ZBUFFER,false);
    //-------------------
      scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
      camera->setPosition(core::vector3df(-50,50,-150));
      camera->addChild(crosshair);
Then you can use any model for cursor,(not tested)but i think it is posible to use animated .x or .md2 to change cursors states(on objent,pick,use,move etc..)
Good luck!