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); }
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; } } }
public static float Intersection_TerrainRay(Landscape terrain, FRay ray) { float t = -1.0f; if (terrain != null) { Vector3 P = getIntersectionPoint(terrain, ray); if (GeometryMath.CMP(ray.Direction.X, 0.0f) <= 0.0f && GeometryMath.CMP(P.X, 0.0f) <= 0.0f) { t = (P.X - ray.StartPosition.X) / ray.Direction.X; } else if (GeometryMath.CMP(ray.Direction.Y, 0.0f) <= 0.0f && GeometryMath.CMP(P.Y, 0.0f) <= 0.0f) { t = (P.Y - ray.StartPosition.Y) / ray.Direction.Y; } else if (GeometryMath.CMP(ray.Direction.Z, 0.0f) <= 0.0f && GeometryMath.CMP(P.Z, 0.0f) <= 0.0f) { t = (P.Z - ray.StartPosition.Z) / ray.Direction.Z; } } return(t); }
public void RenderWaterRefraction(DirectionalLight Sun, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = default(Vector4)) { if (bPostConstructor) { return; } Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*If clip plane is set - enable clipping plane*/ if (GeometryMath.CMP(clipPlane.LengthSquared, 0.0f) > 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } m_liteRefractionShader.startProgram(); m_texture.BindTexture(TextureUnit.Texture0); m_normalMap?.BindTexture(TextureUnit.Texture1); m_liteRefractionShader.SetAlbedoTexture(0); m_liteRefractionShader.SetNormalMap(1); m_liteRefractionShader.SetMaterial(m_material); m_liteRefractionShader.SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); m_liteRefractionShader.SetDirectionalLight(Sun); m_liteRefractionShader.SetClipPlane(ref clipPlane); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); m_liteRefractionShader.stopProgram(); }