예제 #1
0
        protected override void WorldPositionChanged(object source)
        {
            base.WorldPositionChanged(source);

            Vector3D worldPosition;

            SlimBlock.ComputeWorldCenter(out worldPosition);

            Vector3D diff     = worldPosition - oldWorldPosition;
            double   lengthSq = diff.LengthSquared();

            if (lengthSq > MIN_MOVEMENT_SQUARED_FOR_UPDATE)
            {
                if (m_light != null && m_light.RenderObjectID != MyRenderProxy.RENDER_ID_UNASSIGNED)
                {
                    m_light.MarkPositionDirty();
                }
            }
            oldWorldPosition = worldPosition;

            if (m_oldWorldMatrix.Forward != WorldMatrix.Forward)
            {
                if (m_light != null && m_light.RenderObjectID != MyRenderProxy.RENDER_ID_UNASSIGNED)
                {
                    m_light.MarkPositionDirty();
                }
            }
            m_oldWorldMatrix = WorldMatrix;

            if (m_light != null && m_light.RenderObjectID != MyRenderProxy.RENDER_ID_UNASSIGNED)
            {
                m_light.UpdateLight();
            }
        }
        private void UpdateLightPosition()
        {
            if (m_light == null || !m_positionDirty)
            {
                return;
            }

            ProfilerShort.Begin("UpdateLightPosition");

            var newPos = PositionComp.GetPosition() + Vector3.TransformNormal(m_lightLocalPosition, WorldMatrix);

            if (Vector3D.DistanceSquared(m_lightWorldPosition, newPos) > 0.0001)
            {
                m_lightWorldPosition = newPos;
                m_light.MarkPositionDirty();
            }

            m_light.ParentID = Render.GetRenderObjectID();

            MatrixD toLocal = PositionComp.WorldMatrixNormalizedInv;

            m_light.Position           = Vector3D.Transform(m_lightWorldPosition, toLocal);
            m_light.ReflectorDirection = Vector3D.TransformNormal(WorldMatrix.Forward, toLocal);
            m_light.ReflectorUp        = Vector3D.TransformNormal(WorldMatrix.Up, toLocal);
            m_light.MarkPropertiesDirty();
            m_positionDirty = false;

            ProfilerShort.End();
        }