SDK Question How can I read a VECTOR3 string from a scenario file?

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
Hi all!
I have a little, stupid question.
I'm trying to read a VECTOR3 value from a string stored in the scenario file. Now I suppose that the procedure should be this one:

Code:
void padqacont::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
char *line;

while (oapiReadScenario_nextline (scn, line)){
....
...
else if( !_strnicmp(line, "VENTING1_OFS", 12 )) 
  sscanf (line+12, "%1f%1f%1f", &ex_main_a_x,&ex_main_a_y,&ex_main_a_z);
......
......
.....
..... 
else  ParseScenarioLineEx (line, vs);
	}
}

And this one:

....
....
....
VENTING1_OFS 0 12 3
...
...
,,,

is the string in the scenario file.
Unfortunatley read values are not 0, 12, 3 but some big, incredible values like 8453600000000000000.000000 and more. I realized this because i saved again these numbers in the scenario file by using oapiWriteScenario_vec (scn, "VENTING1_OFS", ex_main_a); function. This is very bad to me :shrug:

Someone can help me fixing this issue?
Thanks a lot!
 
I pretty sure that sscanf does the conversion from scientific notation (1.234564124321654e23) to the correct value and that sprintf does the opposite conversion too. Just keep in mind that a float can't hold a huge number.

However, I think you should add spaces in the sscanf call. Like this:
Code:
sscanf (line+12, "%1f %1f %1f", &ex_main_a_x,&ex_main_a_y,&ex_main_a_z);
 
You don't need to use spaces in there at all.

Did you try to set a breakpoint at the sscanf line and check if the value is set correctly after you step through it?

Are ex_main_a_[x-z] of double precision type?
 
I pretty sure that sscanf does the conversion from scientific notation (1.234564124321654e23) to the correct value and that sprintf does the opposite conversion too. Just keep in mind that a float can't hold a huge number.

However, I think you should add spaces in the sscanf call. Like this:
Code:
sscanf (line+12, "%1f %1f %1f", &ex_main_a_x,&ex_main_a_y,&ex_main_a_z);

I've done it, but without results.. values are the same.. I'm surprised because a gave a look to Delta Glider source code and i noticed that the developer did the same thing in the same way, and it works.. just 2 values are stored instead of 3, actually. They refers to nose cone animation state and position.

I'm afraid that the only way i have to solve the problem is to store my values in single number strings, but i don't like that approach because it makes scenario file very long.. I hope to find an option for me:lol:
 
How are ex_main_a_x, ex_main_a_y, and ex_main_a_z variables declared?

Does the sscanf line get hit in debugger when you set a breakpoint on it?
 
Guess:
Try writing your variables as floats with a decimal point, so they can be recognized as such. That is, write in the scenario file:
0.0 12.0 3.0

The idea came to me, when I saw the Delta glider code never reads a sequence of floats, but alwas first an integer, then a float:

} else if (!_strnicmp (line, "GEAR", 4)) {
sscanf (line+4, "%d%lf", &gear_status, &gear_proc);
 
Code:
sscanf (line+12, "%1f%1f%1f", &ex_main_a_x,&ex_main_a_y,&ex_main_a_z);

Looks like a typo to me. If you have declared ex_main_a_x to _z as doubles, use "%lf" instead of "%1f".

I'm not sure if a width specifier even makes sense in this context. Therefore I guess you simply misread "l" for "1", a very common mistake.
 
Looks like a typo to me. If you have declared ex_main_a_x to _z as doubles, use "%lf" instead of "%1f".

I'm not sure if a width specifier even makes sense in this context. Therefore I guess you simply misread "l" for "1", a very common mistake.

Yes, that was the mistake! It works fine now!
I can't believe i spent one and a half day searching the problem everywhere just to realise I miread 1 instead of l

:beathead:

Thanks a lot
 
Back
Top