Example #1
0
 /// <summary>
 /// Chooses one of two vectors depending on the <paramref name="pick1"/> value.
 /// </summary>
 /// <param name="v1">The first vector to choose.</param>
 /// <param name="v2">The second vector to choose.</param>
 /// <param name="pick1">If this value is true, the method chooses the virst vector, otherwise it chooses the second one.</param>
 /// <returns>The selected vector.</returns>
 public static Vector3F Select(Vector3F v1, Vector3F v2, bool pick1)
 {
     return(pick1 ? v1 : v2);
 }
Example #2
0
 public EnvironmentTextureData(Component_Image texture, ref Matrix3F rotation, ref Vector3F multiplier)
 {
     this.texture    = texture;
     this.rotation   = rotation;
     this.multiplier = multiplier;
 }
Example #3
0
        //

        /// <summary>
        /// Constructs a cone with another specified <see cref="ConeF"/> object.
        /// </summary>
        /// <param name="source">A specified cone.</param>
        public ConeF(ConeF source)
        {
            Origin = source.Origin;
            Axis   = source.Axis;
            Angle  = source.Angle;
        }
Example #4
0
 public RangeVector3F(Vector3F minimum, Vector3F maximum)
 {
     this.Minimum = minimum;
     this.Maximum = maximum;
 }
Example #5
0
        public virtual void GetRandomVariation(GetRandomVariationOptions options, Random random, out byte groupIndex, out byte elementIndex, out double positionZ, out QuaternionF rotation, out Vector3F scale)
        {
            //!!!!CompiledData?

            if (options.SetGroup.HasValue)
            {
                groupIndex = options.SetGroup.Value;
            }
            else
            {
                groupIndex = 0;
            }
            elementIndex = 0;
            positionZ    = 0;
            rotation     = QuaternionF.Identity;
            scale        = Vector3F.One;

            bool handled = false;

            GetRandomVariationEvent?.Invoke(this, options, ref handled, ref groupIndex, ref elementIndex);
            if (handled)
            {
                return;
            }

            var groups = GetComponents <Component_SurfaceGroupOfElements>();

            if (groups.Length != 0)
            {
                if (!options.SetGroup.HasValue)
                {
                    var groupProbabilities = new double[groups.Length];
                    for (int n = 0; n < groupProbabilities.Length; n++)
                    {
                        if (groups[n].Enabled)
                        {
                            groupProbabilities[n] = groups[n].Probability;
                        }
                    }
                    groupIndex = (byte)GetRandomIndex(random, groupProbabilities);
                }

                if (groupIndex < groups.Length)
                {
                    var group = groups[groupIndex];

                    var groupElements = group.GetComponents <Component_SurfaceElement>();
                    if (groupElements.Length != 0)
                    {
                        var elementProbabilities = new double[groupElements.Length];
                        for (int n = 0; n < elementProbabilities.Length; n++)
                        {
                            if (groupElements[n].Enabled)
                            {
                                elementProbabilities[n] = groupElements[n].Probability;
                            }
                        }
                        elementIndex = (byte)GetRandomIndex(random, elementProbabilities);
                    }

                    //PositionZRange
                    var positionZRange = group.PositionZRange.Value;
                    if (positionZRange.Minimum != positionZRange.Maximum)
                    {
                        positionZ = random.Next(positionZRange.Minimum, positionZRange.Maximum);
                    }
                    else
                    {
                        positionZ = positionZRange.Minimum;
                    }

                    //RotateAroundItsAxis
                    if (group.RotateAroundItsAxis)
                    {
                        rotation *= Quaternion.FromRotateByZ(random.Next(0, MathEx.PI * 2)).ToQuaternionF();
                    }
                    //MaxIncline
                    if (group.MaxIncline.Value != 0)
                    {
                        var incline = random.Next(group.MaxIncline.Value.InRadians());
                        rotation *= QuaternionF.FromRotateByX((float)incline);
                    }

                    //ScaleRange
                    var   scaleRange = group.ScaleRange.Value;
                    float scaleV;
                    if (scaleRange.Minimum != scaleRange.Maximum)
                    {
                        scaleV = (float)random.Next(scaleRange.Minimum, scaleRange.Maximum);
                    }
                    else
                    {
                        scaleV = (float)scaleRange.Minimum;
                    }
                    scale = new Vector3F(scaleV, scaleV, scaleV);
                }
            }
        }
Example #6
0
 public ColorByte(Vector3F color)
     : this((int)(color.X * 255), (int)(color.Y * 255), (int)(color.Z * 255))
 {
 }
