// ------------------------------------------------------------------------------------------------ #region Light public void InitLight(bool isLightOn) { m_light = MyLights.AddLight(); m_light.Start(MyLight.LightTypeEnum.Spotlight, 1.5f); m_light.ShadowDistance = 20; m_light.ReflectorFalloff = 5; m_light.LightOwner = MyLight.LightOwnerEnum.SmallShip; m_light.UseInForwardRender = true; m_light.ReflectorTexture = "Textures\\Lights\\dual_reflector_2.dds"; m_light.Range = 2; m_light.ReflectorRange = MyCharacter.REFLECTOR_RANGE; m_light.ReflectorColor = MyCharacter.REFLECTOR_COLOR; m_light.ReflectorIntensity = MyCharacter.REFLECTOR_INTENSITY; m_light.ReflectorGlossFactor = MyCharacter.REFLECTOR_GLOSS_FACTOR; m_light.ReflectorDiffuseFactor = MyCharacter.REFLECTOR_DIFFUSE_FACTOR; m_light.Color = MyCharacter.POINT_COLOR; m_light.SpecularColor = new Vector3(MyCharacter.POINT_COLOR_SPECULAR); m_light.Intensity = MyCharacter.POINT_LIGHT_INTENSITY; // Reflector Range now very far m_light.UpdateReflectorRangeAndAngle(MyCharacter.REFLECTOR_CONE_ANGLE, MyCharacter.REFLECTOR_RANGE * REFLECTOR_RANGE_MULTIPLIER); m_light.LightOn = isLightOn; m_light.ReflectorOn = isLightOn; }
public void UpdateLightPosition() { if (m_light != null) { MyCharacter character = m_skinnedEntity as MyCharacter; m_lightLocalPosition = character.Definition.LightOffset; MatrixD headMatrix = character.GetHeadMatrix(false, true, false); MatrixD headMatrixAnim = character.GetHeadMatrix(false, true, true, true); if (m_oldReflectorAngle != MyCharacter.REFLECTOR_DIRECTION) { m_oldReflectorAngle = MyCharacter.REFLECTOR_DIRECTION; m_reflectorAngleMatrix = MatrixD.CreateFromAxisAngle(headMatrix.Forward, MathHelper.ToRadians(MyCharacter.REFLECTOR_DIRECTION)); } m_light.ReflectorDirection = Vector3.Transform(headMatrix.Forward, m_reflectorAngleMatrix); m_light.ReflectorUp = headMatrix.Up; m_light.ReflectorTexture = "Textures\\Lights\\dual_reflector_2.dds"; m_light.ReflectorColor = MyCharacter.REFLECTOR_COLOR; m_light.UpdateReflectorRangeAndAngle(MyCharacter.REFLECTOR_CONE_ANGLE, MyCharacter.REFLECTOR_RANGE); m_light.Position = Vector3D.Transform(m_lightLocalPosition, headMatrixAnim); m_light.UpdateLight(); Matrix[] boneMatrices = character.BoneAbsoluteTransforms; if (m_leftGlare != null) { MatrixD leftGlareMatrix = m_reflectorAngleMatrix * MatrixD.Normalize(boneMatrices[m_leftLightIndex]) * m_skinnedEntity.PositionComp.WorldMatrix; m_leftGlare.Position = leftGlareMatrix.Translation; m_leftGlare.Range = 1; m_leftGlare.ReflectorDirection = -leftGlareMatrix.Up;//, m_reflectorAngleMatrix); m_leftGlare.ReflectorUp = leftGlareMatrix.Forward; m_leftGlare.GlareIntensity = m_light.Intensity; m_leftGlare.GlareSize = m_lightGlareSize; m_leftGlare.GlareQuerySize = 0.1f; m_leftGlare.GlareMaxDistance = MyCharacter.LIGHT_GLARE_MAX_DISTANCE; m_leftGlare.UpdateLight(); } if (m_rightGlare != null) { MatrixD rightGlareMatrix = m_reflectorAngleMatrix * MatrixD.Normalize(boneMatrices[m_rightLightIndex]) * m_skinnedEntity.PositionComp.WorldMatrix; m_rightGlare.Position = rightGlareMatrix.Translation; m_rightGlare.Range = 1; m_rightGlare.ReflectorDirection = -rightGlareMatrix.Up; m_rightGlare.ReflectorUp = rightGlareMatrix.Forward; m_rightGlare.GlareIntensity = m_light.Intensity; m_rightGlare.GlareSize = m_lightGlareSize; m_rightGlare.GlareQuerySize = 0.1f; m_rightGlare.GlareMaxDistance = MyCharacter.LIGHT_GLARE_MAX_DISTANCE; m_rightGlare.UpdateLight(); } } }