Mouse

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
Italia
Posts: 10
Joined: Sun May 04, 2008 11:12 am

Mouse

Post by Italia »

Hello, i am Gianni and i 15 years old. I have a problem:
I move the mouse, and make to talk nonsense to the pressure of the left key of the mouse, the problem I am is like making ? I tried so:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
   virtual bool OnEvent(const SEvent& event)
   {
        if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
        {
             switch( cosa metto ?? )
             {
                 .................
              }
         }

   }
}; 

But at the switch and put inside that?
IO I used the following site to translate http://www.carloneworld.it/Download_Tra ... nslate.htm

In italiano: Come fare sparare alla pressione del tasto sinistro del mouse ? ho usato il codice che vedete, ma non so cosa mettere tra le parentesi dello switch e come mettere una case per la pressione del tasto sinistro del mouse
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

I find it a little difficult to understand, but these two keywords are sufficient I think: MOUSE and PROBLEM :D


Replace this:

Code: Select all

if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
        {
             switch( cosa metto ?? )
             {
                 .................
              }
         } 

with this:

Code: Select all

//--- Mouse Events Go Here ----------------------------------------------------
     if (event.EventType == EET_MOUSE_INPUT_EVENT)
	{


			if (event.MouseInput.Event==EMIE_LMOUSE_PRESSED_DOWN)
               { 
			     //do whatever  
				 return true; 
		       }
			return false;
	 }
I don`t know why you want to use the SWITCH method. To check what? If you need to check whether a button is pressed, released etc. or something else there are lots of examples, just use: search.

If not, try to explain better what is the actual problem and what do you want it to do. :roll:

PS: Ahhh, an WELCOME to the IRRLICHT Forum :wink:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Italia
Posts: 10
Joined: Sun May 04, 2008 11:12 am

Post by Italia »

thanks very much
Italia
Posts: 10
Joined: Sun May 04, 2008 11:12 am

Post by Italia »

the my objective is shooting witch the left button mouse. I tried so but not go.

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
   virtual bool OnEvent(const SEvent& event)
   {
      if (event.EventType == EET_MOUSE_INPUT_EVENT)
       {
             if (event.MouseInput.Event==EMIE_LMOUSE_PRESSED_DOWN)
                   {
                  cout << " a ";
                  core::position2d<s32> mouse;
                  video::ITexture* cursore20 = driver->getTexture("a.JPG");
                  driver->draw2DImage(cursore20,core::position2d<s32>(mouse.X,mouse.Y),
                  core::rect<s32>(0,0,32,32), 0, video::SColor(200,200,200,255), true);
                 return true;
                 }
             return false;
        }
   }
};
a is one image white
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

it will be best to call a function like so:

Code: Select all

if (event.MouseInput.Event==EMIE_LMOUSE_PRESSED_DOWN)
                   {
                  shoot();//call the function to shoot a projectile
                    return true;
                  } 
I advice you to start with the tutorials before creating the next generation FPS or MMO. If you find it difficult to understand the explanations, just start with the Tutorial 1 and explore the code. Play around with the values and when you have some idea what`s goin` on there, than start with the Tutorial 2 and on.

Here`s another good tutorial you should check:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898


Here`s the function used in the Demo tutorial, which comes with the IRRLICHT. You`ll better edit it and use it as a base for your game. It will be best to use the whole Demo application as a base.
But before starting anything, you just HAVE TO check the tutorials:

http://irrlicht.sourceforge.net/tutorials.html

Good luck! :wink:

PS: If you aim building high towers, you`ll have to spend lots of time, working on the bases. ( Sorry for the bad translation, but the idea`s there, isn`t it?)

Code: Select all

void shoot()
{
	scene::ISceneManager* sm = device->getSceneManager();
	scene::ICameraSceneNode* camera = sm->getActiveCamera();

	
	SParticleImpact imp;
	imp.when = 0;

	// get line of camera

	core::vector3df start = camera->getPosition();
	core::vector3df end = (camera->getTarget() - start);
	end.normalize();
	start += end*8.0f;
	end = start + (end * camera->getFarValue());

	core::triangle3df triangle;

	core::line3d<f32> line(start, end);

	// get intersection point with map

	if (sm->getSceneCollisionManager()->getCollisionPoint(
		line, mapSelector, end, triangle))
	{
		// collides with wall
		core::vector3df out = triangle.getNormal();
		out.setLength(0.03f);

		imp.when = 1;
		imp.outVector = out;
		imp.pos = end;
	}
	else
	{
		// doesnt collide with wall
		core::vector3df start = camera->getPosition();
		core::vector3df end = (camera->getTarget() - start);
		end.normalize();
		start += end*8.0f;
		end = start + (end * camera->getFarValue());
	}

	// create fire ball
	scene::ISceneNode* node = 0;
	node = sm->addBillboardSceneNode(0,
		core::dimension2d<f32>(25,25), start);

	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/fireball.bmp"));
	node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);

	f32 length = (f32)(end - start).getLength();
	const f32 speed = 0.6f;
	u32 time = (u32)(length / speed);

	scene::ISceneNodeAnimator* anim = 0;

	// set flight line

	anim = sm->createFlyStraightAnimator(start, end, time);
	node->addAnimator(anim);
	anim->drop();

	anim = sm->createDeleteAnimator(time);
	node->addAnimator(anim);
	anim->drop();

	
}

Last edited by shadowslair on Sun May 04, 2008 3:29 pm, edited 2 times in total.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Italia
Posts: 10
Joined: Sun May 04, 2008 11:12 am

Post by Italia »

OK i have comprend you messagge, but

Code: Select all

C:\Documents and Settings\Gianni\Desktop\main.cpp In function `void shoot()': 35 C:\Documents and Settings\Gianni\Desktop\main.cpp `SParticleImpact' undeclared (first use this function)   (Each undeclared identifier is reported only once for each function it appears in.) 35 C:\Documents and Settings\Gianni\Desktop\main.cpp expected `;' before "imp" 59 C:\Documents and Settings\Gianni\Desktop\main.cpp `imp' undeclared (first use this function)  C:\Documents and Settings\Gianni\Desktop\Nuova cartella (2)\Makefile.win [Build Error]  [../main.o] Error 1 

// line 35
   SParticleImpact imp
// liine 59
  imp.when = 1;
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Did you checked and understood the basic tutorials yet? If so, than you`re too fast... :D

You cannot expect to simply paste the code and everything to start working. Once again, you HAVE TO try reading and understanding some Irrlicht documentation, and the tutorials, and the examples, and the topics and code snippets in this forum... and C++... and some english maybe. :shock: WOW too much maybe. First thing first.

Please be patient and consistent. And hard working too.

If you take some time to learn a few, than you won`t even ask about doing such things. It`s about a month since I started learning C++ and Irrlicht, but I believe I have some progress. So do you.

This will be YOUR game at all... :D

PS: And about your problem- just copy the original Demo project( located here: C:\Irrlicht\irrlicht-1.4\examples\Demo ). Paste it in the same folder and use it as a base.

PS2: And creating your project at the desktop is not a good idea :roll:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Post Reply