Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: ray casting tests  (Read 9615 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
ray casting tests
« on: August 21, 2019, 07:10:26 am »

I am trying to set up a gunsight for the abrams and I need to know the distance of the focussed target from the tank.
I tried with raycasting commands as below but get as result an object  instead of a distance for ray_test. Moreover object seems undefined and I get allways error TypeError: Object #<Object> has no method '.....'  when trying to retrieve any property of the object (such as .get_objurl() or .get_pos()) . If I try   .$ret.get_objurl()  I get error " Cannot call method 'get_objurl' of null" wherever I point the abrams even in mountains. The result doesn't change wether I point on terrain or onto a vehicle.
What's wrong ? Note that in writing the commands I left out ifc_out float3* norm and  ifc_out double3 as I get "wrong number of arguments" whatever I put there.

Code: [Select]
float ray_test( const float3& pos, const float3& dir, float maxdist, ifc_out float3* norm = 0, ifc_out double3* hitpoint = 0, uint joint = pkg::InvalidBoneId )
Code: [Select]
   var ray_test = this.ray_test( {x:0,y:0,z:0}, {x:0,y:1,z:0},100000, this.muzzle_id );
   var obj_test = this.object_test( {x:0,y:0,z:0}, {x:0,y:1,z:0},100000, true, this.muzzle_id );
« Last Edit: September 16, 2019, 03:45:47 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: ray tests
« Reply #1 on: August 26, 2019, 03:05:47 am »

Since JS doesn't have out parameters, the presence of any causes that the method returns a compound object with properties corresponding to out variable names. The return value becomes $ret in such object, hence you should test for ray_test.$ret, ray_test.norm and ray_test.hitpoint.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: ray tests
« Reply #2 on: August 26, 2019, 06:39:52 am »

thank you very much ! Works fine  :)
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: ray tests
« Reply #3 on: August 26, 2019, 04:53:40 pm »

is there a way to draw a line showing the ray ?
may ray direction moves with turret and mantlet rotations
I tried with sketch.draw_line as below but can't clear any line drawn previously (see screenshot)

Code: [Select]
var group = $sketch.create_group();
    $sketch.make_group_active(group);
    $sketch.attach_to_element(geom.get_inst_id(), true);
    $sketch.set_position(geom.get_joint_model_pos( this.muzzle_id ));
    $sketch.set_color(0xffffffff);
    $sketch.draw_line({x:  0, y: 0, z:0},false);
    $sketch.draw_line({x:  -Math.sin(armor_azimuth)*1000, y:Math.cos(armor_azimuth)*1000, z:Math.sin(armor_pitch)*1000})

How to clear a sketch ? Any documentation on sketch ?

Alternatively is there a way to attach a line to a joint in the canvas API ? or even better to draw from ECEF1 to ECEF2 ?


« Last Edit: August 26, 2019, 05:40:03 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: ray tests
« Reply #4 on: August 28, 2019, 09:42:20 am »

Sketch is a stupid api and I'd replace it if there weren't dependencies ...
I think you can only delete the group and create a new one each frame if you want it changing each frame.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: ray tests
« Reply #5 on: August 28, 2019, 01:15:21 pm »

Thank you. Indeed it works by deleting the group.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: ray tests
« Reply #6 on: September 01, 2019, 07:05:33 am »

I managed to attach a gunsight to the abrams gun using sketch API.
Unfortunately I couldn't do it the straigthforward way. First I tried to attach the sketch to the muzzle. I tried as below but the sketch doesn't move with the muzzle, whatever I use as arguments in  this.geometry.get_joint_local_pos or this.geometry.get_joint_model_pos
I also tried to attach a 3D gunsight geometry to the muzzle.
this.geometry.attach_geom( "outerra/gunsight/gunsight",'muzzle', {x:0,y:0.1,z:0}, unitquat);
I indeed can attach it as needed but as I zoom adjusting this.set_fps_camera_fov(fov_cockpit_zoom)
of course the 3D model gets viewed too big (no more hairline but big rods) and obstructs the view. So I discarded also this solution.

Code: [Select]
  var muzzle_pos = this.geometry.get_joint_local_pos(this.muzzle_id);
    // var muzzle_pos = this.geometry.get_joint_model_pos('muzzle');
     $sketch.set_position ({x:muzzle_pos.x ,y:muzzle_pos.y+1,  z:muzzle_pos.z});
     $sketch.draw_line({x:muzzle_pos.x,     y:muzzle_pos.y+1,  z:muzzle_pos.z},true);
     $sketch.draw_line({x:muzzle_pos.x+2, y:muzzle_pos.y+1 , z:muzzle_pos.z});
     $sketch.draw_line({x:muzzle_pos.x-2,  y:muzzle_pos.y+1,  z:muzzle_pos.z});
     $sketch.draw_line({x:muzzle_pos.x,     y:muzzle_pos.y+1,  z:muzzle_pos.z},true);
     $sketch.draw_line({x:muzzle_pos.x,     y:muzzle_pos.y+1,  z:muzzle_pos.z+2});
     $sketch.draw_line({x:muzzle_pos.x,     y:muzzle_pos.y+1,  z:muzzle_pos.z-2});

So a workaround that I found to make it work for the moment is to set the "draw origin" to  sketch.set_position(raytest impact point)
That is draw a scaled gunsight at the impact point so that I am sure to point at the impact point.  Viewed from the tank it looks as if it were part of the tank anyway. Another way is to sketch.set_position(raytest some point along the ray) eventually close to the muzzle.

In the first case I need to set x-ray mode on $sketch.set_xray_mode(true) since the lines will typically intersect with either terrain or objects;
I have noticed that any segment of line inisde an object or terrain is always white and so often hard to see...
(see image)

I managed to change the color of the segment that is "not inside any object or terrain" by
$sketch.set_group_color(0xffff00ff);
or
$sketch.set_color(0xff0000ff)
but the segment that is inside an object or inside terrain (x-ray) is always white.
Is it possible to change this "x-ray color ?" or is it supposed to be white ?

« Last Edit: September 01, 2019, 06:10:41 pm by fly77 »
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: ray tests
« Reply #7 on: September 04, 2019, 04:25:35 pm »

hmm..probably easiest way is to use canvas API and set the cross just in the middle of the screen and attach the fps camera to the gun.
Logged