Author Topic: Mouse-controlled, after-death, free-roaming camera  (Read 20912 times)

0 Members and 1 Guest are viewing this topic.

Rodrigo Ribaldo

  • Duke
  • *
  • See you in August 20xx
    • View Profile
  • Faction: Neutral
  • M&BWB
Mouse-controlled, after-death, free-roaming camera
« on: September 04, 2010, 02:17:18 PM »
Here's the code for a WASD+mouse-controlled free-roaming camera. (I know you want it!)
I couldn't find any camera code I liked, so I wrote one for POP3 for Warband. The cameras I found either had clumsy extra keys for control, a limited camera, or didn't work for Warband.

It was based on kt0's simple after-death camera, but is much expanded:
http://forums.taleworlds.com/index.php/topic,63178.msg1641483.html#msg1641483

At the top of mission templates, add these declarations:
(click to show/hide)
In each mission you want to have the camera, add the triggers:
(click to show/hide)

You also need to disable Warband ending the battle after death, but you can do this yourself (or read kt0's post).

If you use the code, some credit would be nice.

EDIT: added "(neg|is_presentation_active, "prsnt_battle")," in the rotate triggers conditions, so the camera would not rotate wildly when you press Backspace.

EDIT2: lowered the number of triggers (from 8 to 4) and increased mouse sensitivity

FINAL EDIT: fixed spinning in windowed mode
« Last Edit: September 23, 2010, 08:42:40 AM by MadVader »

pampl

  • Veteran
  • *
  • Calradia's #1 drag queen
    • View Profile
  • Faction: Bandit
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #1 on: September 04, 2010, 09:21:06 PM »
Awesome, thanks for this.  One question: does it free-roam in all 3 dimensions or is it bound to the ground?  I'll be using it either way, just curious   :)

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #2 on: September 04, 2010, 09:31:27 PM »
Nice!  That's definitely an improvement over what I've got in Blood and Steel.  I'll use that for sure.  Suggestion: use E and Q for (absolute) up/down.

Oh, and:
Code: [Select]
common_vader_deathcam = [common_init_deathcam,common_start_deathcam,common_move_forward_deathcam,common_move_backward_deathcam,common_move_left_deathcam,common_move_right_deathcam,common_rotate_leftright_deathcam,common_rotate_updown_deathcam,]
« Last Edit: September 04, 2010, 09:34:17 PM by xenoargh »

Lumos

  • Probably Not a Help Desk
  • Moderator
  • *
  • Mens INsana in corpore sano
    • Steam - lumosx
    • YouTube - LumosX
    • View Profile
  • Faction: Nord
  • WBWF&SNWM&BVC
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #3 on: September 04, 2010, 09:47:50 PM »
Oh, and:
Code: [Select]
common_vader_deathcam = [common_init_deathcam,common_start_deathcam,common_move_forward_deathcam,common_move_backward_deathcam,common_move_left_deathcam,common_move_right_deathcam,common_rotate_leftright_deathcam,common_rotate_updown_deathcam,]
My thoughts precisely.... :D

Rodrigo Ribaldo

  • Duke
  • *
  • See you in August 20xx
    • View Profile
  • Faction: Neutral
  • M&BWB
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #4 on: September 04, 2010, 09:49:14 PM »
Awesome, thanks for this.  One question: does it free-roam in all 3 dimensions or is it bound to the ground?  I'll be using it either way, just curious   :)

Yes, it goes everywhere (ergo, free-roaming).

@xenoargh: thanks for the tip!

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #5 on: September 04, 2010, 10:03:06 PM »
I'll work on an auto-end script to plug into this, to end the missions if either side is out of troops, and something to keep the deathcam from going below the ground, as I get it integrated.  Looks good thus far :-)

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #6 on: September 05, 2010, 02:40:28 AM »
OK, tried it out.

Bad news:  upon death, the camera spun upwards constantly.  It was clear that everything else is working.

Looking at the script, it's got to be the sign.

<tests stuff>

After some testing, I've determined what's wrong.

Mouse position is constantly being reported as 50,40.

More testing.  Added fixed_point_multiplier to see finer detail.  Mouse position is constantly being reset to 497/402 over a short number of frames.  I think this is related to the mission_cam mode being set to 1.

My guess?  Mouse position is dependent on screen resolution.  Mouse position is constantly being reset.  Perhaps there's a way to allow the mouse free again.

AHA!!!

The reason why mouse position isn't being read correctly... is because the only time it registers a mouse position correctly is when a Presentation is on.  MadVader must have always had the cheater-radar on ;)

That means this can be fixed, yay :-)
« Last Edit: September 05, 2010, 03:08:53 AM by xenoargh »

