Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Latitude, Longitude, Altitude to XYZ (Lscript Newbie)

  1. #1
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458

    Latitude, Longitude, Altitude to XYZ (Lscript Newbie)

    Okay, I have offically taken the plunge into Lscript. It came upon a need to be able to parse lat/long/alt data from text file into layout to animate a Null.

    Okay, so I started off just trying to get my script to perform the lat, long, alt to x,y,z conversion, and I was actually successful. But I am afraid that is where my success stopped.

    The next step(s) i want to accomplish is to first be able to move a null and keyframe it given the lat, long, alt information. After that, I want to be able to do it in mass kinda like loading a motion file, but with just the columns lat,long,alt,frame# going straight down in a text file.

    Below is the code I have so far. Any help would be great, thanks.

    @script generic
    @name LATLONGTOXYZ
    @version 2.6

    generic
    {

    //CONSTANTS

    Re = 6378137; //Radius at equator
    E2 = 0; //Eccentricity squared


    //Draw the interface
    reqbegin("Lat. Long. to XYZ");

    c0 = ctlnumber("Latitude: ", 1);
    c1 = ctlnumber("Longitude: ", 1);
    c2 = ctlnumber("Altitude: ", 1);

    ctlposition(c0, 35, 5);
    ctlposition(c1, 35, 30);
    ctlposition(c2, 35, 55);


    return if !reqpost();

    //Get the values from the interface.

    lat = getvalue(c0);
    long = getvalue(c1);
    alt = getvalue(c2);

    //perform calcs

    reqend();
    x1 = (Re + alt) * cos(lat*PI/180) * cos(long*PI/180);
    y1 = ((1 - E2) * Re + alt) * sin(lat * PI/180);
    z1 = (Re + alt) * cos(lat * PI/180) * sin(long * PI/180);


    //Display the calcs.

    info("x = ",x1);
    info("y = ",y1);
    info("z = ",z1);

    }
    Chris Moschella

  2. #2
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    so i changed a few things and now i can return the x,y,zs to the object i chose... here is the code so far.

    @script generic
    @name LATLONGTOXYZ
    @version 2.6

    generic
    {

    //CONSTANTS

    Re = 6378137; //Radius at equator
    E2 = 0; //Eccentricity squared


    //Draw the interface
    reqbegin("Lat. Long. to XYZ");

    c0 = ctlnumber("Latitude: ", 1);
    c1 = ctlnumber("Longitude: ", 1);
    c2 = ctlnumber("Altitude: ", 1);
    c3 = ctlallitems("Object Name",object);
    c4 = ctlinteger("Frame",1);

    //ctlposition(c0, 35, 5);
    //ctlposition(c1, 35, 30);
    //ctlposition(c2, 35, 55);
    //ctlposition(c2, 35, 80);

    return if !reqpost();

    //Get the values from the interface.

    lat = getvalue(c0);
    long = getvalue(c1);
    alt = getvalue(c2);
    object = getvalue(c3);
    frame = getvalue(c4);

    //perform calcs

    reqend();
    x1 = (Re + alt) * cos(lat*PI/180) * cos(long*PI/180);
    y1 = ((1 - E2) * Re + alt) * sin(lat * PI/180);
    z1 = (Re + alt) * cos(lat * PI/180) * sin(long * PI/180);

    Position(x1,y1,z1); //return the value



    } //end

    okay, so it will move the object i select... how do i make it automatically set a keyframe? Do I need a process function? I read that most lscripts require one... but when ever i try to make one, i get the message, that it got an ':' expecting a '@'

    back to the drawing board
    Chris Moschella

  3. #3
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    OOOOOOHKAY!!!


    now I seem to be getting this slowly but surely.


    I added this as the last line before the end

    CreateKey(frame/30);



    it takes (time), so to actually put it on the keyframe i want, i have to divide it by 30. this assumes a 30 fps timescale too...


    /edit: i was looking at the manual all night... i had to go to the lscript commander and actually keyframe an object to figure out what the command was.... documentation seems a little backwards so far
    Last edited by Meaty; 07-03-2003 at 09:43 PM.
    Chris Moschella

  4. #4
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    oh, i am STILL trying to figure out how to get Lscript to parse data from a text file. I can't even seem to figure how to get a file requester working. Is that even possible in Lscript?

    The text would be formated in 4 colomns

    latitude longitude altitude frame


    any help would be much appreciated!

    oh and for anyone who wants the final lscript that converts latitude, longitude, and altitude to XYZs and keyframes it at the user input frame, here is the link...

    http://www.deadpixelsociety.com/lscr...galt_to_xyz.ls

    not bad for my first day of lscripting... eh?

    oh, right now, this script assumes a spherical earth, one of these days i will give it the eccentricity calculations.
    Chris Moschella

  5. #5
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458

    LScripting (DAY 2)

    okay, I seem to be having problems getting the script to actually load the file. I figured out the file load dialog and am using code theory from a script i saw on lw3d.org for my data parsing in the for loop. But i cant seem to get it to get the data out of the file.

    The error that comes up is invalid object method for linecount. I think that the method is okay, it is just that my script is not sucessfully opening the file into memory. If I can get beyond this point, i should be able to finish the rest of the script. Any help would be greatly appreciated.

    http://www.deadpixelsociety.com/lscr...galt_to_xyz.ls
    www.deadpixelociety.com/lscirpts/atest.txt


    edit: FYI - if some of the comments seem weird, they may have just gotten out of place
    Last edited by Meaty; 07-04-2003 at 09:58 PM.
    Chris Moschella

  6. #6
    your linecount is spelled: "lineCount".

    i think this is why you get your error messages.

    make sure that you always perform an if() check whether or not the file was properly opened:

    Code:
    f = File(myFile,"r");
    if(!f) error("Error reading file.");
    this way, you'll know _for sure_ whether or not the File Object Agent has indeed been assigned or not. avoid making assumptions on values in variables... test test and test. good luck.
    "The hardness of God is kinder than the softness of men, and His compulsion is our liberation." - C.S. Lewis


  7. #7
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    faulknermano,

    Thanks, the test works. Unfortunatly, by works i mean it says "Error reading file"

    i am rackin my brain here, and i know it is something small and silly. any other ideas? thanks

    http://www.deadpixelsociety.com/lscr...galt_to_xyz.ls
    www.deadpixelociety.com/lscirpts/atest.txt
    Chris Moschella

  8. #8
    Originally posted by Meaty
    faulknermano,

    Thanks, the test works. Unfortunatly, by works i mean it says "Error reading file"

    i am rackin my brain here, and i know it is something small and silly. any other ideas? thanks

    http://www.deadpixelsociety.com/lscr...galt_to_xyz.ls
    www.deadpixelociety.com/lscirpts/atest.txt

    i'm trying to download you atest.txt but have no luck. i tried adding an "s" to the deadpixelociety.com but no luck as well. could you check the link?
    "The hardness of God is kinder than the softness of men, and His compulsion is our liberation." - C.S. Lewis


  9. #9
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    whoops... apparently i cant spell "lscripts" or "society"


    http://www.deadpixelsociety.com/lscripts/atest.txt

    thanks
    Chris Moschella

  10. #10
    i got it.. hahaha... tricky bastard of a script eh?

    the main problem is where you put the getvalue(c6). you put it directly below ctlfilename().

    you have to put the getvalue() funcs AFTER reqpost(). try it.. and it will work..

    remember to change the if(!f) to if(!filedata) (corresponding to your variable name).
    "The hardness of God is kinder than the softness of men, and His compulsion is our liberation." - C.S. Lewis


  11. #11
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    hey thanks, i just tried it, and well... that part works now =] a new problem with the script though... always one right ... but i will play with it more tomorrow and post a question if i can't get it working, i gotta give it a try myself first

    thanks again faulknermano
    Chris Moschella

  12. #12
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458

    soooooo close!

    faulknermano,

    for an lscript newbie, i am pretty happy with my progress so far! heh, its been almost 3 years since my last, and only programming class, intro to c++.

    I actually have this script working now... sort of. My parse command doesnt seem to be working. But it is strange. Right now the list is tabulated because i copy and paste out of MS Excel into Notepad. So my data I am trying to parse looks like this.

    http://www.deadpixelsociety.com/lscripts/atest.txt

    Excel automatically tabulates(indents) the data when i paste it into Notepad. My parse command looks like this(side question, how do you do that 'code' thingy on this web board?)

    >>>code<<<
    __________________________________________
    (lat2,long2,alt2,frame2) = parse(" ",filestring);
    __________________________________________

    when I info(lat2); it returns "0|0|0|0" So it seems to be ignoring my token character specification.
    info(long2); and info(alt2); both come up nil.

    Now as a test, I took a couple of lines and changed them to be delimited by a comma instead. Like this.

    0,0,0,0
    5,0,0,1
    10,0,0,2
    15,0,0,3

    I also changed the parse command to accomodate the comma. The good news is it worked. The bad news is, that is fine for a few lines, but when i am passing in a thousand lines of data, manually formatting like that is not really an option.

    So I tried to copy the tabulation out of notepad and paste it into LSED and it gave me this square character ?_. I ran the script to no avail.

    So I guess, in the end, my question is, how do I parse a tabulation indent as a token character? Is it possible? I am guessing it should be. When we create motion files in Excel, they are tabulated in the exact same way.

    http://www.deadpixelsociety.com/lscr...galt_to_xyz.ls
    http://www.deadpixelsociety.com/lscripts/atest.txt
    Chris Moschella

  13. #13
    a quick answer: the tab token can be expressed as

    Code:
    blah = parse("\t",myLine);
    however, i havent checked if this is possible.

    if this doesnt work, i'll try to have your script a go and since what i can come with, if any.
    "The hardness of God is kinder than the softness of men, and His compulsion is our liberation." - C.S. Lewis


  14. #14
    btw: to insert code in the forum...

    (left bracket)code(right bracket) my code here... (left bracket)/code(right bracket)


    hope that makes sense.
    "The hardness of God is kinder than the softness of men, and His compulsion is our liberation." - C.S. Lewis


  15. #15
    Registered User Meaty's Avatar
    Join Date
    Feb 2003
    Location
    Arlington, VA
    Posts
    458
    thats it! thanks!

    ahh what a great start to my lscripting career!

    thanks for all the help faulknermano!
    Chris Moschella

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •