Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void raycast3D(float x0, float y0, float z0, float x1, float y1, float z1, RaycastResult result){
- float dx = x1 - x0;
- float dy = y1 - y0;
- float dz = z1 - z0;
- if(dz >= 0){
- int startZ = (int)z0;
- int endZ = (int)Math.ceil(z1);
- float xk = dx / dz;
- float yk = dy / dz;
- for(int z = startZ; z < endZ; z++){
- if(dy >= 0){
- //calculate x, y position of z plane intersections with xk and yk
- //generate startY and endY of the 2D line between two z planes
- for(int y = startY; y < endY; y++){
- if(dx > 0){
- //calculate x position of y plane intersections and generate startX and endX
- for(int x = startX; x < endX; x++){
- testVoxelCollision(x, y, z);
- }
- }else{
- //Same as above, but loop over x backwards
- }
- }
- }else{
- //Loop over y backwards, and then branch for x
- }
- }
- }else{
- //Loop over z backwards, and then branch for y and then x
- }
- }
- /*
- If this isn't eye cancer, I don't know what it is, and this is just around 1/8th of the code I will need to write...
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement