PDA

View Full Version : Scientific notation elimination


lehthanis
01-31-2008, 02:13 PM
I'm trying to get this x-plane exporter working better, an dI'm running into some problems with scientific notation. Here's my code that gets all my vertices:


for f = 1 to num_faces do
(
channel = 1
Face = getFace tmesh f
TFace = meshop.getMapFace tmesh channel f
TVx = meshop.getMapVert tmesh channel (TFace.x as integer)
TVy = meshop.getMapVert tmesh channel (TFace.y as integer)
TVz = meshop.getMapVert tmesh channel (TFace.z as integer)
for v = 1 to 3 do
(
case v of
(
1: (curVert = Face.x; curTVert = TVx)
2: (curVert = Face.y; curTVert = TVy)
3: (curVert = Face.z; curTVert = TVz)
)

Vert = getvert tmesh curVert
VertNorm = getNormal tmesh curVert

-- Write Vertex Entries to Array
if SwapYZ.state == true then
append AryVerts ("VT " + (Vert.x as string) + " " + (Vert.z as string) + " " + (Vert.y as string) + " " + (VertNorm.x as string) + " " + (VertNorm.z as string) + " " + (VertNorm.y as string) + " " + (curTVert[1] as string) + " " + (curTVert[2] as string) + "\n")
else
append AryVerts ("VT " + (Vert.x as string) + " " + (Vert.y as string) + " " + (Vert.z as string) + " " + (VertNorm.x as string) + " " + (VertNorm.y as string) + " " + (VertNorm.z as string) + " " + (curTVert[1] as string) + " " + (curTVert[2] as string) + "\n")
)
)



In the last bit there, I'd like to format all the numbers to force the 6th decimal place...no matter the value...

so 1 would be 1.000000...0 would be 0.000000 and you'd end up with numbers that looked like this:


VT -0.430012 0.847051 4.084560 1.000000 0.000000 0.000000 0.197092 0.280742
VT -0.430012 0.772286 3.990822 1.000000 0.000000 0.000000 0.085506 0.044315
VT -0.430012 0.860648 4.065142 1.000000 0.000000 0.000000 0.085506 0.280742
VT -0.430012 0.758689 4.010241 1.000000 0.000000 0.000000 0.197092 0.044315


The above code gives me numbers that look like this:

VT 0.0 -30.2629 -9.45448 0.000356122 -0.999623 0.0274562 0.500104 0.611589
VT 13.1409 -30.2629 -9.45449 4.54736e-007 -0.999433 0.0336666 0.900236 0.611589
VT 13.1564 -30.1539 -7.27129 -0.000549577 -0.999189 0.0402734 0.900706 0.678066
VT 13.1564 -30.1539 -7.27129 -0.000549577 -0.999189 0.0402734 0.900706 0.678066


and I'd like to make them all consistent...Any ideas? Thanks!

BTW...those two example numbers are from two different models, so they shouldn't "match" value wise...I just want to get them formatted the same...the first 4 are from a stock model that came with the program...the second 4 are from my own model exported using my code.

Bobo
01-31-2008, 02:20 PM
Have you tried FormattedPrint()? (Max 9 and higher)

lehthanis
01-31-2008, 02:50 PM
Wow Bobo! That was too easy. Thanks!

Here's what I used...


for f = 1 to num_faces do
(
channel = 1
Face = getFace tmesh f
TFace = meshop.getMapFace tmesh channel f
TVx = meshop.getMapVert tmesh channel (TFace.x as integer)
TVy = meshop.getMapVert tmesh channel (TFace.y as integer)
TVz = meshop.getMapVert tmesh channel (TFace.z as integer)
for v = 1 to 3 do
(
case v of
(
1: (curVert = Face.x; curTVert = TVx)
2: (curVert = Face.y; curTVert = TVy)
3: (curVert = Face.z; curTVert = TVz)
)

Vert = getvert tmesh curVert
VertNorm = getNormal tmesh curVert

VertX = formattedPrint Vert.x format:".6f"
VertY = formattedPrint Vert.y format:".6f"
VertZ = formattedPrint Vert.z format:".6f"
VertNormX = formattedPrint VertNorm.x format:".6f"
VertNormY = formattedPrint VertNorm.y format:".6f"
VertNormZ = formattedPrint VertNorm.z format:".6f"
VertU = formattedPrint curTVert[1] format:".6f"
VertV = formattedPrint curTVert[2] format:".6f"

-- Write Vertex Entries to Array
if SwapYZ.state == true then
append AryVerts ("VT " + VertX + " " + VertZ + " " + VertY + " " + VertNormX + " " + VertNormZ + " " + VertNormY + " " + VertU + " " + VertV + "\n")
else
append AryVerts ("VT " + VertX + " " + VertY + " " + VertZ + " " + VertNormX + " " + VertNormY + " " + VertNormZ + " " + VertU + " " + VertV + "\n")
)
)

CGTalk Moderation
01-31-2008, 02:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.