PDA

View Full Version : Latitude, Longitude, Altitude to XYZ (Lscript Newbie)



Meaty
07-03-2003, 06:11 PM
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);

}

Meaty
07-03-2003, 10:00 PM
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

Meaty
07-03-2003, 10:39 PM
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 :(

Meaty
07-03-2003, 11:45 PM
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...

www.deadpixelsociety.com/lscripts/latlongalt_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.

Meaty
07-04-2003, 10:50 PM
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.

www.deadpixelsociety.com/lscripts/latlongalt_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

faulknermano
07-05-2003, 04:26 AM
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:




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.

Meaty
07-05-2003, 09:44 AM
faulknermano,

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

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

www.deadpixelsociety.com/lscripts/latlongalt_to_xyz.ls
www.deadpixelociety.com/lscirpts/atest.txt

faulknermano
07-05-2003, 07:19 PM
Originally posted by Meaty
faulknermano,

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

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

www.deadpixelsociety.com/lscripts/latlongalt_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?

Meaty
07-05-2003, 07:33 PM
whoops... apparently i cant spell "lscripts" or "society" ;)


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

thanks

faulknermano
07-05-2003, 08:08 PM
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).

Meaty
07-05-2003, 08:51 PM
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

Meaty
07-06-2003, 02:01 PM
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/lscripts/latlongalt_to_xyz.ls
http://www.deadpixelsociety.com/lscripts/atest.txt

faulknermano
07-07-2003, 06:25 AM
a quick answer: the tab token can be expressed as



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.

faulknermano
07-07-2003, 06:28 AM
btw: to insert code in the forum...

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


hope that makes sense.

Meaty
07-07-2003, 07:35 AM
thats it! thanks!

ahh what a great start to my lscripting career!

thanks for all the help faulknermano!

vitruvian
10-16-2013, 02:02 PM
Its possible repost the script link ? Thanks in advance