Example #7
0
        public static bool DetectTextureType(byte[] data, Vector2I size, PixelFormat format, out bool hasAlpha, out bool normalMap)
        {
            hasAlpha  = false;
            normalMap = size.X > 64 && size.Y > 64;

            int normalMapCount = 0;
            int totalCount     = 0;

            for (int y = 0; y < size.Y; y++)
            {
                for (int x = 0; x < size.X; x++)
                {
                    byte r;
                    byte g;
                    byte b;
                    byte a = 255;
                    int  offset;

                    switch (format)
                    {
                    case PixelFormat.R8G8B8A8:
                        offset = (y * size.X + x) * 4;
                        r      = data[offset + 3];
                        g      = data[offset + 2];
                        b      = data[offset + 1];
                        a      = data[offset + 0];
                        break;

                    case PixelFormat.R8G8B8:
                        offset = (y * size.X + x) * 3;
                        r      = data[offset + 2];
                        g      = data[offset + 1];
                        b      = data[offset + 0];
                        break;

                    case PixelFormat.X8R8G8B8:
                        offset = (y * size.X + x) * 4;
                        r      = data[offset + 2];
                        g      = data[offset + 1];
                        b      = data[offset + 0];
                        break;

                    case PixelFormat.A8R8G8B8:
                        offset = (y * size.X + x) * 4;
                        a      = data[offset + 3];
                        r      = data[offset + 2];
                        g      = data[offset + 1];
                        b      = data[offset + 0];
                        break;

                    default:
                        hasAlpha  = false;
                        normalMap = false;
                        return(false);
                    }

                    if (a != 255)
                    {
                        hasAlpha = true;
                    }

                    if (normalMap)
                    {
                        var v = new Vector3F(r, g, b) / 255.0f;
                        v *= 2;
                        v -= new Vector3F(1, 1, 1);
                        var l = v.Length();
                        if (l > 0.75f && l < 1.25f)
                        {
                            normalMapCount++;
                        }
                        else
                        {
                            if (totalCount > 10000)
                            {
                                float p = (float)normalMapCount / totalCount;
                                if (p < .95f)
                                {
                                    normalMap = false;
                                }
                            }
                        }
                    }

                    totalCount++;
                }
            }

            if (normalMap)
            {
                float p = (float)normalMapCount / totalCount;
                if (p < .95f)
                    normalMap = false; }
            }
