当前位置: 首页>>代码示例>>C#>>正文


C# Vector3D.TryNormalize方法代码示例

本文整理汇总了C#中Vector3D.TryNormalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3D.TryNormalize方法的具体用法?C# Vector3D.TryNormalize怎么用?C# Vector3D.TryNormalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector3D的用法示例。


在下文中一共展示了Vector3D.TryNormalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryNormalize

        public void TryNormalize()
        {
            Vector3D v = Vector3D.Zero;
              bool normalized = v.TryNormalize();
              Assert.IsFalse(normalized);

              v = new Vector3D(1, 2, 3);
              normalized = v.TryNormalize();
              Assert.IsTrue(normalized);
              Assert.AreEqual(new Vector3D(1, 2, 3).Normalized, v);

              v = new Vector3D(0, -1, 0);
              normalized = v.TryNormalize();
              Assert.IsTrue(normalized);
              Assert.AreEqual(new Vector3D(0, -1, 0).Normalized, v);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:16,代码来源:Vector3DTest.cs

示例2: GetSunlight

        public static void GetSunlight(float altitude, float turbidity, Vector3D sunDirection,
            out Vector3F directSunlight, out Vector3F scatteredSunlight)
        {
            _spectrum.SetSolarSpectrum();

              sunDirection.TryNormalize();
              double cosZenith = sunDirection.Y;

              Vector3F direct, indirect;
              if (cosZenith > 0)
              {
            // Daylight - Sun is above horizon.
            double zenithAngle = Math.Acos(cosZenith);
            _spectrum.ApplyAtmosphericTransmittance(zenithAngle, turbidity, altitude, _spectrumDirect, _spectrumIndirect);
            direct = _spectrumDirect.ToXYZ();
            indirect = _spectrumIndirect.ToXYZ();
              }
              else
              {
            // Twilight - Sun is below horizon.
            // We lookup luminance based on experimental results on cloudless nights.

            // Get sun angle in degrees for table lookup.
            float solarAltitude = (float)MathHelper.ToDegrees(Math.Asin(sunDirection.Y));

            // Get luminance from table (linearly interpolating the next two table entries).
            int lower = (int)Math.Floor(solarAltitude);
            int higher = (int)Math.Ceiling(solarAltitude);
            float a, b;
            TwilightLuminance.TryGetValue(lower, out a);
            TwilightLuminance.TryGetValue(higher, out b);
            float Y = InterpolationHelper.Lerp(a, b, solarAltitude - lower);

            // We use fixed chromacity values.
            float x = 0.2f;
            float y = 0.2f;

            // Convert xyY to XYZ.
            float X = x * (Y / y);
            float Z = (1.0f - x - y) * (Y / y);

            // Get sunlight from slightly above the horizon.
            const float epsilon = 0.001f;
            const double zenithAngle = ConstantsD.PiOver2 - epsilon;
            _spectrum.ApplyAtmosphericTransmittance(zenithAngle, turbidity, altitude, _spectrumDirect, _spectrumIndirect);
            direct = _spectrumDirect.ToXYZ();
            indirect = _spectrumIndirect.ToXYZ();

            // Blend between table values and sunset light.
            float blend = MathHelper.Clamp(-solarAltitude / 5.0f, 0, 1);
            direct =  InterpolationHelper.Lerp(direct, new Vector3F(0, 0, 0), blend);
            indirect = InterpolationHelper.Lerp(indirect, new Vector3F(X, Y, Z), blend);
              }

              // Convert XYZ to RGB.
              directSunlight = GraphicsHelper.XYZToRGB * direct;
              scatteredSunlight = GraphicsHelper.XYZToRGB * indirect;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:58,代码来源:Ephemeris_Lighting.cs


注:本文中的Vector3D.TryNormalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。