Home   Help Search Login Register  

Author Topic: control camera with mouse  (Read 1951 times)

0 Members and 1 Guest are viewing this topic.

Offline LurchiDerLurch

  • Members
  • *
control camera with mouse
« on: 15 Nov 2009, 15:39:29 »
Hello,

anybody has an idea how to control a camera via mouse?

Just like the gunner view of a cobra for example...  :dunno:

thanks :clap:

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: control camera with mouse
« Reply #1 on: 16 Nov 2009, 10:42:18 »
While working on a "Free Cam" script some weeks (months?) ago I solved it like this:

Code: [Select]
... create and init the cam, then ...
(findDisplay 46) displayAddEventHandler ["MouseMoving", "_this call OnMouseMoving"];

OnMouseMoving = {
  _x = _this select 1;
  _y = _this select 2;
  ... now use _x and _y to rotate the cam (e.g. via camSetTarget) ...
};

HTH

EDIT: I just realized that we are talking about A1. displayAddEventHandler is an A2 command so the above won't work. Dunno how to do it in A1...   :(
« Last Edit: 16 Nov 2009, 10:58:48 by Worldeater »
try { return true; } finally { return false; }

Offline LurchiDerLurch

  • Members
  • *
Re: control camera with mouse
« Reply #2 on: 16 Nov 2009, 18:44:37 »
yeah no problem ;)

in A1 you can solve it with a dialog and then add the mouse moving eventhandler to the controls of the dialog.

I already did this.

I tried it by changing the position of the target which the camera is pointing at.

but the camera is a bit shaking and not very nice to control.  :(

how can i script this in detail please?

thanks

PS: sorry for my bad english ;)

Offline Zipper5

  • BIS Team
  • ****
Re: control camera with mouse
« Reply #3 on: 16 Nov 2009, 19:26:50 »
If you're using camera.sqs, there's a much simpler way of doing it. Go to your Controls options and select Bulldozer Controls from the drop down menu at the top of the window. Then modify the appropriate keys to use "Mouse Left", "Mouse Right", etc. Then you'll be able to control the direction of the camera with the mouse, and the movement with the keyboard. Or, you could even go one step further and map the movement controls to your joystick, giving you even more precise controls. Some people have done this in the past, with excellent results.

Hope that helps.

Offline LurchiDerLurch

  • Members
  • *
Re: control camera with mouse
« Reply #4 on: 17 Nov 2009, 13:56:44 »
yeah but i need this for a script... not a video ;)

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: control camera with mouse
« Reply #5 on: 17 Nov 2009, 21:09:10 »
One thing I did was update the position and the target of the camera at once:

Code: [Select]
OnMouseMoving = {
  ... collect data ...
};

OnKeyDown = {
  ... collect data ...
};

OnKeyUp = {
  ... collect data ...
};

ActivateCamera = {
  waitUntil {
    call UpdateCamera;
    isNull MyCamera;
  };
};

UpdateCamera = {
    ... feed the collected data to 'setPos' and 'camSetTarget', then ...
    MyCamera camCommit 0;
};


Another thing was to move the camera target further away to get a smoother rotation:

Code: [Select]
OnMouseMoving = {
  ...
  // XXX - These constants make it feel "not completely wrong". They were found via try and error.
  // TODO - Find a way to make it feel "right".
  _x = 2500 * (_this select 1);
  _y = 2500 * (_this select 2);
  _z = 2500 * 40;
  _y = _y * -1 // un-invert mouse
  NewCameraTarget = [_x, _z, _y];
  ...
};

ActivateCamera = {
  waitUntil {
    ...
    _target = MyCamera modelToWorld NewCameraTarget;
    MyCamera camSetTarget _target;
    ...
  };
};


This solution isn't perfect however. Maybe it would be better to use the mouse coordinates to rotate (and not just move) a fixed point around the camera position.
try { return true; } finally { return false; }