Example #8
0
 public SphereF(Vector3F origin, float radius)
 {
     this.Origin = origin;
     this.Radius = radius;
 }
        //private void Pipeline_RenderBegin( Component_RenderingPipeline_Basic sender, ViewportRenderingContext context, Component_RenderingPipeline_Basic.FrameData frameData )
        //{
        //	if( EnabledInHierarchy && sender.UseRenderTargets )
        //	{
        //		//frameData.GenerateIBLSpecularTexture = true;
        //		//frameData.DeferredSpecularIBLItensity = 1.0 - Intensity;
        //	}
        //}

        private void Pipeline_RenderDeferredShadingEnd(Component_RenderingPipeline_Basic sender, ViewportRenderingContext context, Component_RenderingPipeline_Basic.FrameData frameData, ref Component_Image sceneTexture)
        {
            if (EnabledInHierarchy && sender.GetUseMultiRenderTargets())
            {
                var actualTexture = sceneTexture;

                var pipeline = (Component_RenderingPipeline_Basic)context.RenderingPipeline;

                Vector3 cameraPos = context.Owner.CameraSettings.Position;
                //!!!!double
                Vector3F cameraPosition = cameraPos.ToVector3F();

                //!!!!double
                Matrix4F projectionMatrix = context.Owner.CameraSettings.ProjectionMatrix.ToMatrix4F();
                Matrix4F viewMatrix       = context.Owner.CameraSettings.ViewMatrix.ToMatrix4F();

                Matrix4F viewProjMatrix    = projectionMatrix * viewMatrix;
                Matrix4F invViewProjMatrix = viewProjMatrix.GetInverse();

                float aspectRatio = (float)context.Owner.CameraSettings.AspectRatio;
                float fov         = (float)context.Owner.CameraSettings.FieldOfView;
                float zNear       = (float)context.Owner.CameraSettings.NearClipDistance;
                float zFar        = (float)context.Owner.CameraSettings.FarClipDistance;

                var ambientLight      = frameData.Lights[frameData.LightsInFrustumSorted[0]];
                var ambientLightPower = ambientLight.data.Power;

                var reflectionTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, actualTexture.Result.ResultFormat);
                {
                    context.SetViewport(reflectionTexture.Result.GetRenderTarget().Viewports[0]);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ScreenSpaceReflection\SSR_fs.sc";

                    int maxSteps = 50;
                    switch (Quality.Value)
                    {
                    case QualityEnum.Lowest: maxSteps = 15; break;

                    case QualityEnum.Low: maxSteps = 25; break;

                    case QualityEnum.Medium: maxSteps = 40; break;

                    case QualityEnum.High: maxSteps = 60; break;

                    case QualityEnum.Highest: maxSteps = 100; break;
                    }

                    //int maxSteps = 50;
                    //switch( Quality.Value )
                    //{
                    //case QualityEnum.Lowest: maxSteps = 20; break;
                    //case QualityEnum.Low: maxSteps = 50; break;
                    //case QualityEnum.Medium: maxSteps = 80; break;
                    //case QualityEnum.High: maxSteps = 120; break;
                    //case QualityEnum.Highest: maxSteps = 160; break;
                    //}

                    shader.Defines.Add(new CanvasRenderer.ShaderItem.DefineItem("MAX_STEPS", maxSteps.ToString()));

                    context.objectsDuringUpdate.namedTextures.TryGetValue("gBuffer0Texture", out var gBuffer0Texture);
                    context.objectsDuringUpdate.namedTextures.TryGetValue("depthTexture", out var depthTexture);
                    context.objectsDuringUpdate.namedTextures.TryGetValue("normalTexture", out var normalTexture);
                    context.objectsDuringUpdate.namedTextures.TryGetValue("gBuffer2Texture", out var gBuffer2Texture);

                    //!!!!reflection probes?
                    pipeline.GetBackgroundEnvironmentTextures(context, frameData, /*true, */ out var environmentTexture, out var environmentTextureIBL);

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, depthTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1, actualTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(2, normalTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    //!!!!rotation, multiplier

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(3, environmentTexture.Value.texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(4, environmentTextureIBL.Value.texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(5, Component_RenderingPipeline_Basic.BrdfLUT,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(6, gBuffer2Texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.Point));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(7, gBuffer0Texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.Point));

                    //!!!часть параметров есть UniformsGeneral.sh

                    shader.Parameters.Set("viewProj", viewProjMatrix);
                    shader.Parameters.Set("invViewProj", invViewProjMatrix);
                    shader.Parameters.Set("cameraPosition", cameraPosition);
                    shader.Parameters.Set("edgeFactorPower", (float)EdgeFactorPower);
                    shader.Parameters.Set("initialStepScale", (float)InitialStepScale.Value);
                    shader.Parameters.Set("worldThickness", (float)WorldThickness.Value);

                    shader.Parameters.Set("colorTextureSize", new Vector4F((float)actualTexture.Result.ResultSize.X, (float)actualTexture.Result.ResultSize.Y, 0.0f, 0.0f));
                    shader.Parameters.Set("zNear", zNear);
                    shader.Parameters.Set("zFar", zFar);
                    shader.Parameters.Set("fov", fov);
                    shader.Parameters.Set("aspectRatio", aspectRatio);

                    context.RenderQuadToCurrentViewport(shader);
                }

                var min = BlurRoughnessMin.Value;
                var max = BlurRoughnessMax.Value;
                if (min > max)
                {
                    min = max;
                }
                var blurRoughnessMin = pipeline.GaussianBlur(context, this, reflectionTexture, min, BlurDownscalingMode, BlurDownscalingValue);
                var blurRoughnessMax = pipeline.GaussianBlur(context, this, reflectionTexture, max, BlurDownscalingMode, BlurDownscalingValue);
                //// Blur Pass:
                //var bluredReflection = pipeline.GaussianBlur( context, this, reflectionTexture, BlurFactorOnMaxRoughness, BlurDownscalingMode, BlurDownscalingValue );

                // Final Pass:
                var finalTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, actualTexture.Result.ResultFormat);
                {
                    context.SetViewport(finalTexture.Result.GetRenderTarget().Viewports[0]);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ScreenSpaceReflection\SSR_Apply_fs.sc";

                    context.objectsDuringUpdate.namedTextures.TryGetValue("gBuffer0Texture", out var gBuffer0Texture);
                    context.objectsDuringUpdate.namedTextures.TryGetValue("depthTexture", out var depthTexture);
                    context.objectsDuringUpdate.namedTextures.TryGetValue("normalTexture", out var normalTexture);
                    context.objectsDuringUpdate.namedTextures.TryGetValue("gBuffer2Texture", out var gBuffer2Texture);

                    //!!!!reflection probes?
                    pipeline.GetBackgroundEnvironmentTextures(context, frameData, /*true, */ out var environmentTexture, out var environmentTextureIBL);

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, actualTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1, blurRoughnessMin,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(2, blurRoughnessMax,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    //shader.Parameters.Set( "1", new GpuMaterialPass.TextureParameterValue( reflectionTexture,
                    //	TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None ) );

                    //shader.Parameters.Set( "2", new GpuMaterialPass.TextureParameterValue( bluredReflection,
                    //	TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None ) );

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(3, depthTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(4, normalTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    //!!!!rotation, multiplier

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(5, environmentTexture.Value.texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(6, environmentTextureIBL.Value.texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(7, Component_RenderingPipeline_Basic.BrdfLUT,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(8, gBuffer2Texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.Point));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(9, gBuffer0Texture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.Point));

                    shader.Parameters.Set("invViewProj", invViewProjMatrix);
                    shader.Parameters.Set("cameraPosition", cameraPosition);
                    shader.Parameters.Set("intensity", (float)Intensity);
                    shader.Parameters.Set("ambientLightPower", ambientLightPower);

                    context.RenderQuadToCurrentViewport(shader);
                }

                // Free Targets:
                context.DynamicTexture_Free(reflectionTexture);
                context.DynamicTexture_Free(blurRoughnessMin);
                context.DynamicTexture_Free(blurRoughnessMax);
                //context.RenderTarget_Free( bluredReflection );
                context.DynamicTexture_Free(actualTexture);

                // Update actual Texture:
                actualTexture = finalTexture;

                //result
                sceneTexture = actualTexture;
            }
        }
Example #10
0
        //!!!!было. сложно.
        //public bool Add( Vec3F p )
        //{
        //	if( radius < 0.0f )
        //	{
        //		origin = p;
        //		radius = 0.0f;
        //		return true;
        //	}
        //	else
        //	{
        //		float x = p.x - origin.x;
        //		float y = p.y - origin.y;
        //		float z = p.z - origin.z;
        //		float lengthSqr = x * x + y * y + z * z;
        //		float r = lengthSqr;
        //		//float r = ( p - origin ).LengthSqr();

        //		if( r > radius * radius )
        //		{
        //			r = MathEx.Sqrt( r );

        //			float coef = .5f * ( 1.0f - radius / r );
        //			origin.x += x * coef;
        //			origin.y += y * coef;
        //			origin.z += z * coef;
        //			//origin += ( p - origin ) * 0.5f * ( 1.0f - radius / r );

        //			radius += .5f * ( r - radius );
        //			return true;
        //		}
        //		return false;
        //	}
        //}

        static void ClosestPtPointTriangle(ref Vector3F p, ref Vector3F a, ref Vector3F b, ref Vector3F c, out Vector3F result)
        {
            Vector3F ab;

            Vector3F.Subtract(ref b, ref a, out ab);
            //Vec3 ab = b - a;

            Vector3F ac;

            Vector3F.Subtract(ref c, ref a, out ac);
            //Vec3 ac = c - a;

            Vector3F ap;

            Vector3F.Subtract(ref p, ref a, out ap);
            //Vec3 ap = p - a;

            float d1;

            Vector3F.Dot(ref ab, ref ap, out d1);
            float d2;

            Vector3F.Dot(ref ac, ref ap, out d2);
            if (d1 <= 0.0f && d2 <= 0.0f)
            {
                result = a;
                return;
            }

            //check if P in vertex region outside B
            Vector3F bp;

            Vector3F.Subtract(ref p, ref b, out bp);
            //Vec3 bp = p - b;
            float d3;

            Vector3F.Dot(ref ab, ref bp, out d3);
            float d4;

            Vector3F.Dot(ref ac, ref bp, out d4);
            if (d3 >= 0.0f && d4 <= d3)
            {
                result = b;
                return;
            }

            float vc = d1 * d4 - d3 * d2;

            if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f)
            {
                float v = d1 / (d1 - d3);
                result = a + v * ab;
                return;
            }

            Vector3F cp;

            Vector3F.Subtract(ref p, ref c, out cp);
            //Vec3 cp = p - c;
            float d5; Vector3F.Dot(ref ab, ref cp, out d5);
            float d6; Vector3F.Dot(ref ac, ref cp, out d6);

            if (d6 >= 0.0f && d5 <= d6)
            {
                result = c;
                return;
            }

            float vb = d5 * d2 - d1 * d6;

            if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f)
            {
                float w = d2 / (d2 - d6);
                result = a + w * ac;
                return;
            }

            float va = d3 * d6 - d5 * d4;

            if (va <= 0.0f && (d4 - d3) >= 0.0f && (d5 - d6) >= 0.0f)
            {
                float w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
                result = b + w * (c - b);
                return;
            }

            {
                float denom = 1.0f / (va + vb + vc);
                float v     = vb * denom;
                float w     = vc * denom;
                result = a + ab * v + ac * w;
                return;
            }
        }
Example #11
0
 public SphereF(SphereF source)
 {
     Origin = source.Origin;
     Radius = source.Radius;
 }
        void ProcessVertex(ref Vector3F position, out Vector3F result)
        {
            Matrix4? nullable = new Matrix4?(PosCenter.Value.ToMatrix4());
            Matrix4  matrix4  = nullable ?? Matrix4.Identity;
            Matrix4F matrix4f = matrix4.ToMatrix4F();
            bool     inv      = matrix4f.Inverse();

            MatrixInv = inv;

            ResPosVec1 = matrix4f * Pos1n.Value.Position.ToVector3F();

            result = position;
            var sc        = new Vector3F(0.2f, 0.2f, 0.2f);
            var rposition = position * sc;

            var   l_r01   = (float)Pos01n.Value.Scale.X;
            var   relp01  = (Pos01n.Value.Position).ToVector3F();
            var   l_dist1 = (rposition - relp01);
            float l_l01   = l_dist1.Length();

            var   l_r02   = (float)Pos02n.Value.Scale.X;
            var   relp02  = (Pos02n.Value.Position).ToVector3F();
            var   l_dist2 = (rposition - relp02);
            float l_l02   = l_dist2.Length();

            var   l_r03   = (float)Pos03n.Value.Scale.X;
            var   relp03  = (Pos03n.Value.Position).ToVector3F();
            var   l_dist3 = (rposition - relp03);
            float l_l03   = l_dist3.Length();

            var   l_r04   = (float)Pos04n.Value.Scale.X;
            var   relp04  = (Pos04n.Value.Position).ToVector3F();
            var   l_dist4 = (rposition - relp04);
            float l_l04   = l_dist4.Length();

            var f = ((ResPos1.Value.Position - PosCenter.Value.Position) / sc).ToVector3F().GetNormalize();
            SphericalDirectionF sd = new SphericalDirectionF(f.X, f.Y);
            float       ax         = MathEx.Acos(f.X);
            float       ay         = MathEx.Asin(f.X);
            QuaternionF q          = new AnglesF().ToQuaternion();


            if (l_l01 <= l_r01)
            {
                var relp1 = matrix4f * Pos1n.Value.Position.ToVector3F();
                result = relp1;
            }
            if (l_l02 <= l_r02)
            {
                var relp2 = matrix4f * Pos2n.Value.Position.ToVector3F();;
                result = relp2;
            }
            if (l_l03 <= l_r03)
            {
                var relp3 = matrix4f * Pos3n.Value.Position.ToVector3F();;
                result = relp3;
            }
            if (l_l04 <= l_r04)
            {
                var relp4 = matrix4f * Pos4n.Value.Position.ToVector3F();;
                result = relp4;
            }
        }
Example #13
0
 /// <summary>
 /// Rounds a given vector towards zero for each component in it and returns the truncated vector.
 /// </summary>
 /// <param name="v">The vector to truncate.</param>
 /// <returns>The truncated vector</returns>
 public Vector3F GetTruncate(Vector3F v)
 {
     return(new Vector3F((int)v.X, (int)v.Y, (int)v.Z));
 }
Example #14
0
 /// <summary>
 /// Rounds the current instance of <see cref="Vector3F"/> towards zero for each component in a vector.
 /// </summary>
 /// <param name="v"></param>
 public void Truncate(Vector3F v)
 {
     X = (int)X;
     Y = (int)Y;
     Z = (int)Z;
 }
Example #15
0
 public CapsuleF(Vector3F point1, Vector3F point2, float radius)
 {
     this.Point1 = point1;
     this.Point2 = point2;
     this.Radius = radius;
 }
Example #16
0
 public RayF(RayF source)
 {
     Origin    = source.Origin;
     Direction = source.Direction;
 }
Example #17
0
        //

        static SimpleTypes()
        {
            //string
            RegisterType(typeof(string), delegate(string value)
            {
                if (value == null)
                {
                    return("");
                    //throw new Exception( "GetSimpleTypeValue: string type, value = null" );
                }
                return(value);
            }, "");

            //bool
            RegisterType(typeof(bool), delegate(string value)
            {
                string lower = value.ToLower();
                if (value == "1" || lower == "yes" || lower == "true")
                {
                    return(true);
                }
                else if (value == "0" || lower == "no" || lower == "false")
                {
                    return(false);
                }
                else
                {
                    return(bool.Parse(value));
                }
            }, false);

            //sbyte
            RegisterType(typeof(sbyte), delegate(string value) { return(sbyte.Parse(value)); }, 0);

            //byte
            RegisterType(typeof(byte), delegate(string value) { return(byte.Parse(value)); }, 0);

            //char
            RegisterType(typeof(char), delegate(string value) { return(char.Parse(value)); }, 0);

            //short
            RegisterType(typeof(short), delegate(string value) { return(short.Parse(value)); }, 0);

            //ushort
            RegisterType(typeof(ushort), delegate(string value) { return(ushort.Parse(value)); }, 0);

            //int
            RegisterType(typeof(int), delegate(string value) { return(int.Parse(value)); }, 0);

            //uint
            RegisterType(typeof(uint), delegate(string value) { return(uint.Parse(value)); }, (uint)0);

            //long
            RegisterType(typeof(long), delegate(string value) { return(long.Parse(value)); }, (long)0);

            //ulong
            RegisterType(typeof(ulong), delegate(string value) { return(ulong.Parse(value)); }, (ulong)0);

            //float
            RegisterType(typeof(float), delegate(string value) { return(float.Parse(value)); }, 0.0f);

            //double
            RegisterType(typeof(double), delegate(string value) { return(double.Parse(value)); }, 0.0);

            //decimal
            RegisterType(typeof(decimal), delegate(string value) { return(decimal.Parse(value)); }, (decimal)0.0);

            //Vec2
            RegisterType(typeof(Vector2F), delegate(string value) { return(Vector2F.Parse(value)); }, Vector2F.Zero);

            //Range
            RegisterType(typeof(RangeF), delegate(string value) { return(RangeF.Parse(value)); }, RangeF.Zero);

            //Vec3
            RegisterType(typeof(Vector3F), delegate(string value) { return(Vector3F.Parse(value)); }, Vector3F.Zero);

            //Vec4
            RegisterType(typeof(Vector4F), delegate(string value) { return(Vector4F.Parse(value)); }, Vector4F.Zero);

            //Bounds
            RegisterType(typeof(BoundsF), delegate(string value) { return(BoundsF.Parse(value)); }, BoundsF.Zero);

            //Quat
            RegisterType(typeof(QuaternionF), delegate(string value) { return(QuaternionF.Parse(value)); }, QuaternionF.Identity);

            //ColorValue
            RegisterType(typeof(ColorValue), delegate(string value) { return(ColorValue.Parse(value)); }, ColorValue.Zero);

            //ColorValuePowered
            RegisterType(typeof(ColorValuePowered), delegate(string value) { return(ColorValuePowered.Parse(value)); }, ColorValuePowered.Zero);

            //ColorPacked
            RegisterType(typeof(ColorByte), delegate(string value) { return(ColorByte.Parse(value)); }, ColorByte.Zero);

            //SphereDir
            RegisterType(typeof(SphericalDirectionF), delegate(string value) { return(SphericalDirectionF.Parse(value)); }, SphericalDirectionF.Zero);

            //Vec2I
            RegisterType(typeof(Vector2I), delegate(string value) { return(Vector2I.Parse(value)); }, Vector2I.Zero);

            //Vec3I
            RegisterType(typeof(Vector3I), delegate(string value) { return(Vector3I.Parse(value)); }, Vector3I.Zero);

            //Vec4I
            RegisterType(typeof(Vector4I), delegate(string value) { return(Vector4I.Parse(value)); }, Vector4I.Zero);

            //Rect
            RegisterType(typeof(RectangleF), delegate(string value) { return(RectangleF.Parse(value)); }, RectangleF.Zero);

            //RectI
            RegisterType(typeof(RectangleI), delegate(string value) { return(RectangleI.Parse(value)); }, RectangleI.Zero);

            //Degree
            RegisterType(typeof(DegreeF), delegate(string value) { return(DegreeF.Parse(value)); }, DegreeF.Zero);

            //Radian
            RegisterType(typeof(RadianF), delegate(string value) { return(RadianF.Parse(value)); }, RadianF.Zero);

            //Vec2D
            RegisterType(typeof(Vector2), delegate(string value) { return(Vector2.Parse(value)); }, Vector2.Zero);

            //RangeD
            RegisterType(typeof(Range), delegate(string value) { return(Range.Parse(value)); }, Range.Zero);

            //RangeI
            RegisterType(typeof(RangeI), delegate(string value) { return(RangeI.Parse(value)); }, RangeI.Zero);

            //Vec3D
            RegisterType(typeof(Vector3), delegate(string value) { return(Vector3.Parse(value)); }, Vector3.Zero);

            //Vec4D
            RegisterType(typeof(Vector4), delegate(string value) { return(Vector4.Parse(value)); }, Vector4.Zero);

            //BoundsD
            RegisterType(typeof(Bounds), delegate(string value) { return(Bounds.Parse(value)); }, Bounds.Zero);

            //QuatD
            RegisterType(typeof(Quaternion), delegate(string value) { return(Quaternion.Parse(value)); }, Quaternion.Identity);

            //SphereDirD
            RegisterType(typeof(SphericalDirection), delegate(string value) { return(SphericalDirection.Parse(value)); }, SphericalDirection.Zero);

            //RectD
            RegisterType(typeof(Rectangle), delegate(string value) { return(Rectangle.Parse(value)); }, Rectangle.Zero);

            //DegreeD
            RegisterType(typeof(Degree), delegate(string value) { return(Degree.Parse(value)); }, Degree.Zero);

            //RadianD
            RegisterType(typeof(Radian), delegate(string value) { return(Radian.Parse(value)); }, Radian.Zero);

            //Angles
            RegisterType(typeof(AnglesF), delegate(string value) { return(AnglesF.Parse(value)); }, AnglesF.Zero);

            //AnglesD
            RegisterType(typeof(Angles), delegate(string value) { return(Angles.Parse(value)); }, Angles.Zero);

            //Mat2F
            RegisterType(typeof(Matrix2F), delegate(string value) { return(Matrix2F.Parse(value)); }, Matrix2F.Zero);

            //Mat2D
            RegisterType(typeof(Matrix2), delegate(string value) { return(Matrix2.Parse(value)); }, Matrix2.Zero);

            //Mat3F
            RegisterType(typeof(Matrix3F), delegate(string value) { return(Matrix3F.Parse(value)); }, Matrix3F.Zero);

            //Mat3D
            RegisterType(typeof(Matrix3), delegate(string value) { return(Matrix3.Parse(value)); }, Matrix3.Zero);

            //Mat4F
            RegisterType(typeof(Matrix4F), delegate(string value) { return(Matrix4F.Parse(value)); }, Matrix4F.Zero);

            //Mat4D
            RegisterType(typeof(Matrix4), delegate(string value) { return(Matrix4.Parse(value)); }, Matrix4.Zero);

            //PlaneF
            RegisterType(typeof(PlaneF), delegate(string value) { return(PlaneF.Parse(value)); }, PlaneF.Zero);

            //PlaneD
            RegisterType(typeof(Plane), delegate(string value) { return(Plane.Parse(value)); }, Plane.Zero);

            //Transform
            RegisterType(typeof(Transform), delegate(string value) { return(Transform.Parse(value)); }, Transform.Identity);

            //UIMeasureValueDouble
            RegisterType(typeof(UIMeasureValueDouble), delegate(string value) { return(UIMeasureValueDouble.Parse(value)); }, new UIMeasureValueDouble());

            //UIMeasureValueVec2
            RegisterType(typeof(UIMeasureValueVector2), delegate(string value) { return(UIMeasureValueVector2.Parse(value)); }, new UIMeasureValueVector2());

            //UIMeasureValueRect
            RegisterType(typeof(UIMeasureValueRectangle), delegate(string value) { return(UIMeasureValueRectangle.Parse(value)); }, new UIMeasureValueRectangle());

            RegisterType(typeof(RangeVector3F), delegate(string value) { return(RangeVector3F.Parse(value)); }, RangeVector3F.Zero);
            RegisterType(typeof(RangeColorValue), delegate(string value) { return(RangeColorValue.Parse(value)); }, RangeColorValue.Zero);

            //no Parse methods. This is complex structures. This is not simple types? or just can't parse?
            //Box
            //Capsule
            //Cone
            //Line3
            //Line2
            //Ray
            //Frustum?

            RegisterConvertDoubleToFloatTypes();
        }
Example #18
0
 public RayF(Vector3F origin, Vector3F direction)
 {
     this.Origin    = origin;
     this.Direction = direction;
 }
Example #19
0
        public static object ExtractOneComponentArray(StandardVertex[] vertices, Components component)
        {
            switch (component)
            {
            case Components.Position:
            {
                Vector3F[] array = new Vector3F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Position;
                }
                return(array);
            }

            case Components.Normal:
            {
                Vector3F[] array = new Vector3F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Normal;
                }
                return(array);
            }

            case Components.Tangent:
            {
                Vector4F[] array = new Vector4F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Tangent;
                }
                return(array);
            }

            case Components.Color:
            {
                ColorValue[] array = new ColorValue[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].Color;
                }
                return(array);
            }

            case Components.TexCoord0:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord0;
                }
                return(array);
            }

            case Components.TexCoord1:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord1;
                }
                return(array);
            }

            case Components.TexCoord2:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord2;
                }
                return(array);
            }

            case Components.TexCoord3:
            {
                Vector2F[] array = new Vector2F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].TexCoord3;
                }
                return(array);
            }

            case Components.BlendIndices:
            {
                Vector4I[] array = new Vector4I[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].BlendIndices;
                }
                return(array);
            }

            case Components.BlendWeights:
            {
                Vector4F[] array = new Vector4F[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    array[n] = vertices[n].BlendWeights;
                }
                return(array);
            }
            }

            Log.Fatal("StandardVertex: ExtractOneComponentArray: Invalid requested component.");
            return(null);
        }
