private List <Vector3> GetRayCastPositionsOnCharacterBoundByVelocity(FRay[] insideCastRays, BoundBase characterBound, Vector3 boundMax, Vector3 boundMin, Vector3 boundOrigin) { List <Vector3> rayCastPositions = new List <Vector3>(); for (Int32 i = 0; i < insideCastRays.Length; i++) { FRay ray = insideCastRays[i]; float localIntersectionDistance = -1.0f; BoundBase.BoundType boundType = characterBound.GetBoundType(); if ((boundType & BoundBase.BoundType.AABB) == BoundBase.BoundType.AABB) { localIntersectionDistance = GeometryMath.Intersection_RayAABBExt(ray, boundMax, boundMin); } else if ((boundType & BoundBase.BoundType.OBB) == BoundBase.BoundType.OBB) { localIntersectionDistance = GeometryMath.Intersection_RayOBBExt(ray, (characterBound as OBB).GetTangetX(), (characterBound as OBB).GetTangetY(), (characterBound as OBB).GetTangetZ(), boundOrigin, (characterBound as OBB).GetExtent()); } if (localIntersectionDistance > -1.0f) { Vector3 intersectionPosition = ray.GetPositionInTime(localIntersectionDistance); rayCastPositions.Add(new Vector3(intersectionPosition)); } } return(rayCastPositions); }
private Selection GetSelection(int screenX, int screenY) { // Try to see what can be selected Vector3 rayStart = GeometryMath.Unproject(new Vector3(screenX, Viewport.height - screenY, 0.1), ProjectionMatrix, Viewport); Vector3 rayEnd = GeometryMath.Unproject(new Vector3(screenX, Viewport.height - screenY, IsPerspective ? 1.0 : -1.0), ProjectionMatrix, Viewport); Vector3 rayDirection = (rayEnd - rayStart).GetNormalized(); bool closestHitOpaque = false; double closestDistance = Double.MaxValue; int closestPrimitiveTriangleIndex = -1; DebugRenderPrimitive closestPrimitive = null; List <DebugRenderPrimitive> debugRenderPrimitives = Session.DebugRenderStorage.GetCachedPrimitives(); foreach (DebugRenderPrimitive primitive in debugRenderPrimitives) { bool hitOpaque; int triangleIndex; Vector3 intersection = new Vector3(0, 0, 0); if (primitive.RayCheck(Session.PlaybackPosition, rayStart, rayDirection, out triangleIndex, out hitOpaque, out intersection)) { double distance = rayStart.Distance(intersection); if (distance < closestDistance) { closestPrimitiveTriangleIndex = triangleIndex; closestDistance = distance; closestPrimitive = primitive; closestHitOpaque = hitOpaque; } } } return(closestPrimitive != null ? new Selection(closestPrimitive, closestPrimitiveTriangleIndex, closestHitOpaque) : null); }
private RayCastOutputData GetClosestRayCastResult(FRay ray, List <BoundBase> collidedBounds) { float resultShortestDistance = -1.0f; BoundBase resultBound = null; // DO RAY CAST IN ALL COLLIDED BOUNDING BOXES for (Int32 i = 0; i < collidedBounds.Count; i++) { float localIntersectionDistance = 0.0f; BoundBase.BoundType boundType = collidedBounds[i].GetBoundType(); if ((boundType & BoundBase.BoundType.AABB) == BoundBase.BoundType.AABB) { localIntersectionDistance = GeometryMath.Intersection_RayAABB(ray, collidedBounds[i] as AABB); } else if ((boundType & BoundBase.BoundType.OBB) == BoundBase.BoundType.OBB) { localIntersectionDistance = GeometryMath.Intersection_RayOBB(ray, collidedBounds[i] as OBB); } if (resultShortestDistance <= -1.0f || (localIntersectionDistance > 0.0f && localIntersectionDistance < resultShortestDistance)) { resultShortestDistance = localIntersectionDistance; resultBound = collidedBounds[i]; } } Vector3 intersectionPosition = ray.GetPositionInTime(resultShortestDistance); return(new RayCastOutputData(ray, resultBound, resultShortestDistance, intersectionPosition)); }
private RayCastOutputData GetClosestAndHighestRay(List <RayCastOutputData> rayCastResults, BoundBase characterBound) { float boundMaxY = characterBound.GetMax().Y; RayCastOutputData rayCastOutputData = null; List <RayCastOutputData> mostHighRayCastPositionResults = new List <RayCastOutputData>(); // find rays with the most high start position foreach (var result in rayCastResults) { if (result.shortestDistance > -1 && GeometryMath.CMP(result.parentRay.StartPosition.Y, boundMaxY) > 0) { mostHighRayCastPositionResults.Add(result); } } if (mostHighRayCastPositionResults.Count > 1) { // find ray with the most close intersection position float intersectionDistance = mostHighRayCastPositionResults.First().shortestDistance; rayCastOutputData = mostHighRayCastPositionResults.First(); for (Int32 i = 1; i < mostHighRayCastPositionResults.Count; i++) { if (mostHighRayCastPositionResults[i].shortestDistance <= intersectionDistance) { rayCastOutputData = mostHighRayCastPositionResults[i]; intersectionDistance = rayCastOutputData.shortestDistance; } } } return(rayCastOutputData); }
private void FindParameters(out double height, out double width) { var pts = GetPoints(); height = GeometryMath.FindMagnitude(new LineSegment(pts[0], pts[1])); width = GeometryMath.FindMagnitude(new LineSegment(pts[1], pts[2])); }
public override bool IsExisting() { var points = GetPoints(); // Checking for repeating points for (int i = 0; i < points.Length; i++) { for (int j = 0; j < points.Length; j++) { if (i != j && GeometryMath.IsPointsEqual(points[i], points[j])) { return(false); } } } // Checking for self-intersections; for (int i = 0; i < points.Length; i++) { for (int j = 0; j < points.Length; j++) { var a = new LineSegment(points[i], points[(i + 1) % points.Length]); var b = new LineSegment(points[j], points[(j + 1) % points.Length]); if (i != j && GeometryMath.IsIntersected(a, b)) { return(false); } } } return(true); }
public void TestRayAABBIntersect() { Vector3 rayStart = new Vector3(0, 0, 0); Vector3 rayDir = new Vector3(0, 0, 1); double s, t; Bounds bounds = new Bounds(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); // Check that ray hits AABB (ray starts inside the bounds) Assert.IsTrue(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to hit AABB but did not (ray starts inside AABB)"); rayStart = new Vector3(0, 0, -2); // Check that ray hits AABB (ray starts outside the bounds) Assert.IsTrue(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to hit AABB but did not (ray starts outside AABB)"); rayDir = new Vector3(0, 0, -1); // Check that ray does not hit AABB (ray goes to other direction) Assert.IsFalse(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to miss AABB but did not (ray goes away from AABB)"); rayStart = new Vector3(1, 0, -2); rayDir = new Vector3(1, 0, 1); // Check that ray does not hit AABB (ray is co-linear with one side of the AABB) Assert.IsFalse(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to miss AABB but did not (ray is co-linear with one side of the AABB)"); }
public void TestBarycentricCoordinates() { Vector2 a = new Vector2(0, -0.5); Vector2 b = new Vector2(-0.5, 0.5); Vector2 c = new Vector2(0.5, 0.5); Vector2 point = new Vector2(0, 0); double t, u, v; // Check that barycentric coordinates are all between 0..1 GeometryMath.GetBarycentricCoordinates(point, a, b, c, out t, out u, out v); Assert.IsTrue(t >= 0.0 && t <= 1.0 && u >= 0.0 && u <= 1.0 && v >= 0.0 && v <= 1.0, "Expected t, u, v to be within 0..1 (point in middle of triangle)"); point = new Vector2(0, -0.5); // Check that barycentric coordinates are 0, 0, 1 as point is exactly where with one of the triangle points GeometryMath.GetBarycentricCoordinates(point, a, b, c, out t, out u, out v); Assert.IsTrue(t == 1.0 && u == 0.0 && v == 0.0, "Expected t = 0, u = 0, v = 1 (point in the same place as one of the triangle points)"); point = new Vector2(-0.25, 0); // Check that one of the barycentric coordinates is 0 as point is on one of the triangle edges GeometryMath.GetBarycentricCoordinates(point, a, b, c, out t, out u, out v); Assert.IsTrue(v == 0, "Expected one of the (t, u, v) be 0 (point is in one of the triangle edges)"); point = new Vector2(0, -0.51); // Check that barycentric coordinates are not between 0..1 GeometryMath.GetBarycentricCoordinates(point, a, b, c, out t, out u, out v); Assert.IsFalse(t >= 0.0 && t <= 1.0 && u >= 0.0 && u <= 1.0 && v >= 0.0 && v <= 1.0, "Expected one of the (t, u, v) be outside 0..1 (point is outside of the triangle)"); }
private Tile TileAt(Ray ray, List <Tile> list, Vector3 position) { for (int i = 0; i < list.Count; i++) { var tile = list[i]; Vector3 worldA = root.TransformPoint(tile.a); Vector3 worldB = root.TransformPoint(tile.b); Vector3 worldC = root.TransformPoint(tile.c); Plane plane = new Plane(worldA, worldB, worldC); float distance; if (plane.Raycast(ray, out distance)) { Vector3 point = ray.GetPoint(distance); if (GeometryMath.PointInTriangle(worldA, worldB, worldC, point)) { if (tile.children.Count > 0) { var t = TileAt(ray, tile.children, position); if (t != null) { return(t); } } else { return(tile); } } } } return(null); }
public void TestPointInCircumcircle() { Vector2 a = new Vector2(0, -0.5); Vector2 b = new Vector2(-0.5, 0.5); Vector2 c = new Vector2(0.5, 0.5); Vector2 point = new Vector2(0, 0); // Check that point is in circumcircle Assert.IsTrue(GeometryMath.PointInCircumcircle(point, a, b, c), "Expected to be inside circumcircle but was not (point in middle of triangle)"); point = new Vector2(0, 1); // Check that point is not in circumcircle Assert.IsFalse(GeometryMath.PointInCircumcircle(point, a, b, c), "Expected to be outside circumcircle (point outside one of the corners)"); // Check that point is in circumcircle when triangle points are on the same line a = new Vector2(0, 0); b = new Vector2(1, 0); c = new Vector2(2, 0); Assert.IsTrue(GeometryMath.PointInCircumcircle(point, a, b, c), "Expected to be inside circumcircle (all triangle points on the same line)"); // Check that point is in circumcircle when on triangle side length is 0 a = new Vector2(0, 0); b = new Vector2(0, 0); c = new Vector2(0, 1); Assert.IsTrue(GeometryMath.PointInCircumcircle(point, a, b, c), "Expected to be inside circumcircle (one triangle side length is 0)"); // Check that point is in circumcircle when is it just within radius a = new Vector2(0, -0.5); b = new Vector2(-0.5, 0.5); c = new Vector2(0.5, 0.5); point = new Vector2(0, -0.5); Assert.IsTrue(GeometryMath.PointInCircumcircle(point, a, b, c), "Expected to be inside circumcircle (point is the same as one of the triangle points)"); }
public void RenderScreenSpace(RenderInfo info, Matrix4x4 transformMatrix, Viewport viewport) { if (info.showAnnotations) { Font font = new Font("Calibri", 12.0f * 0.75f); List <DebugRenderPrimitive> primitivesToRender = GetCachedPrimitives(); foreach (DebugRenderPrimitive primitive in primitivesToRender) { if (primitive.Annotation != null && primitive.Annotation.IsValidAt(info.time)) { Vector3 screenPosition = GeometryMath.Project(primitive.WorldBounds.Center, transformMatrix, viewport); if (screenPosition.z >= 0.0) { Size textSize = TextRenderer.MeasureText(primitive.Annotation.Text, font); Vector3 textHalfSize = new Vector3((double)textSize.Width, (double)textSize.Height, 0.0) * 0.5; OpenGLDrawHelper.FillRectangle(DebugRenderControl.gl, screenPosition - textHalfSize, screenPosition + textHalfSize, primitive.Annotation.Color.Brightness > 0.5 ? new Color32(0, 0, 0, 255) : new Color32(255, 255, 255, 255), false); DebugRenderControl.gl.DrawText((int)(screenPosition.x - textHalfSize.x) + 2, (int)(screenPosition.y - textHalfSize.y * 0.4), primitive.Annotation.Color.R, primitive.Annotation.Color.G, primitive.Annotation.Color.B, "Calibri", 12.0f, primitive.Annotation.Text); } } } } }
public override void CameraTick(float DeltaTime) { if (bTransformationDirty) { if (m_collisionHeadUnit != null) { m_collisionHeadUnit.TryCameraCollision(this); } bTransformationDirty = false; } if (m_bThirdPersonTargetTransformationDirty) { m_lerpTimeElapsed = Math.Min(m_lerpTimeElapsed + DeltaTime, m_timeForInterpolation); Vector3 finalTargetVector = m_thirdPersonTarget.ComponentTranslation; m_actualTargetVector = LerpPosition(m_lerpTimeElapsed, 0.0f, m_timeForInterpolation, ref m_actualTargetVector, ref finalTargetVector); // If camera is at final position if (GeometryMath.CMP(m_lerpTimeElapsed, m_timeForInterpolation) > 0) { m_lerpTimeElapsed = 0.0f; m_bThirdPersonTargetTransformationDirty = false; } } }
private void CheckFrameBoundingBoxCollision(ref bool bFrameBoundBoxCollision, ref Component characterRootComponent, ref CollisionUnit characterCollisionUnit, ref Component collidedRootComponent, ref List <BoundBase> collidedRootBounds) { foreach (var unit in CollisionUnits) { if (characterCollisionUnit.RootComponent == unit.RootComponent) { continue; } AABB aabb1 = characterCollisionUnit.GetAndTryUpdateFramingBoundingBox(); AABB aabb2 = unit.GetAndTryUpdateFramingBoundingBox(); if (GeometryMath.AABBAABB(aabb1, aabb2)) { bFrameBoundBoxCollision = true; collidedRootComponent = aabb2.ParentComponent.GetRootComponent(); collidedRootBounds.AddRange(unit.GetBoundingBoxes()); } } if (bFrameBoundBoxCollision) { CollisionOutput.Add(new CollisionOutputFramingAABB(characterRootComponent, collidedRootComponent)); } else { CollisionOutput.Add(new CollisionOutputNoCollided(characterRootComponent)); } }
static double CalculatePerimeters(GeometryMath gm, int[] valueIntegers) { if (valueIntegers != null) return gm(valueIntegers); else return 0.0; }
/// <summary> /// /// </summary> /// <param name="worldPosition"></param> /// <returns></returns> public bool Contains(Vector3 worldPosition) { Vector3 worldA = grid.root.TransformPoint(a); Vector3 worldB = grid.root.TransformPoint(b); Vector3 worldC = grid.root.TransformPoint(c); return(GeometryMath.PointInTriangle(worldA, worldB, worldC, worldPosition)); }
private void GetEdgePoints(BaseCamera viewerCamera, ConvexVolume volume, out Vector3 LBN, out Vector3 RTF) { Vector3 ViewerPosition = viewerCamera.GetEyeVector(); // Find left and right edges Vector3 IntersectionPointC = GetLeftRightIntersectionPoint(ViewerPosition, volume.FarPlane, volume.LeftPlane); Vector3 IntersectionPointB = GetLeftRightIntersectionPoint(ViewerPosition, volume.FarPlane, volume.RightPlane); // Find top and bottom edges Vector3 IntersectionPointBottom = GetTopBottomIntersectionPoint(ViewerPosition, volume.FarPlane, volume.BottomPlane); Vector3 IntersectionPointTop = GetTopBottomIntersectionPoint(ViewerPosition, volume.FarPlane, volume.TopPlane); float left, right, top, bottom, near, far; // left Dictionary <float, Vector3> projectedValues = new Dictionary <float, Vector3>(); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, -RightVector), IntersectionPointB); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, -RightVector), IntersectionPointC); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -RightVector), ViewerPosition); left = projectedValues[projectedValues.Keys.Max()].X; // right projectedValues.Clear(); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, RightVector), IntersectionPointB); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, RightVector), IntersectionPointC); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, RightVector), ViewerPosition); right = projectedValues[projectedValues.Keys.Max()].X; // top projectedValues.Clear(); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointTop, UpVector), IntersectionPointTop); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointBottom, UpVector), IntersectionPointBottom); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, UpVector), ViewerPosition); top = projectedValues[projectedValues.Keys.Max()].Y; // bottom projectedValues.Clear(); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointTop, -UpVector), IntersectionPointTop); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointBottom, -UpVector), IntersectionPointBottom); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -UpVector), ViewerPosition); bottom = projectedValues[projectedValues.Keys.Max()].Y; // far projectedValues.Clear(); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, ForwardVector), IntersectionPointB); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, ForwardVector), IntersectionPointC); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, ForwardVector), ViewerPosition); far = projectedValues[projectedValues.Keys.Max()].Z; // near projectedValues.Clear(); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, -ForwardVector), IntersectionPointB); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, -ForwardVector), IntersectionPointC); projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -ForwardVector), ViewerPosition); near = projectedValues[projectedValues.Keys.Max()].Z; LBN = new Vector3(left, bottom, near); RTF = new Vector3(right, top, far); }
private void CreateMesh() { double height = 0.5; double radius = 0.5; Segments = SMath.Clamp(Segments, 3, 256); VertexList = new VertexNormalColor[Segments * (CreateCaps ? 2 : 1) + 1]; IndexList = new uint[Segments * 3 + (CreateCaps ? (Segments - 2) * 3 : 0)]; // Create vertices VertexList[0].Position = new Vector3(0, 0, height); for (int i = 0; i < Segments; i++) { double angle = ((double)i / (double)Segments) * Math.PI * 2.0; Vector2 planarCoordinate = Vector2.FromAngle(angle, radius); VertexList[i + 1].Position = new Vector3(planarCoordinate.X, planarCoordinate.Y, -height); if (CreateCaps) { // Top (for cap) VertexList[i + Segments + 1].Position = new Vector3(planarCoordinate.X, planarCoordinate.Y, -height); } } // Create normals Vector3 capNormal = CreateCaps ? GeometryMath.GetTriangleNormal(VertexList[1].Position, VertexList[2].Position, VertexList[3].Position) : new Vector3(0, 0, 0); for (int i = 0; i < Segments; i++) { Vector3 manifoldNormal = GeometryMath.GetTriangleNormal(VertexList[0].Position, VertexList[(i + 1) % Segments + 1].Position, VertexList[i + 1].Position); VertexList[i + 1].Normal = manifoldNormal; if (CreateCaps) { VertexList[Segments + i + 1].Normal = capNormal; } } // Create triangles int index = 0; for (int i = 0; i < Segments; i++) { // Manifold IndexList[index++] = 0; IndexList[index++] = (uint)((i + 1) % Segments + 1); IndexList[index++] = (uint)(i + 1); if (CreateCaps && i < Segments - 2) { // Cap IndexList[index++] = (uint)(Segments + 1); IndexList[index++] = (uint)(Segments + i + 2); IndexList[index++] = (uint)(Segments + i + 3); } } }
public void AddTriangle(int time, Vector3 a, Vector3 b, Vector3 c, Color32 color) { LocalBounds.Encapsulate(a); LocalBounds.Encapsulate(b); LocalBounds.Encapsulate(c); Vector3 newTriangleNormal = GeometryMath.GetTriangleNormal(a, b, c); ArrayList <VertexNormalColor> vertexList = color.A < 255 ? transparentVertexList : opaqueVertexList; List <DebugRenderTriangleIndexMarker> triangleMarkers = color.A < 255 ? transparentTriangleMarkers : opaqueTriangleMarkers; vertexList.Add(new VertexNormalColor() { Position = a, Color = color, Normal = newTriangleNormal }); vertexList.Add(new VertexNormalColor() { Position = b, Color = color, Normal = newTriangleNormal }); vertexList.Add(new VertexNormalColor() { Position = c, Color = color, Normal = newTriangleNormal }); // Find or create new index marker and add triangle DebugRenderTriangleIndexMarker searchItem = new DebugRenderTriangleIndexMarker(0, time); int index = triangleMarkers.BinarySearch(searchItem); if (index < 0) { index = ~index; } while (index > 0 && index < triangleMarkers.Count && triangleMarkers[index].time > time) { // Not exact match but the next one -> Decrease index by one to have only the range that counts up for the requested time index--; } if (index < triangleMarkers.Count && triangleMarkers[index].time == time) { // Has existing one for this time -> Update end index triangleMarkers[index].index = vertexList.Count - 1; } else { // Insert new DebugRenderTriangleIndexMarker range = new DebugRenderTriangleIndexMarker(vertexList.Count - 1, time); triangleMarkers.Insert(index, range); } if (!InfiniteLength && EndTime < time) { EndTime = time; } }
public override bool IsExisting() { var lines = GetLines(); var a = GeometryMath.FindMagnitude(lines[0]); var b = GeometryMath.FindMagnitude(lines[1]); var c = GeometryMath.FindMagnitude(lines[2]); return(a + b > c && a + c > b && b + c > a); }
protected virtual bool RayCheckInternal(int time, Vector3 rayStart, Vector3 rayDirection, out int triangleIndex, out bool hitOpaque, out Vector3 intersection) { hitOpaque = false; triangleIndex = -1; double tmin, tmax; Bounds bounds = WorldBounds; GeometryMath.IntersectAABB(rayStart, rayDirection, bounds.Min, bounds.Max, out tmin, out tmax); intersection = WorldBounds.Center - rayDirection.GetNormalized() * Math.Min(tmin, tmax); return(true); }
public override double FindArea() { var lines = GetLines(); var p = FindPerimeter() / 2; var a = GeometryMath.FindMagnitude(lines[0]); var b = GeometryMath.FindMagnitude(lines[1]); var c = GeometryMath.FindMagnitude(lines[2]); return(System.Math.Sqrt(p * (p - a) * (p - b) * (p - c))); }
public virtual void IsLitByLightSource(List <PointLight> LightList) { m_lightVisibilityMap.Init(LightList.Count, false); for (Int32 i = 0; i < LightList.Count; i++) { BoundBase bound = GetAABBFromAllChildComponents(); FSphere boundSphere = (FSphere)bound; FSphere lightSphere = new FSphere(LightList[i].Position.Xyz, LightList[i].AttenuationRadius); m_lightVisibilityMap[i] = GeometryMath.IsSphereVsSphereIntersection(ref boundSphere, ref lightSphere); } }
public bool Contains(Vector2 point) { if (GeometryMath.PointInTriangle(a, b, c, point) || GeometryMath.PointInTriangle(a, c, d, point) || GeometryMath.PointInSegment(a, c, point) || GeometryMath.PointInSegment(b, d, point)) { return(true); } return(false); }
public bool Intersect(Vector2 a, Vector2 b) { if (GeometryMath.SegmentIntersect(this.a, this.b, a, b) || GeometryMath.SegmentIntersect(this.b, this.c, a, b) || GeometryMath.SegmentIntersect(this.c, this.d, a, b) || GeometryMath.SegmentIntersect(this.d, this.a, a, b)) { return(true); } return(false); }
protected override bool RayCheckInternal(int time, Vector3 rayStart, Vector3 rayDirection, out int triangleIndex, out bool hitOpaque, out Vector3 intersection) { Matrix4x4 mat = GetTransform(); hitOpaque = false; triangleIndex = -1; intersection = new Vector3(0, 0, 0); double minDistSq = Double.MaxValue; Vector3 triangleIntersection = new Vector3(0, 0, 0); int elementCount = GetElementCount(time, false); for (int i = 0; i < elementCount; i += 3) { Vector3 a = mat * opaqueVertexList[i].Position; Vector3 b = mat * opaqueVertexList[i + 1].Position; Vector3 c = mat * opaqueVertexList[i + 2].Position; if (GeometryMath.Intersect(rayStart, rayDirection, a, b, c, out triangleIntersection)) { double distSq = rayStart.DistanceSquared(triangleIntersection); if (distSq < minDistSq) { minDistSq = distSq; intersection = triangleIntersection; triangleIndex = i; hitOpaque = true; } } } elementCount = GetElementCount(time, true); for (int i = 0; i < elementCount; i += 3) { Vector3 a = mat * transparentVertexList[i].Position; Vector3 b = mat * transparentVertexList[i + 1].Position; Vector3 c = mat * transparentVertexList[i + 2].Position; if (GeometryMath.Intersect(rayStart, rayDirection, a, b, c, out triangleIntersection)) { double distSq = rayStart.DistanceSquared(triangleIntersection); if (distSq < minDistSq) { minDistSq = distSq; intersection = triangleIntersection; triangleIndex = i; hitOpaque = false; } } } return(triangleIndex != -1); }
private void CheckRegularBoundingBoxAndCameraSphereCollision(ref bool bSphereAndFrameBoundingBoxCollision, ref List <BoundBase> collidedRootBounds, ref FSphere cameraCollisionSphere) { foreach (var testingBound in collidedRootBounds) { FSphere obbCollisionSphere = (FSphere)testingBound; if (GeometryMath.IsSphereVsSphereIntersection(ref cameraCollisionSphere, ref obbCollisionSphere)) { bSphereAndFrameBoundingBoxCollision = true; break; } } }
private Vector3 GetTopBottomIntersectionPoint(Vector3 A, FPlane cbPlane, FPlane incidentPlane) { Vector3 result; Vector3 acNormal = new Vector3(incidentPlane.X, incidentPlane.Y, incidentPlane.Z); Vector3 acRayDirection = Vector3.Cross(acNormal, RightVector); Vector3 cbNormal = new Vector3(cbPlane.X, cbPlane.Y, cbPlane.Z); // if ac ray is opposite directed - invert it's direction acRayDirection *= Vector3.Dot(cbNormal, acRayDirection) > 0.0 ? 1 : -1; FRay acRay = new FRay(A, acRayDirection); result = GeometryMath.GetIntersectionRayPlane(cbPlane, acRay); return(result); }
public bool RayCheck(int time, Vector3 rayStart, Vector3 rayDirection, out int triangleIndex, out bool hitOpaque, out Vector3 intersection) { hitOpaque = false; triangleIndex = 0; intersection = new Vector3(0, 0, 0); double tmin, tmax; Bounds bounds = WorldBounds; if (GeometryMath.IntersectAABB(rayStart, rayDirection, bounds.Min, bounds.Max, out tmin, out tmax)) { return(RayCheckInternal(time, rayStart, rayDirection, out triangleIndex, out hitOpaque, out intersection)); } return(false); }
public void TestLineLineDistance() { Vector3 startA = new Vector3(0, 0, 0); Vector3 endA = new Vector3(1, 0, 0); Vector3 startB = new Vector3(0, 2, 0); Vector3 endB = new Vector3(1, 1, 0); double t; double s; double distance = GeometryMath.LineLineDistance(startA, endA, startB, endB, true, true, out t, out s); // Check that ray hits AABB (ray starts inside the bounds) Assert.IsTrue(distance == 1, String.Format("Expected distance to be 1 but got {0}, t {1} s {2} (lines cross but testing against segments)", distance, t, s)); }
public override bool IsExisting() { var points = GetPoints(); for (int i = 0; i < points.Length; i++) { var angle = GeometryMath.FindAngle( new LineSegment(points[i], points[(i + 1) % points.Length]), new LineSegment(points[(i + 1) % points.Length], points[(i + 2) % points.Length]) ); if (GeometryMath.IsDoubleEqual(angle, System.Math.PI / 2) == false) { return(false); } } return(true); }
// CAMERA private List <BoundBase> GetBoundingBoxesForCameraCollisionTest(ref FSphere cameraCollisionSphere, Component characterRootComponent) { List <BoundBase> resultCollidedRootBounds = new List <BoundBase>(); foreach (var unit in CollisionUnits) { if (unit.RootComponent == characterRootComponent) { continue; } FSphere aabbCollisionSphere = (FSphere)(unit.GetAndTryUpdateFramingBoundingBox()); if (GeometryMath.IsSphereVsSphereIntersection(ref cameraCollisionSphere, ref aabbCollisionSphere)) { resultCollidedRootBounds.AddRange(unit.GetBoundingBoxes()); } } return(resultCollidedRootBounds); }