0
나는 광선 추적에 완전히 익숙하지 않아 실린더를 표시하는 데 문제가 있습니다. 구를 찾기위한 코드를 구현했으며 여기서 찾은 튜토리얼을 따르고 있습니다 : http://woo4.me/wootracer/cylinder-intersection/ 간단한 실린더 (무한 시작)를 추가하십시오. 다음 코드를 작성했지만 실린더에 어떤 좌표를 지정했는지에 관계없이 이미지에 단색의 평평한 표면이 표시됩니다. 누구든지 내가 잘못 가고있는 것에 대한 힌트를 줄 수 있습니까? 나는 3 일 동안 google을 검색했고 Stack Overflow를 검색했고 여러 가지 방법으로 포럼과 튜토리얼에서 아무 소용이 없는지 제안했다. 그래서 여기 누군가가 내가 잘못 가고있는 것을 볼 수 있을까 ?? 미리 감사드립니다 !! 내 프리미티브 '레이 교차 방법에서실린더를 사용한 간단한 광선 추적?
virtual double findIntersection(Ray ray){
Vect rayOrigin = ray.getRayOrigin();
double rayOriginX = rayOrigin.getVectX();
double rayOriginY = rayOrigin.getVectY();
double rayOriginZ = rayOrigin.getVectZ();
Vect rayDirection = ray.getRayDirection();
double rayDirectionX = rayDirection.getVectX();
double rayDirectionY = rayDirection.getVectY();
double rayDirectionZ = rayDirection.getVectZ();
//a=d x2 + d y2 b = ex d x + e y d y c = ex2 + e y2−1
double a = rayDirectionX * rayDirectionX + rayDirectionY * rayDirectionY;
double b = 2* rayOriginX * rayDirectionX + 2* rayOriginY * rayDirectionY;
double c = rayOriginX * rayOriginX + rayOriginY * rayOriginY - 1;
double discriminant = b*b - 4 * a*c;
if (discriminant > 0){
//ray intersects
double root1 = ((-1 * b - sqrt(discriminant))/2*a - 0.0001);
if (root1 > 0){
return root1; //first root is the smallest positive value
}
else{
double root2 = ((sqrt(discriminant) - b)/2*a - 0.0001);
return root2; //the second root is the smallest positive value
}
}
else{
//ray misses the Cylinder
return -1;
}
}
![enter image description here][1]};