Volumes Of Fun http://www.volumesoffun.com/phpBB3/ |
|
Mini optimization in Raycast http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=313 |
Page 1 of 1 |
Author: | Muchacho [ Fri Jan 13, 2012 5:59 pm ] |
Post subject: | Mini optimization in Raycast |
In the doRaycast() function. instead of : Code: float minx = floorf(x1), maxx = minx + 1.0f; float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) / std::abs(x2 - x1); float miny = floorf(y1), maxy = miny + 1.0f; float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) / std::abs(y2 - y1); float minz = floorf(z1), maxz = minz + 1.0f; float tz = ((z1 > z2) ? (z1 - minz) : (maxz - z1)) / std::abs(z2 - z1); float deltatx = 1.0f / std::abs(x2 - x1); float deltaty = 1.0f / std::abs(y2 - y1); float deltatz = 1.0f / std::abs(z2 - z1); rewrite to : Code: float deltatx = 1.0f / std::abs(x2 - x1); float deltaty = 1.0f / std::abs(y2 - y1); float deltatz = 1.0f / std::abs(z2 - z1); float minx = floorf(x1), maxx = minx + 1.0f; float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) * deltatx; // 1.0f / std::abs(x2 - x1) float miny = floorf(y1), maxy = miny + 1.0f; float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) * deltaty; float minz = floorf(z1), maxz = minz + 1.0f; float tz = ((z1 > z2) ? (z1 - minz) : (maxz - z1)) * deltatz; Not a bug deal, just less abs call, less subtraction, and overall less divisions. Sorry I have the "divide desease" for several months. ![]() Make me feel like Adrian Monk... |
Author: | David Williams [ Fri Jan 13, 2012 10:29 pm ] |
Post subject: | Re: Mini optimization in Raycast |
Thanks for this, I've made the change to Git master. I wouldn't update though as there's a few breaking changes going on at the moment. The code was based off Christer Ericson's book 'Real Time Collision Detection' so I was naturally curious about why he doesn't make this optimisation. But after looking back at it, it's because he supports traversing over a grid where each cell can be bigger than one (it's for spatial subdivision). In our case the cell size is always one, which enables the optimisation you suggest. |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |