ok it works

This commit is contained in:
GoaLitiuM
2021-08-15 18:12:31 +03:00
parent 4714b888a8
commit 758c6a51f6
2 changed files with 22 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ namespace Game
public struct MapFacePlane
{
public Vector3 v1, v2, v3;
public Plane plane;
public string texture;
public Vector2 offset;
public float rotation;
@@ -323,7 +324,7 @@ namespace Game
// ( <v1> ) ( <v2> ) ( <v3> ) <shader> <x_shift> <y_shift> <rotation> <x_scale> <y_scale> <content_flags> <surface_flags> <value>
case '(':
{
MapFacePlane plane;
MapFacePlane plane = new MapFacePlane();
plane.v1 = ParsePlaneVector3(data, ref index);
plane.v2 = ParsePlaneVector3(data, ref index);
plane.v3 = ParsePlaneVector3(data, ref index);
@@ -335,6 +336,12 @@ namespace Game
plane.surfaceFlags = ParseInt(data, ref index);
plane.surfaceValue = ParseInt(data, ref index);
plane.v1 = new Vector3(plane.v1.X, plane.v1.Z, plane.v1.Y);
plane.v2 = new Vector3(plane.v2.X, plane.v2.Z, plane.v2.Y);
plane.v3 = new Vector3(plane.v3.X, plane.v3.Z, plane.v3.Y);
plane.plane = new Plane(plane.v1, plane.v2, plane.v3);
planes.Add(plane);
break;
}

View File

@@ -1423,7 +1423,7 @@ namespace Game
float minD = 0f;
foreach (var brushPlane in brush.planes)
{
var p = new Plane(brushPlane.v1, brushPlane.v2, brushPlane.v3);
var p = brushPlane.plane;
minD = Mathf.Min(p.D);
maxD = Mathf.Max(p.D);
}
@@ -1450,7 +1450,7 @@ namespace Game
//foreach (var brushPlane in brush.planes.Skip(skipPlanes).Take(takePlanes))
foreach (var brushPlane in brush.planes)
{
Plane plane = new Plane(brushPlane.v1, brushPlane.v2, brushPlane.v3);
Plane plane = brushPlane.plane;
//if (asdf % 2 == 0)
//plane = new Plane(-plane.Normal, -plane.D);
@@ -1458,8 +1458,8 @@ namespace Game
List<Vector3> faceVertices = new List<Vector3>();
List<Vector3> clippedVertices = new List<Vector3>();
Func<float, bool> isFront = (f) => f < epsilon;
Func<float, bool> isBack = (f) => f > epsilon;
Func<float, bool> isFront = (f) => f > epsilon;
Func<float, bool> isBack = (f) => f < epsilon;
List<Tuple<Vector3, Vector3>> edges = new List<Tuple<Vector3, Vector3>>();
List<Tuple<Vector3, Vector3>> faceEdges = new List<Tuple<Vector3, Vector3>>();
@@ -1538,7 +1538,7 @@ namespace Game
{
Ray ray = new Ray(start, (end - start).Normalized);
Ray ray2 = new Ray(end, (start - end).Normalized);
if (plane.Intersects(ref ray, out Vector3 point) /*|| plane.Intersects(ref ray2, out point)*/)
if (plane.Intersects(ref ray, out Vector3 point) || plane.Intersects(ref ray2, out point))
{
edgeEnd = point;
clippedVertices.Add(point);
@@ -1748,9 +1748,9 @@ namespace Game
if (dotX > dotY && dotX > dotZ)
theUp = Vector3.Right;
else if (dotZ > dotX && dotZ > dotY)
theUp = Vector3.Forward;
theUp = -Vector3.Forward;
else if (dotY > dotX && dotY > dotZ)
theUp = Vector3.Up;
theUp = -Vector3.Up;
//rot = Quaternion.LookRotation(theUp, Vector3.Dot(normal, Vector3.Forward) < -0.01f ? Vector3.Forward : Vector3.Up);
@@ -1758,17 +1758,18 @@ namespace Game
//theUp = Vector3.Right;
//theUp = new Vector3(theUp.X, theUp.Z, theUp.Y);
var up1 = Vector3.Up;
var up2 = Vector3.Forward;
var up2 = -Vector3.Forward;
//theUp = Vector3.Forward;
Quaternion rot = Quaternion.LookRotation(theUp, Mathf.Abs(Vector3.Dot(theUp, up1)) > 0.01f ? up2 : up1);
rot = rot * Quaternion.RotationAxis(Vector3.Forward, 180f * Mathf.DegreesToRadians);
//rot.Invert();
Vector2 uvScale = new Vector2(1f / 16);
Vector2 uvScale = new Vector2(1f / 1f / 64f);
float uvRotation = 0f;
bool found = false;
foreach (var brushPlane in brush.planes)
{
Plane plane = new Plane(brushPlane.v1, brushPlane.v2, brushPlane.v3);
Plane plane = brushPlane.plane;
if ((plane.Normal - normal).Length < 0.01f)
{
uvScale = 1f / brushPlane.scale / 64f;
@@ -1829,8 +1830,8 @@ namespace Game
meshCollider.CollisionData = collisionData;
// TODO: flip Y and Z
childModel.Orientation = Quaternion.RotationYawPitchRoll(180f*Mathf.DegreesToRadians, -90f*Mathf.DegreesToRadians, 0f);
childModel.Scale = new Vector3(1f, -1f, 1f);
//childModel.Orientation = Quaternion.RotationYawPitchRoll(180f*Mathf.DegreesToRadians, -90f*Mathf.DegreesToRadians, 0f);
//childModel.Scale = new Vector3(1f, -1f, 1f);
}
}