Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Bresenham won't help you here, I'm afraid...what you need are Ray/Line-Plane intersection algorithms:</p> <ul> <li><a href="http://en.wikipedia.org/wiki/Line-plane_intersection" rel="nofollow">Line-Plane intersection on Wikipedia</a></li> <li><a href="http://mathworld.wolfram.com/Line-PlaneIntersection.html" rel="nofollow">Line-Plane intersection on Wolfram</a></li> <li><a href="http://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm" rel="nofollow">Ray-Plane intersection on SigGraph</a></li> </ul> <p>In very rough mathy-pseudocode:</p> <p>(caveat:It's been a long time since I've done 3d graphics)</p> <pre><code>// Ray == origin point + some distance in a direction myRay = Porg + t*Dir; // Plane == Some point on cube face * normal of cube face (facing out), // at some distance from origin myPlane = Pcube * Ncubeface - d; // Straight shot: from ray origin to point on cube direction straightTo = (Pcube - Porg); </code></pre> <p>With these two equations, you can infer some things:</p> <ul> <li><p>If the dot product of 'straightTo' and the plane normal is zero (call this "angA"), your origin point is inside the face of the cube.</p></li> <li><p>If the dot product of the ray direction and the plane normal is close to 0 (call this "angB"), the ray is running parallel to the face of the cube - that is, not intersecting (unless you count if the origin is in the cube face, above).</p></li> <li><p>If (-angA / angB) &lt; 0, your ray is pointing away from the cube face.</p></li> </ul> <p>There's other stuff, too, but I'm already pressing the limits of my meager memory. :)</p> <p>EDIT: There <em>might</em> be a "shortcut", now that I think it though a bit...this is all assuming you're using a 3-d array-like structure for your "map".</p> <p>Ok, so bear with me here, thinking and typing on my phone - what if you used the standard old Bresenham delta-error algorithm, but "fixed" it into 2D?</p> <p>So let's say:</p> <ul> <li>We are at position (5, 5, 5) in a (10x10x10) "box"</li> <li>We are pointing (1 0 0) (i.e., +X axis)</li> <li>A ray cast from the upper-left corner of our view frustrum is still just a line; the definitions for "x" and "y" change, is all</li> <li>"X" in this case would be (mental visualization)...say along the axis parallel to the eye line, but level with the cast line; that is, if we were looking at a 2D image that was (640x480), "center" was (0,0) and the upper left corner was (-320,-240), this "X axis line" would be a line cast through the point (-320,0) into infinity.</li> <li>"Y" would likewise be a projection of the normal "Y" axis, so...pretty much the same, unless we're tilting our heads.</li> <li>Now, the math would get hairy as hell when trying to figure out what the next deltaX value would be, but once you'd figured out the formula, it'd be basically constant time calculations (and now that I think about it, the "X axis" is just going to be the vector &lt;1 0 0> projected through whatever your camera projection is, right?</li> </ul> <p>Sorry for the rambling, I'm on the train home. ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload