Float Grid
BlitzMax Forums/BlitzMax Beginners Area/Float Grid
| ||
I can't figure out how to lock my objects to a grid based on a float value... I get that you do X/Grid*Grid, but Grid has to be an integer. If it's a float, it doesn't work. You could do Int(X/Grid)*Grid but that wouldn't lock a value to, for example, a 0.5 grid. Any help? |
| ||
Int(Grid*0.5)/2.0 |
| ||
Sorry, I don't quite get it. Grid can by anything from 0.01 to 1000. How would a dynamic number like that apply to your formula? |
| ||
You have a coordinate, and you want to snap it to some arbitrary step.GRID_SPACING:float = 0.5 'The distance between steps of the grid. coordinate:float = 771.3523 'Some random position of the object. 'First, get the fractional part of the result of dividing the coordinate by the grid spacing. division:float = coordinate / GRID_SPACING fractionalPart:float = division - Int( division ) 'The float value minus the integer version (with the decimal part truncated). 'Now you know where the object is positioned on the grid based on that fractional part. 'The fractional part will never be negative. The object is either at a grid step or between two grid steps (by some percentage). recommendedPosition:float = coordinate If fractionalPart = 0.0 'Object is already snapped to the grid. recommendedPosition = coordinate 'Object should remain there. Else If fractionalPart > 0.5 'Object is beyond the middle between two grid steps. recommendedPosition = ( Int( division ) + 1 ) * GRID_SPACING 'Go forward to the nearest grid step. Else recommendedPosition = Int( division ) * GRID_SPACING 'Go back to the nearest grid step. Endif Endif 'The variable 'recommendedPosition' holds the new coordinate that you need to assign to the object.Some more theory here: http://www.blitzbasic.com/Community/posts.php?topic=104929#1274455 |
| ||
Actually, I rather quickly realized that Int(X/Grid)*Grid DOES work. I was storing the final value as an integer though, so it was my fault all along! Thanks everyone. heh Another question though! I've made a quad with a grid texture on it. Anyone know how I can adjust the size of the grid texture? If I just resize the mesh or texture, the lines(on the texture) will get real tiny, almost invisible. So I can't do that... |
| ||
Use geometry instead of texture. |