Crosshair

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Guest

Crosshair

Post by Guest »

Hello,
I'm new here and I have a question: how can I add a crosshair. Please send some code :wink:

PS: Please excuse my bad english :wink:
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

1024x768

Post by LordNaikon »

for a solution of 1024x768

Code: Select all

driver->draw2DRectangle( irr::video::SColor(100,100,200,100), irr::core::rect<s32>(511,372,513,378) ); //above

driver->draw2DRectangle( irr::video::SColor(100,100,200,100), irr::core::rect<s32>(518,383,524,385) ); //right

driver->draw2DRectangle( irr::video::SColor(100,100,200,100), irr::core::rect<s32>(511,390,513,396) ); //down

driver->draw2DRectangle( irr::video::SColor(100,100,200,100), irr::core::rect<s32>(500,383,506,385) ); //left
looks like this
Image
Last edited by LordNaikon on Wed Jul 07, 2004 9:56 am, edited 1 time in total.
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
Guest

Post by Guest »

It works! Thanks :D
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

Post by LordNaikon »

everytime again :D
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

What you could also do, because you have to account for other screen sizes, if you want the cross hair in the middle of the screen, you can do something like:

Code: Select all

irr::core::position2d<irr::f32> pos = Cursor->getRelativePosition();
// keep cursor in the middle of the screen
pos.X = 0.5f;
pos.Y = 0.5f;
Cursor->setPosition(pos);
This will position the cursor in the middle of the screen.
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

Why you get position of a cursor and then overwrite it with new valuse. To keep cursor in the meedle of the screen this is sufficient:

Code: Select all

Cursor->setPosition(irr::core::position2d<irr::f32>(0.5f,0.5f));
Tomasz Nowakowski
Openoko - www.openoko.pl
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Oh, yeah, okay. That does make more sense.

I was just changing someone else's code, which generally I do on a mostly line by line basis, because its occasionally hard to see where someone is going with it. (occasionally, but admitedly not in this case :D)
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

If you use a camera that traps the cursor, it may jump around a bit more than you'd want a crosshair to. I haven't actually tried it, so maybe it wouldn't be a problem, but the cursor with the irrlicht fps camera appears to jump around a bit
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Guest

Post by Guest »

Thanks to all,
I have one more question to LordNaikom: where did You get that shotgun? Any links? :wink:
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

Post by LordNaikon »

i know you would ask that question :D , but i have to say i don't know where i get that shotgun sry. i am also searching of free model stuff all around.
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
Th3one
Posts: 17
Joined: Fri Nov 25, 2005 11:43 am

Post by Th3one »

This'l add your crosshair no probs buddy....

Code: Select all

scene::ISceneNode* crosshair = 0;
   
      crosshair = smgr->addBillboardSceneNode(crosshair,   
      core::dimension2d<f32>(10, 10));
      crosshair->setMaterialFlag(video::EMF_LIGHTING, false);
      crosshair->setMaterialTexture(0, driver->getTexture 
                                               ("../../Textures/crosshair1.bmp"));   
      crosshair->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
      crosshair->setPosition(core::vector3df(0,0,150));
   
      camera->addChild(crosshair);
Guest

Post by Guest »

sorry mate but this thread is a _little_ old :) (lets say 1,5 years) - the thread owner will have found the solution already after such a long time i guess :D

see you!
independentCreations
Posts: 24
Joined: Fri Oct 28, 2005 10:05 am
Location: Gold Coast, QLD, Australia

Post by independentCreations »

must of went diggin for that 1 th3one, year and a half. i hope guest solved this allready :)
"do it, do it now"
Th3one
Posts: 17
Joined: Fri Nov 25, 2005 11:43 am

Post by Th3one »

hehe yea...but surely it'll help the likes of me that were searching for the solution :P
magisterrivus
Posts: 33
Joined: Sat Aug 05, 2006 9:46 pm

Post by magisterrivus »

A little addition to this 2yrs old code

Code: Select all

crosshair->setMaterialFlag(video::EMF_ZBUFFER, false);
;)
under construction
Post Reply