Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Outerra Tech Demo download. Help with graphics driver issues

Pages: 1 [2]

Author Topic: External Dynamic Data  (Read 11781 times)

dac

  • Jr. Member
  • *
  • Posts: 14
  • newbie
Re: External Dynamic Data
« Reply #15 on: September 19, 2014, 02:23:19 am »

Great thank you, input would be on lat/lon and possibly alt, using the highest level of either ground or sea-level would also be good.
Logged

dac

  • Jr. Member
  • *
  • Posts: 14
  • newbie
Re: External Dynamic Data
« Reply #16 on: October 21, 2014, 06:49:32 am »

Hey sorry to keep bugging about this, has there been any update?

Thanks
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: External Dynamic Data
« Reply #17 on: October 22, 2014, 01:59:16 pm »

Sorry I didn't have time to check it yet. I did a quick test, but encountered some issues. Some quick code to look at (sea level placement):

Code: [Select]
  var world,igc,vehicle;

  function ll2xyz(lon,lat) {
    const R = 6378135;
    const rad = Math.PI/180.0;
    var fc = Math.cos(lon*rad);
    var fs = Math.sin(lon*rad);
    var ac = Math.cos(lat*rad);

    return [R*fc*ac, R*fs*ac, R*Math.sin(lat*rad)];
  }

  if(!world) world = $eview.$query_interface("ot::js::world.get");
  if(!igc) igc = $eview.$query_interface("ot::js::igc.get");
  if(world && !vehicle) {
    var c = map.getBounds().getCenter();    //this is from google maps object
    var pos = ll2xyz(c.lng(), c.lat());
    vehicle = world.create_instance("outerra/ddg/ddg", pos, {x:0, y:0, z:0, w:1}, false);
  }
Logged

dac

  • Jr. Member
  • *
  • Posts: 14
  • newbie
Re: External Dynamic Data
« Reply #18 on: December 09, 2014, 04:45:59 am »

Thanks for your work, i've yet to get anything to function though.

I'm invoking your example code from the Google map load() code, the map loads fine (and I assume the code?) but no vehicles are being created.

It seems to evaluate correctly and execute the create commands but as I mentioned, nothing is being created at the map center.
Do you have it working on your end? Any suggestions?

As always, thanks,

DaC
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: External Dynamic Data
« Reply #19 on: December 18, 2014, 04:11:44 am »

Sorry, there was a bug in that code (erroneously pasted an older one). The ll2xyz function should return {x:R*fc*ac, y:R*fs*ac, z:R*Math.sin(lat*rad)};

Note that this places objects on the sea level, so they will be under the terrain elsewhere. To correct that, add the result of world.elevation(pos) to R.
Logged

dac

  • Jr. Member
  • *
  • Posts: 14
  • newbie
Re: External Dynamic Data
« Reply #20 on: December 19, 2014, 06:57:49 am »

Thank you however there's still some issues. Here's the code I got working if others are interested. There seems to be some issues with getting the map.getBounds().getCenter() however you can also just hardcode a value in for testing. There were also a missing w variable in the pos returned.



Code: [Select]
   
function spawnVehicle(){
if(!world) {
world = $eview.$query_interface("ot::js::world.get");
}

if(!igc) {
igc = $eview.$query_interface("ot::js::igc.get");
}
 
if(world && !vehicle) {

                //Hardcoded values, lat lon in decimal
lat = 55.66393055555555;
lon = 12.640802777777777;

var pos = ll2xyz(lon, lat);
vehicle = world.create_instance("outerra/ddg/ddg", pos, {x:0, y:0, z:0, w:0}, false);

  }
}

function ll2xyz(lon,lat) {
    const R = 6378135;
    const rad = Math.PI/180.0;
    var fc = Math.cos(lon*rad);
    var fs = Math.sin(lon*rad);
    var ac = Math.cos(lat*rad);

return {x:R*fc*ac, y:R*fs*ac, z:R*Math.sin(lat*rad), w:1};
  }

This will create a ship somewhere near the coast of Denmark.

Any way to rotate the vehicle in creation or after it's been created? Or setting speed, modifying position of an already created vehicle etc?
« Last Edit: December 19, 2014, 07:09:26 am by dac »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: External Dynamic Data
« Reply #21 on: December 19, 2014, 09:52:44 am »

There's no w in position, because it's just a 3D world position. Also, the rotation quaternion should not be all zeros, the last w should be 1 for no rotation from default ECEF frame.
I tested it with map.getBounds().getCenter(), what problems did you have?

Once you get reference to the vehicle, you can use set_pos and set_rot methods to adjust its position and rotation. You can't set the speed directly, because that's a function of vehicle script, of its reaction to throttle and other inputs.
Logged

dac

  • Jr. Member
  • *
  • Posts: 14
  • newbie
Re: External Dynamic Data
« Reply #22 on: December 19, 2014, 10:04:36 am »

You are correct about w, I got it mixed up with the w in the create_instance where it will crash if there's no w :)

If I use the map.getBounds().getCenter() it doesn't seem to execute anything (I'm guessing a Javascript error that I'm unable to see). Using a hard-coded values fixes that.

Using vehicle.set_rot(x); crashes the program with an
Quote
Fatal error exception - error reading struct opening token
but maybe the create_instance doesn't return the vehicle object?

As always,

Thank you
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: External Dynamic Data
« Reply #23 on: December 19, 2014, 01:59:59 pm »

set_rot expects a quaternion, as an object with x y z w members. With quaternions you actually need to provide all of them, unlike with vectors where the missing elements are set to 0. That's what you probably meant by crashing with no w.
Logged
Pages: 1 [2]