Crystal Space
Welcome,
Guest
. Please
login
or
register
.
May 19, 2013, 05:04:50 pm
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
9223
Posts in
2230
Topics by
5382
Members
Latest Member:
Razasaqib
Crystal Space
Associate Projects
CEL Discussion
Mouselook in CEL achieved
« previous
next »
Pages:
[
1
]
Author
Topic: Mouselook in CEL achieved (Read 5224 times)
muffinpeddler
Full Member
Posts: 122
Mouselook in CEL achieved
«
on:
August 18, 2005, 09:43:27 pm »
Well, I finally figured out how to do a mouse look in CEL. I know several people were interested in this, since they couldn't find out how to do it through the docs. I had to look through source files for some of the info...should the documentation be expanded so these questions are stopped? Anyways, here is the run down:
First of all, make sure you bind mousex_centered and mousey_centered in your pccommandinput, and give it a useful action name. Adding _centered will make
it so that the mouse cursor is centered in the frame and you recieve the offset from ScreenToCentered():
Code:
pcinput->Bind("mousey_centered", "pitch");
pcinput->Bind("mousex_centered", "yaw");
Then, make sure you are getting the message ID just like everything else in your player behavior:
Code:
id_pccommandinput_yaw = pl->FetchStringID ("pccommandinput_yaw");
id_pccommandinput_pitch = pl->FetchStringID ("pccommandinput_pitch");
Then, in your player behavior SendMessage:
Code:
bool MyBehavePlayer::SendMessage (csStringID msg_id,
iCelPropertyClass* pc,
celData& ret, iCelParameterBlock* params,
va_list arg)
We get the amount offset from center (for how much to rotate) through the celData reference.
add this code:
Code:
else if (msg_id == id_pccommandinput_yaw)
{
if(ret.value.f > 0) {
float s = pcactormove->GetRotationSpeed(); //remember old setting for keyboard motion
pcactormove->SetRotationSpeed(ret.value.f*100);
pcactormove->RotateRight(true);
pcactormove->RotateLeft(false);
pcactormove->SetRotationSpeed(s); //reset setting
} else if(ret.value.f < 0) {
float s = pcactormove->GetRotationSpeed(); //remember old setting for keyboard motion
pcactormove->SetRotationSpeed(-ret.value.f*100);
pcactormove->RotateLeft(true);
pcactormove->RotateRight(false);
pcactormove->SetRotationSpeed(s); //reset setting
} else {
float s = pcactormove->GetRotationSpeed();
pcactormove->RotateRight(false);
pcactormove->RotateLeft(false);
pcactormove->SetRotationSpeed(s);
}
else if (msg_id == id_pccommandinput_pitch)
{
pccamera->MovePitch(-ret.value.f*0.3f);
}
...
You might have to fiddle with some of the float literals to get equal movement, I haven't done so yet.
This works for me so far, but I would like to hear from those more experienced with CEL whether this is a good approach or if there is something better. Again, I couldn't find this information anywhere, and moving the actor is a little odd, since I would rather move the camera with MoveYaw and MovePitch, but MoveYaw does nothing.
Good luck!
«
Last Edit: August 19, 2005, 01:11:50 am by muffinpeddler
»
Logged
rre
Guest
Re: Mouselook in CEL achieved
«
Reply #1 on:
October 08, 2005, 07:13:30 pm »
wow, I have been looking to do this for ages. thank you.
Logged
muffinpeddler
Full Member
Posts: 122
Re: Mouselook in CEL achieved
«
Reply #2 on:
October 09, 2005, 01:53:56 am »
You are very welcome, I'm glad it could help you.
As for the future, I believe Jorrit told me that there will be a new camera type that can handle mouse looking natively, so this hack will be obsolete.
Logged
jerwebb
Newbie
Posts: 10
Re: Mouselook in CEL achieved
«
Reply #3 on:
October 24, 2005, 10:43:26 pm »
Just wanted to thank muffin for this spot of code - exactly what I was looking for!
Logged
muffinpeddler
Full Member
Posts: 122
Re: Mouselook in CEL achieved
«
Reply #4 on:
October 25, 2005, 06:24:37 am »
Hey no problem, just trying to share my experiences.
Here is actually what I have come to use (with not a ton of testing) for the various values and what not. The problem is that the yaw and pitch are two separate things (actor, camera), so one must apply different values where necessary:
Code:
else if (msg_id == id_pccommandinput_yaw)
{
if(ret.value.f > 0) {
float s = pcactormove->GetRotationSpeed();
pcactormove->SetRotationSpeed(ret.value.f*70);
pcactormove->RotateRight(true);
pcactormove->RotateLeft(false);
pcactormove->SetRotationSpeed(s);
} else if(ret.value.f < 0) {
float s = pcactormove->GetRotationSpeed();
pcactormove->SetRotationSpeed(-ret.value.f*70);
pcactormove->RotateLeft(true);
pcactormove->RotateRight(false);
pcactormove->SetRotationSpeed(s);
} else {
float s = pcactormove->GetRotationSpeed();
pcactormove->SetRotationSpeed(0);
pcactormove->RotateRight(false);
pcactormove->RotateLeft(false);
}
}
else if (msg_id == id_pccommandinput_pitch)
{
pccamera->MovePitch(-ret.value.f*0.6f);
}
So far these values are acceptable.
Logged
jerwebb
Newbie
Posts: 10
Re: Mouselook in CEL achieved
«
Reply #5 on:
October 25, 2005, 03:49:47 pm »
Those values are pretty close to what I also came up with. I was also going to mention, that I set mine to work when the right mouse button was pressed. I had some troubles getting it to fly, initially, but I finally set a bool freelookmode to be true when pressed and false when not on "mouse2". Then I changed the code in the lines to:
Code:
else if (msg_id == id_pccommandinput_yaw && freelookmode)
else if (msg_id == id_pccommandinput_pitch && freelookmode)
Nothing earthshaking, but I thought I'd mention it if its handy to someone. Quick question - where can I find a list of the key triggers, such as "mouse1", and "mousey_centered"? I've looked around, and I'm not seeing it anywhere - in particular, I'm looking for mousewheel commands, but I'd really like all of them, eventually.
Logged
muffinpeddler
Full Member
Posts: 122
Re: Mouselook in CEL achieved
«
Reply #6 on:
October 25, 2005, 09:54:01 pm »
Oh, finding those is a real pain. From what I remember, there aren't very many different types (like axis, mouse, etc), but you would want to look at the input source file and look for the strings. You can look at the file on CVS here:
http://cvs.sourceforge.net/viewcvs.py/cel/cel/plugins/propclass/input/inpfact.cpp?rev=1.31&view=markup
And I think doing mouse stuff in the message function is okay, but I am having a horrible time with key messages. For example, when you hold down shift to run and w for forward, if you don't let them go in the right order, you keep moving forward with no keys down. Even with up and down messages being caught...Hmm...
Logged
griminventions
Newbie
Posts: 33
Re: Mouselook in CEL achieved
«
Reply #7 on:
October 26, 2005, 02:26:40 am »
The terrain demo uses shift for faster movement, maybe you could look there for an example?
Logged
jerwebb
Newbie
Posts: 10
Re: Mouselook in CEL achieved
«
Reply #8 on:
October 26, 2005, 03:29:46 pm »
Thanks for the link, muffin!
Handily enough, cel already has a function to handle running with the shift key (or whatever key you assign). Check the celtest demo. Also, you could handle it as I mentioned rather unclearly for my mouse button. First, in the key assignment, you do the obvious:
Code:
pcinput->Bind ("shift", "runmode");
Then in the bl you add:
Code:
id_pccommandinput_runmode1 = pl->FetchStringID ("pccommandinput_runmode1");
id_pccommandinput_runmode0 = pl->FetchStringID ("pccommandinput_runmode0");
Here is where I had trouble, until I just created a flag - in this case
Code:
bool runmode;
Code:
else if (msg_id == id_pccommandinput_runmode1)
runmode = true;
else if (msg_id == id_pccommandinput_runmode0)
runmode = false;
Code:
else if (msg_id == id_pccommandinput_forward0 && runmode)
and
Code:
else if (msg_id == id_pccommandinput_forward1 && runmode)
Hopefully, that's more clear than I was in my earlier post - anyway, I'd use the existing cel function, but I threw up the code for any other situations you want a key press combined with another. Likely, cel has a function already exisiting that works more elegantly, but this works great, with no bugs that I've noticed.
Logged
muffinpeddler
Full Member
Posts: 122
Re: Mouselook in CEL achieved
«
Reply #9 on:
October 26, 2005, 06:27:43 pm »
Now, try holding down a movment key, then shift, then let go of the movement, but keep shift down, then let go of shift. Are you still moving? That's the problem I am having, even with your code. Perhaps it's a bug in CEL, or it's a bug in my code, either way, it's not good.
Logged
jerwebb
Newbie
Posts: 10
Re: Mouselook in CEL achieved
«
Reply #10 on:
October 27, 2005, 01:41:32 am »
Aaahh, I forgot something - try this:
Code:
else if (msg_id == id_pccommandinput_runmode0)
{
runmode = false;
pcactormove->Forward(false);
}
Does the trick for me, I just forgot to include this line.
Logged
Alansmile
Newbie
Posts: 21
Re: Mouselook in CEL achieved
«
Reply #11 on:
April 10, 2013, 11:20:31 am »
Wholesale Nike NFL Jerseys
Wholesale NFL Jerseys
cheap nike nfl jerseys
,cheap nfl jersey,Cheap Jerseys On Sale,cheap soccer jerseys,
wholesale jerseys
jerseys shop, nfl nike jerseys,buy jerseys online, soccer jerseys shop online, nfl jerseys store online,wholesale ncaa jerseys
Logged
Pages:
[
1
]
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Crystal Space Development
-----------------------------
=> General Crystal Space Discussion
=> Support
-----------------------------
Crystal Space Project Development
-----------------------------
=> Feature Requests
=> Plugins
=> Bug Reports
-----------------------------
Crystal Space Development
-----------------------------
=> Game Content Creation
-----------------------------
Miscellaneous
-----------------------------
=> Article/Tutorial Requests
=> Article/Tutorial Discussion
-----------------------------
Crystal Space Project Development
-----------------------------
=> Development Discussion
-----------------------------
Crystal Space Projects
-----------------------------
=> Project Discussion
=> WIP Projects
=> Finished Projects
-----------------------------
Associate Projects
-----------------------------
=> CEL Discussion
=> Crystal Core Discussion
=> CrystalBlend Discussion
-----------------------------
Crystal Space Project Development
-----------------------------
=> Google Summer of Code
-----------------------------
Associate Projects
-----------------------------
=> Apricot (Open Game)
=> Ares Project
Loading...