Lumos

  • Probably Not a Help Desk
  • Moderator
  • *
  • Mens INsana in corpore sano
    • Steam - lumosx
    • YouTube - LumosX
    • View Profile
  • Faction: Nord
  • WBWF&SNWM&BVC
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #7 on: September 05, 2010, 07:56:43 AM »
Don't you have the "battle" presentation always on?
Oh, no, you didn't. But mods that always have it on (sort of), will they use it freely?

Rodrigo Ribaldo

  • Duke
  • *
  • See you in August 20xx
    • View Profile
  • Faction: Neutral
  • M&BWB
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #8 on: September 05, 2010, 08:12:43 AM »
In my tests, the mouse position is always reported as 500,375 (center of the screen) if you don't move the mouse. If you move it, it will change for a moment, then return to the center.

I didn't have any active presentations while testing - I don't think it will work with the battle presentation on, you may need to switch the camera on/off (e.g. put an extra condition in the rotate triggers like "(neg|is_presentation_active, "prsnt_battle"),").

The center coordinates above are for (set_fixed_point_multiplier, 1000). AFAIK, the coordinates are independent of resolution, but screen aspect ratio may change them (probably 500,400 in your case for the center) - I don't know if this is true, so any tests are appreciated.

You can change the code to capture the correct center coordinates in the start trigger or calculate them somehow, if they are the cause (and not the presentation).

EDIT: heavily edited
« Last Edit: September 05, 2010, 08:53:29 AM by MadVader »

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #9 on: September 05, 2010, 09:00:40 AM »
OK... here is a more-or-less complete rewrite, that fixes a lot of little issues:

1.  Triggers reduced to a minimal number.
2.  Dummy presentation included, so that cues from the mouse work properly, for those of us who don't trigger a Presentation during normal operations.
3.  End-sequence that counts the living Agents and automatically ends the Mission when one side or the other is all dead.
4.  Prevents the code from allowing underground movement.

The only fix I didn't include, because I'm lazy, is doing some matrix math to determine whether the camera's vector has resulted in the camera flipping over or has twisted sideways.  It's probably possible to do that, but it's very difficult without being able to get the matrix values.
module_mission_templates:
(click to show/hide)

module_scripts:
(click to show/hide)

And yes, I am absolutely sure that if you don't have a Presentation running and you're dead, it doesn't work- the mouse position gets reset to the center very, very fast (maybe 5-10 frames, for a big movement).  If you do run a Presentation, however, it returns useful numbers.
« Last Edit: September 05, 2010, 10:32:35 AM by xenoargh »

Rodrigo Ribaldo

  • Duke
  • *
  • See you in August 20xx
    • View Profile
  • Faction: Neutral
  • M&BWB
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #10 on: September 05, 2010, 09:41:08 AM »
I don't think an active presentation is needed, that may need a rethink. I would just prevent the rotate (mouse) trigger(s) from operating when prsnt_battle is active.
I'll have to run this by few testers, though, to see if they have a similar problem with mouse position resetting too fast for the triggers to catch.

The code: you'll need extra pairs of position_rotate_x around your position_rotate_z, if you don't want the camera to change its yaw (see original code). Nice work otherwise.





 

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #11 on: September 05, 2010, 10:31:51 AM »
IDK about the presentation thing, except that it absolutely didn't run as written, and that was what I eventually tracked down.  Could be driver-specific engine stuff going on, etc.

OK, here's a yaw-fixed version of the module_mission_templates script:

(click to show/hide)
...and I'll fix the one above.  Thanks for the assist, storing the original value as zero is very slick  :mrgreen:

Rodrigo Ribaldo

  • Duke
  • *
  • See you in August 20xx
    • View Profile
  • Faction: Neutral
  • M&BWB
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #12 on: September 05, 2010, 01:13:05 PM »
Updated the original code.
I really want to avoid running fake presentations, if the problem with different mouse settings/drivers can be solved by increasing mouse sensitivity in the code (and that's still iffy until more testing is done).

Rodrigo Ribaldo

  • Duke
  • *
  • See you in August 20xx
    • View Profile
  • Faction: Neutral
  • M&BWB
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #13 on: September 23, 2010, 08:36:00 AM »
Updated the code in the first post, the spinning problem for some players is now fixed.

Thanks to LittleMikey who found out the spinning problem (also xenoargh's complaint) occured only in windowed mode. The mouse idle position changes in windowed mode, so the mouse needs to be recentered, which is now handled in the code.

Idibil

  • External Developer
  • *
    • View Profile
    • Nova Regula
  • Faction: Nord
  • MP nick: Celt√≠beroIdibil
Re: Mouse-controlled, after-death, free-roaming camera
« Reply #14 on: September 25, 2010, 11:44:18 AM »
great work here!