about summary refs log tree commit diff
path: root/src/Models.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2023-11-18 21:40:15 +0900
committerNguyễn Gia Phong <cnx@loang.net>2023-11-18 21:40:15 +0900
commitae0810b2d4cdd31cd05f5746c6411da9d458eead (patch)
treea827fbe10c12a4a4665b98144f32e767ba5a3553 /src/Models.cpp
parent371906f5fb958691a8bfce85c28eb4dfaf63559c (diff)
downloadblackshades-ae0810b2d4cdd31cd05f5746c6411da9d458eead.tar.gz
Convert model geometry to Zig
Diffstat (limited to 'src/Models.cpp')
-rw-r--r--src/Models.cpp46
1 files changed, 7 insertions, 39 deletions
diff --git a/src/Models.cpp b/src/Models.cpp
index 63cf26a..bc0b4d2 100644
--- a/src/Models.cpp
+++ b/src/Models.cpp
@@ -46,16 +46,16 @@ void Model::CalculateNormals()
 		vArray[i*27+26]=Triangles[i].b;
 	}
 
-	boundingspherecenter = {};
+	this->center = {};
 	for (int i = 0; i < vertexNum; ++i)
-		boundingspherecenter += vertex[i];
-	boundingspherecenter /= vertexNum;
+		this->center += vertex[i];
+	this->center /= vertexNum;
 
-	boundingsphereradius = 0;
+	this->radius = 0;
 	for (int i = 0; i < vertexNum; ++i)
-		boundingsphereradius = std::max(boundingsphereradius,
-			sqrlen(boundingspherecenter - vertex[i]));
-	boundingsphereradius = sqrt(boundingsphereradius);
+		this->radius = std::max(this->radius,
+			sqrlen(this->center - vertex[i]));
+	this->radius = sqrt(this->radius);
 }
 
 void Model::load(const char* path)
@@ -106,35 +106,3 @@ void Model::draw(float r, float g, float b)
 	glColor4f(r, g, b, 1.0f);
 	glDrawArrays(GL_TRIANGLES, 0, TriangleNum*3);
 }
-
-int Model::LineCheck(XYZ p1, XYZ p2, XYZ *p)
-{
-	int result = -1;
-	if (segCrossSphere(p1, p2, boundingspherecenter, boundingsphereradius)) {
-		float olddistance = 9999999.0;
-		for (int j = 0; j < TriangleNum; ++j) {
-			XYZ point;
-			if (!segCrossTrigon(p1, p2,
-			                    vertex + Triangles[j].vertex[0],
-			                    vertex + Triangles[j].vertex[1],
-			                    vertex + Triangles[j].vertex[2],
-			                    normals + j, &point))
-				continue;
-			float distance = sqrlen(point - p1);
-			if (distance < olddistance || result == -1) {
-				olddistance = distance;
-				result = j;
-				*p = point;
-			}
-		}
-	}
-	return result;
-}
-
-int Model::LineCheck2(XYZ p1, XYZ p2, XYZ *p, XYZ move, float deg_y)
-{
-	int result = this->LineCheck(rotate(p1 - move, 0, -deg_y, 0),
-		rotate(p2 - move, 0, -deg_y, 0), p);
-	*p = rotate(*p, 0, deg_y, 0) + move;
-	return result;
-}