you can use any direction vector, it does not need to be normalized or anything.
do a regular polyvox raycast.
Code:
PolyVox::RaycastResult result;
PolyVox::Raycast raycast(&volume, position, direction, result);
raycast.execute();
while reading this i found out that all my math isn't necessary... how stupid of me not to see this...
the contact plane is the one where result.previousVoxel and result.intersectionVoxel have a different coordinate.
so I guess you'd make a simple if:
Code:
PolyVox::Vector3DFloat exactHitPosition;
if(result.previousVoxel.getX() == result.intersectionVoxel.getX() && result.previousVoxel.getY() == result.intersectionVoxel.getY()) {
// zplane is hitplane
// sig is computed as in previous post
now my mathbook says:
Quote:
n1*(p1 + r*u1) + n2*(p2 + r*u2) + n3*(p3 + r*u3) = b
where n1,n2,n3 is the plane normal, b is the plane offset, p1,p2,p3 is the vector hook point, u1,u2,u3 is the vector direction.
since we only have 3 different planes here which are aligned to 2 axis, only one of n1,n2,n3 is not zero an therefore 1 (normalized), simplyfying this to
Quote:
1*(p1+r*u1) = b
which can be rearranged to
Quote:
r = (b - p1)/u1
which is in code:
Code:
float r = (result.previousVoxel.getZ() + sig.getZ()*0.5 - position.getZ())/direction.getZ();
exactHitPosition = position + direction*r;
Code:
repeat this for the other planes...
} else if(xplane stuff here) {
// repeat for .getX()
} else if(yplane stuff here) {
// repeat for .getY()
} else {
// error
}
if your initial direction vector is messed up, all this won't help you... try dumping it and checking manually if it makes sense...