Advertisement
Guest User

Untitled

a guest
Mar 9th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. public void raycast3D(float x0, float y0, float z0, float x1, float y1, float z1, RaycastResult result){
  2.     float dx = x1 - x0;
  3.     float dy = y1 - y0;
  4.     float dz = z1 - z0;
  5.    
  6.     if(dz >= 0){
  7.  
  8.         int startZ = (int)z0;
  9.         int endZ = (int)Math.ceil(z1);
  10.                
  11.         float xk = dx / dz;
  12.         float yk = dy / dz;
  13.    
  14.         for(int z = startZ; z < endZ; z++){
  15.             if(dy >= 0){
  16.  
  17.                 //calculate x, y position of z plane intersections with xk and yk
  18.                 //generate startY and endY of the 2D line between two z planes
  19.  
  20.                 for(int y = startY; y < endY; y++){
  21.                     if(dx > 0){
  22.                        
  23.                         //calculate x position of y plane intersections and generate startX and endX
  24.  
  25.                         for(int x = startX; x < endX; x++){
  26.                            testVoxelCollision(x, y, z);
  27.                         }
  28.                     }else{
  29.                         //Same as above, but loop over x backwards
  30.                     }
  31.                 }
  32.             }else{
  33.                  //Loop over y backwards, and then branch for x
  34.             }
  35.         }
  36.     }else{
  37.         //Loop over z backwards, and then branch for y and then x
  38.     }
  39. }
  40.  
  41. /*
  42. 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...
  43. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement