event type toggle

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.
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

event type toggle

Post by Dogs »

I spent some time messing around with key events and finally got that working... Now Id like to figure out how to set up the mouse events as I see the api looks simpler then the key events lol but I still cant figure it out lol...

What im looking to do is somethings like this..

if ( event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN ) {
Mouse1=true;

if ( event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN ) {
Mouse1=false;


I want to set up two events and loop them.. So that when I click on the right mouse button Mouse1 is true and then when I click on it agian Mouse1 is false and back and forth, Toggle function

If anyone wants to take a stab at this and post some example code would be great...
Thanks agian for any help...
Im such a bother lol.. :oops:
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

This is example for my key events..
if
((event.EventType == EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_SPACE:{
return mouse2 = true;
}break;
return false;
}
}


If I wanted to make this loop I figured that doing it this way would work..


while(mouse2==false)
((event.EventType == EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_SPACE:{
return mouse2 = true;
}break;
return false;
}
}

if
((event.EventType == EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_SPACE:{
return mouse2 = false;
}break;
return false;
}
}
something kinda like this...
but when I try to use (while) I get compile errors saying unexspected end of program or something like that..
My C++ skills are so poor lol.. I just hope in time I get the hang of it lol..

Basically I want to do something just like above but with the right mouse button .
Ive got a working vertion of this but it uses two diff keys the tab and space.. I also have the same problem figureing out how to make it loop as well... The flow of control works one time just perfectly but then is dead afterwards and the program goes on like the key events are just not there..
Its cause its not looping back to the start again.. Ive got some tutorials on useing loops but is for C and not C++ im wondering if there is a diff between the way this is done now with C++..?
Well any help here or code id thank you much for..
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

lets see a loop...like this?

int looptoggle = 0;

if (looptoggle == 2) {looptoggle = 0};

if (looptoggle == 1) { //this is where the toggle would be on and does something }

almost forgot the most important part... making the mouse button ++looptoggle...silly me

there are much better ways of using math and code to create toggles with less charicters and more efficiency but this should work just as well for now...

good luck

P.S. there are plenty of great free C++ tutorials available even ones based on game design try using google instead of the other shitty search engines and see what you find =)
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Hell yea I always use google... Im not sure what I would do without it lol..
Thanks for the help ill see what I can do with it...
Its great to see a forum that people actually help lol..
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Well actually I gues I could just say what im doing and this would probably help a lot...
I set up my code with the getCursorControl()->setVisible = true or false,
I also added the camera->setInputReceiverEnabled = tue or false.

Ive got the two if commands set up rather much like above but two of them..
mouse1
mouse2
for starting point I just used two keyboard keys, Tab and Space.
When event is true for mouse1

}
if(mouse1){
camera->setInputReceiverEnabled(false),device->getCursorControl()->setVisible(false);
}



When event is true for mouse2

if(mouse2){
device->getCursorControl()->setVisible(true),camera->setInputReceiverEnabled(true);
}


This system works great for a one shot deal lol..
Im so bad in my code stage at this moment that I cant figure out how to set up a way to loop the events ..



if
((event.EventType == EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_SPACE:{
return mouse2 = true;
}break;
return false;
}
}
if ((event.EventType == EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_TAB:{
return mouse1 = true;
}break;
return false;
}
}


The flow of control is only a one shot deal.. I tried to add while loops and I got compile errors... lol.. :cry: Sad .. my coding is like I said not very good .... But you have to work at it in order to figure it out lol..
Basically this enables the active camera in fps and hides the mouse cursor then the other key sets in reverse and gives back the cursor and mouse movement from the fpcamera so that you can click inside of another window... In my case will be the chat client for my game..

The main thing is when I do figure out how to make the system I have now work Ill need to figure out how to use the mouse events and then Id like to see this system work with just one mouse button, The right mouse button..
Clicking one time enables and clicking agian disables...
Im sure the method Im using now will work in a simalar fashon the same way with the mouse events... I was shocked in fact that these values changed on the fly like this, I figured that these two where loaded on start of the engine and stayed that way...
I saw a example that somene else did with this same thing in mind but there code example is huge...? Im sure that with a loop my code here would work just as well...

So with this code and detailed info on what im doing ( I should have just done this in the first place sorry ) I hope that this will help others understand what im tring to get to work...

Thanks for any help..
Kande
Posts: 19
Joined: Fri Sep 10, 2004 9:37 pm
Location: Mannheim / Germany
Contact:

Post by Kande »

First of all..... to be honest.... i dont really know what you want. But i guess it.

So, you want Mouse1 which is boolean to change its value between true and false, everytime you press the mouse button..... thats what i guess you want.

The solution would be, without testing it (in Germany now its 3:35 in the morning and i am about to go to bed) Initialize Mouse1 to false:

Mouse1 = false;

And everytime when the clicking event arrives set it like this:

Mouse1 = !Mouse1;

So the value changes from false to true and from true to false.
Life is expensive..... but a trip around the sun is included.
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Kande, how could I make this boolean vble work? :

bool particles = false;

and then make it switch from:

ps->setParticleSize(core::dimension2d<f32>(20,20));

to

ps->setParticleSize(core::dimension2d<f32>(0,0));

to make the particle emitter turn on and off?

ps. i already assigned "P" in my event receiver to do this but when I say:

if (particles)
ps->setParticleSize(core::dimension2d<f32>(0,0));

It turns the particles off, but it's not boolean, so I can't get it back on.

thnx!
Image
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

lol sounds like same problem im having but with events for diff things.. Mine works great for a one shot deal but then is done afterwards.. Im going to check out what the difference is from my code using
Mouse1 = true or false; to this one...
Mouse1 = !Mouse1;
Im not sure what the ! dose as I cant remember ill have to refresh my code for my head by looking it up agian.. lol.. :oops:

Thanks for the help agian...
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

I must say Kande YOU ARE A GENIUS.... Yea it works..
Now if when you get the time you could exsplain why this works lol..

Wow im thrilled to death like I said I would be...
Now to change the code over to use my mouse insted lol...

Thanks a ton... :lol:
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

@afecelis, maybe I don' understood you well but...
Why do you use these functions with particle size =0?
IParticleSystemSceneNode is derive many properties from ISceneNode base class, so use some like this

Code: Select all

ps->setVisible(true);
if(ps->isVisible ())
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

thnx captor!
your tip gave me the solution!!!

now I got a question.

setvisible only works with particles or it may be used with any node?

thnx!!!

:D
Image
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

With almost all nodes, if in base class of them this property is defined like "public" or "protected".
Kande
Posts: 19
Joined: Fri Sep 10, 2004 9:37 pm
Location: Mannheim / Germany
Contact:

Post by Kande »

! in c/c++ is the negation operator. This means if Mouse1 is true !Mouse1 is false. Thats why Mouse1 = !Mouse1; just changes the value to its opposite. But i wasnt sure if irrlicht is sending the event in every cycle as long as the mouse button is pressed. In this case it wouldnt have worked. But it looks like its just sending the message once, when the mouse button was clicked, thats good.
Life is expensive..... but a trip around the sun is included.
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Well It works ... I just cant belive that it took something so simple to make it work... I had the code very close on my end (not the example I posted) but was missing some way to loop it.. It was working fine like I said one time around but wasnt working a second time...
And I think that ! symbol was covered in one of my old C introduction manuals around here some place.. I do need to do more study on the changes from C to C++... :? Well actually I need to do more period lol..
But the hands on working with this engine is a great way for me to learn more.. The help in this forum has been great as well..
Anyway it works great lol , Ive changed it all over to one mouse key now and it toggles both of my funtions from true back to false now enabling the mouse to appear back on screen and halting the camera and then back visa versa..
Again thanks for all your great help... :)
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

there is a loop like the above example in the program I just released...

I have included the source and you may learn alot from it go download it...


Here http://irrlicht.sourceforge.net/phpBB2/ ... 3241#23241
Post Reply