Example #20
0
 public void GetPointOnRay(float t, out Vector3F result)
 {
     result.X = Origin.X + Direction.X * t;
     result.Y = Origin.Y + Direction.Y * t;
     result.Z = Origin.Z + Direction.Z * t;
 }
Example #21
0
 public RangeVector3F(RangeVector3F a)
 {
     Minimum = a.Minimum;
     Maximum = a.Maximum;
 }
 public static BulletSharp.Math.Vector3 Convert(Vector3F v)
 {
     return(new BulletSharp.Math.Vector3(v.X, v.Y, v.Z));
 }
Example #23
0
            //

            public KeyFrame(float time, int boneIndex, Vector3F position, QuaternionF rotation, Vector3F scale)
            {
                this.Time      = time;
                this.BoneIndex = boneIndex;
                this.Position  = position;
                this.Rotation  = rotation;
                this.Scale     = scale;
            }
 public static void Convert(ref Vector3F v, out BulletSharp.Math.Vector3 result)
 {
     result = new BulletSharp.Math.Vector3(v.X, v.Y, v.Z);
 }
        /////////////////////////////////////////

        void ProcessVertex(float multiplier, float multiplier1, float invMultiplier, ref Vector3F position, out Vector3F result)
        {
            var   random = new Random(position.GetHashCode());
            float nposx  = 0;
            float Ax     = 0;
            float nposy  = 0;
            float Ay     = 0;
            float nposz  = 0;
            float Az     = 0;
            float ofs1   = off1;
            float ofs2   = off2;

            result = position;


            if (posN == 1)
            {
                if (sigN == 1 && position.X <= (float)Multiplier2)
                {
                    Ax    = multiplier * (float)Math.Exp(-position.Z * position.Z * multiplier1);
                    nposx = position.X + Math.Sign(position.X) * (Ax * ((float)Math.Exp(-position.Y * position.Y * multiplier1)));
                    if (nposx > (float)Multiplier2)
                    {
                        nposx = (float)Multiplier2;
                    }

                    result = new Vector3F(
                        nposx,
                        position.Y,
                        position.Z);
                }
                if (sigN == -1 && position.X > (float)Multiplier2)
                {
                    Ax    = multiplier * (float)Math.Exp(-position.Z * position.Z * multiplier1);
                    nposx = position.X + Math.Sign(position.X) * (Ax * ((float)Math.Exp(-position.Y * position.Y * multiplier1)));
                    if (nposx < (float)Multiplier2)
                    {
                        nposx = (float)Multiplier2;
                    }

                    result = new Vector3F(
                        nposx,
                        position.Y,
                        position.Z);
                }
            }
            else if (posN == 2)
            {
                if (sigN == 1 && position.Y <= (float)Multiplier2)
                {
                    Ay    = multiplier * (float)Math.Exp(-position.Z * position.Z * multiplier1);
                    nposy = position.Y + Math.Sign(position.Y) * (Ay * ((float)Math.Exp(-position.X * position.X * multiplier1)));
                    if (nposy > (float)Multiplier2)
                    {
                        nposy = (float)Multiplier2;
                    }

                    result = new Vector3F(
                        position.X,
                        nposy,
                        position.Z);
                }
                if (sigN == -1 && position.Y > (float)Multiplier2)
                {
                    Ay    = multiplier * (float)Math.Exp(-position.Z * position.Z * multiplier1);
                    nposy = position.Y + Math.Sign(position.Y) * (Ay * ((float)Math.Exp(-position.X * position.X * multiplier1)));
                    if (nposy < (float)Multiplier2)
                    {
                        nposy = (float)Multiplier2;
                    }

                    result = new Vector3F(
                        position.X,
                        nposy,
                        position.Z);
                }
            }
            else if (posN == 3)
            {
                if (sigN == 1 && position.Z <= (float)Multiplier2)
                {
                    Az    = multiplier * (float)Math.Exp(-(position.X - ofs2) * (position.X - ofs2) * multiplier1);
                    nposz = position.Z + Math.Sign(position.Z) * (Az * ((float)Math.Exp(-(position.Y - ofs1) * (position.Y - ofs1) * multiplier1)));
                    if (nposz > (float)Multiplier2)
                    {
                        nposz = (float)Multiplier2;
                    }

                    result = new Vector3F(
                        position.X,
                        position.Y,
                        nposz);
                }
                if (sigN == -1 && position.Z > (float)Multiplier2)
                {
                    Az    = multiplier * (float)Math.Exp(-(position.X - ofs2) * (position.X - ofs2) * multiplier1);
                    nposz = position.Z + Math.Sign(position.Z) * (Az * ((float)Math.Exp(-(position.Y - ofs1) * (position.Y - ofs1) * multiplier1)));
                    if (nposz < (float)Multiplier2)
                    {
                        nposz = (float)Multiplier2;
                    }

                    result = new Vector3F(
                        position.X,
                        position.Y,
                        nposz);
                }
            }
        }
