Outerra forum
Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => Topic started by: fly77 on January 28, 2019, 02:20:56 pm
-
Hi. I am trying to get a camera that allows freely moving inside a vehicle - namely an aircraft carrier - while still having its controls. To set the direction of camera movement I use the direction of the mouselook from
the this.get_fps_camera_rot(base = false) command and then register axis to compute increments camx, camy,camz that I then use to set the fps camera positions using command this.set_fps_camera_pos({x: camx,y: camy,z : camz}); Everything works reasonably fine except that the mouse look when in fps mode (v-keys) inside a vehicle seems limited to 360 deg or even less. What I mean is that I cannot turn my head more than +/-180 deg (or actually it seems even less, maybe +/-170 deg) which of course limits the freedom of movement of my "free-fps camera". Since this limit does not exist when in "external camera mode" (key-c when in vehicle) I wonder if it is possible to disable this limit for the fps camera ? Interestingly using track-IR the same limits exist but these limits can be shifted by using the mouse while looking around with track-IR. So it seems there should also be a way to remove or extend these limits when using just the mouse to look around...at least I hope so.
-
set_fps_camera_pos sets where you stand, with your body facing in the direction of what was set by set_fps_camera_rot, by default vehicle forward.
The limit is for the neck, but it should be relative to the fps body rotation set.
-
Thanks a lot for the hint. Allthough i struggle still with quaternions I got it working by fiddling around somehow, even though i don't understand completely why it should be like that.
To extend the range beyond the neck limit I multiplied the yaw angle camrot.y obtained from the mouse command this.get_fps_camera_rot(false) by a factor 1.5 (or maybe PI/2)
in the angle that controls camera movements and a factor PI (or maybe its PI/2?) in this.set_fps_camera_rot that controls body (fps) rotation. Seems reasonable. In any case now it works as I wanted and I can move freely around my
aircraft carrier deck ! ;)
function toQuaternion( pit, roll, yaw)
{
// Abbreviations for the various angular functions
var cy = Math.cos(yaw * 0.5);
var sy = Math.sin(yaw * 0.5);
var cr = Math.cos(roll * 0.5);
var sr = Math.sin(roll * 0.5);
var cp = Math.cos(pit * 0.5);
var sp = Math.sin(pit * 0.5);
var Quat = [];
Quat.w = cy * cr * cp + sy * sr * sp;
Quat.x = cy * sr * cp - sy * cr * sp;
Quat.y = cy * cr * sp + sy * sr * cp;
Quat.z = sy * cr * cp - cy * sr * sp;
return Quat;
}
function update_frame(dt, engine, brake, steering){
camrot= this.get_fps_camera_rot(false);
camx = camx + 0.1*camystep*Math.cos(1.5*PI*camrot.y ) - 0.1*camxstep*Math.sin(1.5*PI*camrot.y );
camy = camy + 0.1*camystep*Math.sin(1.5*PI*camrot.y ) + 0.1*camxstep*Math.cos(1.5*PI*camrot.y );
this.set_fps_camera_pos({x:camx, y: camy,z : camz});
this.set_fps_camera_rot( toQuaternion( 0, PI/2, PI*camrot.y), 2 );
}