Make Cursors for camera in a simple way

A forum to store posts deemed exceptionally wise and useful
Post Reply
r3i
Posts: 147
Joined: Wed Jun 29, 2005 10:15 am
Location: Sorrento
Contact:

Make Cursors for camera in a simple way

Post 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) ); }
}
"We work in the dark, we do what we can, we give what we have, Our doubt is our passion and our passion is our task. The rest: is art of Madness" (H.James)
Abraxas
Posts: 57
Joined: Mon Nov 07, 2005 3:56 pm

Post 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.
Image
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post 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.
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post 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.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Pazystamo
Posts: 115
Joined: Sat Dec 03, 2005 5:56 pm
Location: Lithuania
Contact:

Post 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!
Post Reply