Anteworld - Outerra Game > Modding: Importer, Tools & Utilities

ray casting tests

(1/2) > >>

fly77:
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: ---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 )
--- End code ---


--- Code: ---   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 );
--- End code ---

cameni:
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.

fly77:
thank you very much ! Works fine  :)

fly77:
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: --- 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})
--- End code ---

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 ?


cameni:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version