Optimize Mapp:RotateVertex()

This function can get rather expensive and waste a surprisingly
large amount of time. Using moors as a test zone simply switching
from the C math API cos/sin to std::cos/std::sin seemed to help

11.11% Map::RotateVertex(glm::tvec3<float, (glm::precision)0>&, float, float, float)
4.16% Map::RotateVertex(glm::tvec3<float, (glm::precision)0>&, float, float, float)
This commit is contained in:
Michael Cook (mackal) 2016-07-10 23:18:26 -04:00
parent 402353affa
commit a9ff407657

View File

@ -897,18 +897,18 @@ bool Map::LoadV2(FILE *f) {
void Map::RotateVertex(glm::vec3 &v, float rx, float ry, float rz) { void Map::RotateVertex(glm::vec3 &v, float rx, float ry, float rz) {
glm::vec3 nv = v; glm::vec3 nv = v;
nv.y = (cos(rx) * v.y) - (sin(rx) * v.z); nv.y = (std::cos(rx) * v.y) - (std::sin(rx) * v.z);
nv.z = (sin(rx) * v.y) + (cos(rx) * v.z); nv.z = (std::sin(rx) * v.y) + (std::cos(rx) * v.z);
v = nv; v = nv;
nv.x = (cos(ry) * v.x) + (sin(ry) * v.z); nv.x = (std::cos(ry) * v.x) + (std::sin(ry) * v.z);
nv.z = -(sin(ry) * v.x) + (cos(ry) * v.z); nv.z = -(std::sin(ry) * v.x) + (std::cos(ry) * v.z);
v = nv; v = nv;
nv.x = (cos(rz) * v.x) - (sin(rz) * v.y); nv.x = (std::cos(rz) * v.x) - (std::sin(rz) * v.y);
nv.y = (sin(rz) * v.x) + (cos(rz) * v.y); nv.y = (std::sin(rz) * v.x) + (std::cos(rz) * v.y);
v = nv; v = nv;
} }