public static Vector3D operator +(Vector3D a, Vector3D b) { var vec3 = new Vector3D { X = a.X + b.X, Y = a.Y + b.Y, Z = a.Z + b.Z }; return vec3; }
public static Vector3D operator +(Vector3D a, float b) { var vec3 = new Vector3D { X = a.X + b, Y = a.Y + b, Z = a.Z + b }; return vec3; }
public static Vector3D operator *(Vector3D a, Vector3D b) { var vec3 = new Vector3D { X = a.Y * b.Z - a.Z * b.Y, Y = a.Z * b.X - a.X * b.Z, Z = a.X * b.Y - a.Y * b.X }; return vec3; }
public static Vector3D operator *(Vector3D a, float b) { var vec3 = new Vector3D { X = a.X * b, Y = a.Y * b, Z = a.Z * b }; return vec3; }
private Vector3D[] GetVertices(Stream stream) { Lump lump = header.lumps[(int)LumpType.LUMP_VERTEXES]; stream.Position = lump.offset; Vector3D[] vertices = new Vector3D[(lump.length / 3) / 4]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vector3D(); vertices[i].X = UtilityReader.ReadFloat(stream); vertices[i].Y = UtilityReader.ReadFloat(stream); vertices[i].Z = UtilityReader.ReadFloat(stream); } return vertices; }
private Plane[] GetPlanes(Stream stream) { Lump lump = header.lumps[(int)LumpType.LUMP_PLANES]; Plane[] planes = new Plane[lump.length / 20]; stream.Position = lump.offset; for (int i = 0; i < planes.Length; i++) { planes[i] = new Plane(); Vector3D normal = new Vector3D(); normal.X = UtilityReader.ReadFloat(stream); normal.Y = UtilityReader.ReadFloat(stream); normal.Z = UtilityReader.ReadFloat(stream); planes[i].normal = normal; planes[i].distance = UtilityReader.ReadFloat(stream); planes[i].type = UtilityReader.ReadInt(stream); } return planes; }
public bool IsVisible(Vector3D start, Vector3D end) { Vector3D vDirection = end - start; Vector3D vPoint = start; int iStepCount = (int)vDirection.Length(); vDirection /= iStepCount; Leaf pLeaf = new Leaf() { area = -1 }; while (iStepCount > 0) { vPoint += vDirection; pLeaf = GetLeafForPoint(vPoint); if (pLeaf.area != -1) { if ( (pLeaf.contents & ContentsFlag.CONTENTS_SOLID) == ContentsFlag.CONTENTS_SOLID || (pLeaf.contents & ContentsFlag.CONTENTS_DETAIL) == ContentsFlag.CONTENTS_DETAIL ) { break; } } iStepCount--; } return (pLeaf.contents & ContentsFlag.CONTENTS_SOLID) != ContentsFlag.CONTENTS_SOLID; }
public Leaf GetLeafForPoint(Vector3D point) { int node = 0; Node pNode; Plane pPlane; float d = 0.0f; while (node >= 0) { pNode = nodes[node]; pPlane = planes[pNode.planenum]; d = Vector3D.Dot(point, pPlane.normal) - pPlane.distance; if (d > 0) { node = pNode.children[0]; } else { node = pNode.children[1]; } } return ( (-node - 1) >= 0 && -node - 1 < leafs.Length ? leafs[-node - 1] : new Leaf() { area = -1, contents = ContentsFlag.CONTENTS_EMPTY } ); }
public static Vector3D operator -(Vector3D a, Vector3D b) { var vec3 = new Vector3D { X = a.X - b.X, Y = a.Y - b.Y, Z = a.Z - b.Z }; return vec3; }
public float DistanceFrom(Vector3D vec) { return Distance(this, vec); }
public static float Dot(Vector3D left, Vector3D right) { float single = left.X * right.X + left.Y * right.Y + left.Z * right.Z; return single; }
public static float Distance(Vector3D a, Vector3D b) { var vec3 = a - b; var single = (float)Math.Sqrt((double)(vec3.X * vec3.X + vec3.Y * vec3.Y + vec3.Z * vec3.Z)); return single; }