added normal vector to raycast results

This commit is contained in:
devZoGok
2022-10-29 21:19:02 +03:00
parent 5bc6bce1c5
commit 186bd47c69
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -26,8 +26,8 @@ namespace vb01{
for(int i = 0; i < numVerts / 3; i++){
Vector3 pointA = pos + rot * vertices[indices[i * 3]].pos, pointB = pos + rot * vertices[indices[i * 3 + 1]].pos, pointC = pos + rot * vertices[indices[i * 3 + 2]].pos;
Vector3 hypVec = pointA - rayPos;
Vector3 perpVec = (pointB - pointA).cross(pointC - pointA);
float a1 = hypVec.norm().getAngleBetween(perpVec.norm());
Vector3 perpVec = (pointB - pointA).cross(pointC - pointA).norm();
float a1 = hypVec.norm().getAngleBetween(perpVec);
if(a1 > PI / 2){
a1 = PI - a1;
@@ -35,7 +35,7 @@ namespace vb01{
}
float perpLine = hypVec.getLength() * cos(a1);
float a2 = perpVec.norm().getAngleBetween(rayDir.norm());
float a2 = perpVec.getAngleBetween(rayDir.norm());
if(a2 <= PI / 2){
float distance = perpLine / cos(a2);
@@ -55,6 +55,7 @@ namespace vb01{
if(withinBisecA && withinBisecB && withinBisecC){
CollisionResult result;
result.pos = contactPoint;
result.norm = -perpVec;
result.distance = distance;
result.mesh = m;
results.push_back(result);
+1 -1
View File
@@ -10,7 +10,7 @@ namespace vb01{
class Ray{
public:
struct CollisionResult{
Vector3 pos;
Vector3 pos, norm;
float distance;
Mesh *mesh = nullptr;
};