diff options
Diffstat (limited to 'src/Models.cpp')
-rw-r--r-- | src/Models.cpp | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/Models.cpp b/src/Models.cpp index ad0f357..e706ebf 100644 --- a/src/Models.cpp +++ b/src/Models.cpp @@ -6,14 +6,11 @@ void Model::CalculateNormals() { - for (int i = 0; i < TriangleNum; ++i) { - CrossProduct(vertex[Triangles[i].vertex[1]] + for (int i = 0; i < TriangleNum; ++i) + normals[i] = normalize(crossProduct(vertex[Triangles[i].vertex[1]] - vertex[Triangles[i].vertex[0]], vertex[Triangles[i].vertex[2]] - - vertex[Triangles[i].vertex[0]], - normals + i); - Normalise(normals + i); - } + - vertex[Triangles[i].vertex[0]])); for (int i = 0; i < TriangleNum; ++i) { vArray[i*27+0]=vertex[Triangles[i].vertex[0]].x; @@ -128,10 +125,7 @@ int Model::LineCheck(XYZ p1,XYZ p2, XYZ *p) int intersecting=0; int firstintersecting=-1; XYZ point; - if(sphere_line_intersection(p1.x,p1.y,p1.z, - p2.x,p2.y,p2.z, - boundingspherecenter.x,boundingspherecenter.y,boundingspherecenter.z, - boundingsphereradius)) + if (segmentIntersectsSphere(p1, p2, boundingspherecenter, boundingsphereradius)) for (j=0;j<TriangleNum;j++){ intersecting=LineFacetd(p1,p2,vertex[Triangles[j].vertex[0]],vertex[Triangles[j].vertex[1]],vertex[Triangles[j].vertex[2]],normals[j],&point); if (intersecting == 0) continue; @@ -153,10 +147,7 @@ int Model::LineCheck2(XYZ p1,XYZ p2, XYZ *p, XYZ move, float rotate) p2=p2-move; if(rotate)p1=DoRotation(p1,0,-rotate,0); if(rotate)p2=DoRotation(p2,0,-rotate,0); - if(sphere_line_intersection(p1.x,p1.y,p1.z, - p2.x,p2.y,p2.z, - boundingspherecenter.x,boundingspherecenter.y,boundingspherecenter.z, - boundingsphereradius)) + if (segmentIntersectsSphere(p1, p2, boundingspherecenter, boundingsphereradius)) for (j=0;j<TriangleNum;j++){ intersecting=LineFacetd(p1,p2,vertex[Triangles[j].vertex[0]],vertex[Triangles[j].vertex[1]],vertex[Triangles[j].vertex[2]],normals[j],&point); if (intersecting == 0) continue; @@ -181,10 +172,7 @@ int Model::LineCheck2(XYZ *p1,XYZ *p2, XYZ *p, XYZ *move, float *rotate) *p2=*p2-*move; if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0); if(*rotate)*p2=DoRotation(*p2,0,-*rotate,0); - if(sphere_line_intersection(p1->x,p1->y,p1->z, - p2->x,p2->y,p2->z, - boundingspherecenter.x,boundingspherecenter.y,boundingspherecenter.z, - boundingsphereradius)) + if (segmentIntersectsSphere(*p1, *p2, boundingspherecenter, boundingsphereradius)) for (j=0;j<TriangleNum;j++){ intersecting = LineFacetd(*p1, *p2, vertex[Triangles[j].vertex[0]], @@ -213,10 +201,7 @@ int Model::LineCheck3(XYZ p1,XYZ p2, XYZ *p, XYZ move, float rotate, float *d) p2=p2-move; p1=DoRotation(p1,0,-rotate,0); p2=DoRotation(p2,0,-rotate,0); - if(sphere_line_intersection(p1.x,p1.y,p1.z, - p2.x,p2.y,p2.z, - boundingspherecenter.x,boundingspherecenter.y,boundingspherecenter.z, - boundingsphereradius)) + if (segmentIntersectsSphere(p1, p2, boundingspherecenter, boundingsphereradius)) for (j=0;j<TriangleNum;j++){ intersecting=LineFacetd(p1,p2,vertex[Triangles[j].vertex[0]],vertex[Triangles[j].vertex[1]],vertex[Triangles[j].vertex[2]],normals[j],&point); if (intersecting == 0) continue; |