Example #26
0
 public void GetDirection(out Vector3F result)
 {
     Vector3F.Subtract(ref Point2, ref Point1, out result);
     result.Normalize();
 }
Example #27
0
 public EnvironmentTextureData(Component_Image texture)
 {
     this.texture    = texture;
     this.rotation   = Matrix3F.Identity;
     this.multiplier = Vector3F.One;
 }
Example #28
0
 public CapsuleF(CapsuleF source)
 {
     Point1 = source.Point1;
     Point2 = source.Point2;
     Radius = source.Radius;
 }
Example #29
0
 /// <summary>
 /// Constructs a cone with the given origin, axis and angle.
 /// </summary>
 /// <param name="origin">The origin.</param>
 /// <param name="axis">The axis.</param>
 /// <param name="angle">The angle.</param>
 public ConeF(Vector3F origin, Vector3F axis, RadianF angle)
 {
     this.Origin = origin;
     this.Axis   = axis;
     this.Angle  = angle;
 }
Example #30
0
 /// <summary>
 /// Calculates the distance between two vectors.
 /// </summary>
 /// <param name="v1">The first vector.</param>
 /// <param name="v2">The second vector.</param>
 /// <returns>The distance between two vectors.</returns>
 public static float Distance(ref Vector3F v1, ref Vector3F v2)
 {
     Subtract(ref v1, ref v2, out Vector3F result);
     return(result.Length());
 }