Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
ea70661f
Commit
ea70661f
authored
May 28, 2014
by
Martin Schultz
Browse files
* objLoader uses fast Atof implementation
parent
1ed3727b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/ACGL/OpenGL/Data/GeometryDataLoadStoreOBJ.cc
View file @
ea70661f
...
...
@@ -32,6 +32,39 @@ namespace
int
normal
;
};
// Really naive implementtion of atof but fast
// if parsing fails std::atof is used the format we expect is a float with a . as decimal point
float
fastAtof
(
const
char
*
_begin
,
const
char
*
_end
)
{
const
char
*
p
=
_begin
;
float
r
=
0.0
;
bool
neg
=
false
;
if
(
*
p
==
'-'
)
{
neg
=
true
;
++
p
;
}
while
(
*
p
>=
'0'
&&
*
p
<=
'9'
&&
p
<=
_end
)
{
r
=
(
r
*
10.0
)
+
(
*
p
-
'0'
);
++
p
;
}
if
(
*
p
==
'.'
&&
p
<=
_end
)
{
float
f
=
0.0
;
int
n
=
0
;
++
p
;
while
(
*
p
>=
'0'
&&
*
p
<=
'9'
&&
p
<=
_end
)
{
f
=
(
f
*
10.0
)
+
(
*
p
-
'0'
);
++
p
;
++
n
;
}
r
+=
f
/
std
::
pow
(
10.0
,
n
);
}
if
(
neg
)
{
r
=
-
r
;
}
if
(
p
<
_end
)
//we didnt reach the end something went wrong
return
std
::
atof
(
_begin
);
return
r
;
}
// Parses a string of space-separated numbers into a packed floating-point vector (_data) with a maximum number of _maxDimension elements
void
parseVector
(
const
char
*
_start
,
const
char
*
_end
,
int
_maxDimension
,
int
&
_dimension
,
float
*
_data
)
{
...
...
@@ -46,7 +79,7 @@ namespace
while
(
_dimension
<
_maxDimension
&&
it
<
end
)
{
found
=
std
::
find
(
it
,
end
,
' '
);
_data
[
_dimension
++
]
=
std
::
atof
(
it
);
_data
[
_dimension
++
]
=
fastAtof
(
it
,
found
-
1
);
it
=
found
==
end
?
end
:
found
+
1
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment