Example #1
0
 public Matrix4f(Vector4f r0, Vector4f r1, Vector4f r2, Vector4f r3)
 {
     R0 = r0;
     R1 = r1;
     R2 = r2;
     R3 = r3;
 }
Example #2
0
        public static Vector4f ExtractBackgroundColor( Vector4f composite, Vector4f foreground )
        {
            // c = composite, f = foreground, b = background
            // red channel:
	        // c_r = f_a * f_r + ( 1 - f_a ) * b_r
	        // ==> b_r = ( c_r - f_a * f_r ) / ( 1 - f_a )
	        //
	        // alpha channel:
	        // c_a = f_a + b_a * ( 1 - f_a )
	        // ==> b_a = ( c_a - f_a ) / ( 1 - f_a )

            Vector3f compositeRGB = composite.XYZ;
            Vector3f foregroundRGB = foreground.XYZ;
            float ca = composite.w;
            float fa = foreground.w;

            if( fa > 0 && fa < 1 ) // partially transparent
            {
                var backgroundRGB = new Vector3f( compositeRGB - fa * foregroundRGB ) / ( 1.0f - fa );
                var ba = ( ca - fa ) / ( 1 - fa );

                return new Vector4f( backgroundRGB, ba ).Saturate();
            }
            else if( fa < 0.5f ) // foreground is fully transparent: background = input
            {
                return composite;
            }
            else // fa == 1, foreground is completely opaque, have no idea what the background is, return opaque black
            {
                // return new Vector4f( 0, 0, 0, 1 );
                return Vector4f.Zero;
            }
        }
Example #3
0
File: Bsp.cs Project: Frassle/Ibasa
 internal Surface(Vector4f s, Vector4f t, int textureIndex, int flags)
 {
     S = s;
     T = t;
     TextureIndex = textureIndex;
     Flags = flags;
 }
 public VertexPosition4fColor4ub( Vector4f position, byte r, byte g, byte b, byte a )
 {
     this.position = position;
     this.r = r;
     this.g = g;
     this.b = b;
     this.a = a;
 }        
Example #5
0
 public Vector4f Add(Vector4f other)
 {
     Vector4f res = new Vector4f();
     res.x = this.x + other.x;
     res.y = this.y + other.y;
     res.z = this.z + other.z;
     res.w = this.w + other.w;
     return res;
 }
Example #6
0
File: Vvd.cs Project: Frassle/Ibasa
 internal Vertex(ImmutableArray<BoneWeight> boneWeights,
     Vector3f position, Vector3f normal, Vector2f textureCoordinates, Vector4f tangent)
 {
     BoneWeights = boneWeights;
     Position = position;
     Normal = normal;
     TextureCoordinates = textureCoordinates;
     Tangent = tangent;
 }
Example #7
0
        public void Apply( Image4f input, Image4f output )
        {
            Vector4f[,] controlPoints = new Vector4f[ 4, 4 ];

            int w_out = output.Width;
            int h_out = output.Height;

            int w_in = input.Width;
            int h_in = input.Height;

            // scaling coefficients
            float x_outToIn = Arithmetic.DivideIntsToFloat( w_in, w_out );
            float y_outToIn = Arithmetic.DivideIntsToFloat( h_in, h_out );

            for( int yOut = 0; yOut < h_out; ++yOut )
            {
                float yInFloat = ( yOut + 0.5f ) * y_outToIn;
                int yIn0 = yInFloat.FloorToInt() - 1;
                int yIn1 = yIn0 + 3;

                for( int xOut = 0; xOut < w_out; ++xOut )
                {
                    float xInFloat = ( xOut + 0.5f ) * x_outToIn;
                    int xIn0 = xInFloat.FloorToInt() - 1;
                    int xIn1 = xIn0 + 3;

                    // grab the 16 control points
                    for( int yc = yIn0; yc <= yIn1; ++yc )
                    {   
                        int dy = yc - yIn0;
                        int ycc = Arithmetic.Clamp( yc, 0, h_in );                        

                        for( int xc = xIn0; xc <= xIn1; ++xc )
                        {
                            int dx = xc - xIn0;
                            int xcc = Arithmetic.Clamp( xc, 0, w_in );
                            
                            controlPoints[ xc, yc ] = input[ xcc, ycc ];
                        }
                    }
                    
                    // compute Catmull-Rom splines in the x direction
                    float tx = Arithmetic.FractionalPart( xInFloat );
                    float ty = Arithmetic.FractionalPart( yInFloat );

                    var v0i = EvaluateSpline( controlPoints[ 0, 0 ], controlPoints[ 0, 1 ], controlPoints[ 0, 2 ], controlPoints[ 0, 3 ], tx );
                    var v1i = EvaluateSpline( controlPoints[ 1, 0 ], controlPoints[ 1, 1 ], controlPoints[ 1, 2 ], controlPoints[ 1, 3 ], tx );
                    var v2i = EvaluateSpline( controlPoints[ 2, 0 ], controlPoints[ 2, 1 ], controlPoints[ 2, 2 ], controlPoints[ 2, 3 ], tx );
                    var v3i = EvaluateSpline( controlPoints[ 3, 0 ], controlPoints[ 3, 1 ], controlPoints[ 3, 2 ], controlPoints[ 3, 3 ], tx );

                    var vii = EvaluateSpline( v0i, v1i, v2i, v3i, ty );
                    
                    output[ xOut, yOut ] = vii;
                }
            }
        }
Example #8
0
 public static LineItem[] MakeRectangle( Rect2f rect, Vector4f color )
 {
     return new[]
     {
         new LineItem( rect.Origin, rect.BottomRight, color ), 
         new LineItem( rect.BottomRight, rect.TopRight, color ), 
         new LineItem( rect.TopRight, rect.TopLeft, color ), 
         new LineItem( rect.TopLeft, rect.Origin, color )
     };
 }
Example #9
0
        public LineItem( Vector4f p0, Vector4f c0,
            Vector4f p1, Vector4f c1 )
        {
            P0 = p0;
            C0 = c0;
            P1 = p1;
            C1 = c1;

            BlendType = BlendType.Opaque;
        }
Example #10
0
        // TODO: from 4 points?

        /// <summary>
        /// Construct a plane given a point on the plane and its normal (does not need to be unit length)
        /// </summary>
        /// <param name="p"></param>
        /// <param name="normal"></param>
        public Plane4f( Vector4f p, Vector4f normal )
        {
            var unitNormal = normal.Normalized();
            e = -Vector4f.Dot( unitNormal, p );

            a = unitNormal.x;
            b = unitNormal.y;
            c = unitNormal.z;
            d = unitNormal.w;
        }
Example #11
0
 public Matrix4f(
     float m11, float m12, float m13, float m14,
     float m21, float m22, float m23, float m24,
     float m31, float m32, float m33, float m34,
     float m41, float m42, float m43, float m44)
 {
     R0 = new Vector4f(m11, m12, m13, m14);
     R1 = new Vector4f(m21, m22, m23, m24);
     R2 = new Vector4f(m31, m32, m33, m34);
     R3 = new Vector4f(m41, m42, m43, m44);
 }
Example #12
0
 private Terrain(IOpenGL33 gl, IVertexArray vertexArray, IVertexBuffer vertexBuffer, IElementArray elementBuffer, TerrainShader shader)
 {
     _gl = gl;
     _vertexArray = vertexArray;
     _vertexBuffer = vertexBuffer;
     _elementBuffer = elementBuffer;
     _shader = shader;
     Model = Matrix4f.Identity;
     View = Matrix4f.Identity;
     Projection = Matrix4f.Identity;
     Diffuse = new Vector4f(Color.DodgerBlue.R / 255f, Color.DodgerBlue.G / 255f, Color.DodgerBlue.B / 255f, 1f);
 }
Example #13
0
        public static Vector4f Over( Vector4f foreground, Vector4f background )
        {
            // c = composite, f = foreground, b = background
            // red channel:
	        // c_r = f_a * f_r + ( 1 - f_a ) * b_r
	        //
	        // alpha channel:
	        // c_a = f_a + b_a * ( 1 - f_a )
            Vector3f rgb = foreground.w * foreground.XYZ + ( 1.0f - foreground.w ) * background.XYZ;
            float a = foreground.w + background.w * ( 1 - foreground.w );

            return new Vector4f( rgb, a );
        }
Example #14
0
        public void GetRow_ReturnsCorrectRow(int index)
        {
            // Arrange
            var vectors = new Vector4f[4];
            vectors[index] = new Vector4f(1, 2, 3, 4);
            var mat = new Matrix4f(vectors[0], vectors[1], vectors[2], vectors[3]);

            // Act
            var theRow = mat.Row(index);

            // Assert
            Assert.That(theRow, Is.EqualTo(new Vector4f(1, 2, 3, 4)));
        }
Example #15
0
        public TriangleItem( Vector4f p0, Vector4f p1, Vector4f p2,
            Vector4f c0, Vector4f c1, Vector4f c2, BlendType blendType )
        {
            P0 = p0;
            P1 = p1;
            P2 = p2;

            C0 = c0;
            C1 = c1;
            C2 = c2;

            BlendType = blendType;
        }
Example #16
0
 public TriangleItem
     (
         Vector2f p0, Vector2f p1, Vector2f p2,
         Vector4f c0, Vector4f c1, Vector4f c2,
         BlendType blendType
     )
     : this
     (
         new Vector4f( p0, 0, 1 ), new Vector4f( p1, 0, 1 ), new Vector4f( p2, 0, 1 ),
         c0, c1, c2,
         blendType
     )
 {
     
 }
Example #17
0
        /// <summary>
        /// TODO: C# 4.0: default to 0,0,0,0 and 1,1,1,1
        /// 
        /// intensities between blackPoint and whitePoint are linearly scaled between 0 and 1.
        /// intensities < blackPoint are clamped to 0, intensities > whitePoint are clamped to 1.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="blackPoint"></param>
        /// <param name="whitePoint"></param>
        public static void Apply( Image4f input, Image4ub output,
            Vector4f blackPoint, Vector4f whitePoint )
        {
            if( input.Size != output.Size )
            {
                throw new ArgumentException( "input and output must be of the same size" );
            }
            var range = whitePoint - blackPoint;

            for( int k = 0; k < input.NumPixels; ++k )
            {
                Vector4f p = input[ k ];
                Vector4f q = ( p - blackPoint ) / range;
                Vector4ub r = q.ToUnsignedByte();

                output[ k ] = r;
            }
        }
Example #18
0
        // TODO: clean this up, this is a huge mess
        // Intersection namespace, with one for each pair?
        public static bool HyperplaneHypercubeIntersection( Vector4f[] hcVertices,
            Plane4f plane )
        {
            bool foundNegative = false;
            bool foundPositive = false;

            for ( int i = 0; i < 16; ++i )
            {
                float val = plane.Distance( hcVertices[ i ] );

                if ( val < 0 )
                {
                    foundNegative = true;
                }
                else if ( val > 0 )
                {
                    foundPositive = true;
                }
            }

            return foundNegative && foundPositive;
        }
Example #19
0
        public static TriangleItem[] MakeSquare( Vector2f center, float radius, Vector4f color, BlendType blendType )
        {
            return new[]
            {
                new TriangleItem
                (
                    new Vector2f( center.X - radius, center.Y - radius ),
                    new Vector2f( center.X + radius, center.Y - radius ),
                    new Vector2f( center.X - radius, center.Y + radius ),
                    color,
                    blendType
                ),

                new TriangleItem
                (
                    new Vector2f( center.X - radius, center.Y + radius ),
                    new Vector2f( center.X + radius, center.Y - radius ),
                    new Vector2f( center.X + radius, center.Y + radius ),
                    color,
                    blendType
                )
            };
        }
Example #20
0
 public static Vector4f zxzz(this Vector4f v)
 {
     return(new Vector4f(v.z, v.x, v.z, v.z));
 }
Example #21
0
 /// <summary>Get the nearest point between this <see cref="Box4f"/> and a <see cref="Vector4f"/>. If the <see cref="Vector4f"/> is inside this <see cref="Box4f"/>, it is returned untouched.</summary>
 public Vector4f NearestPointTo( Vector4f point )
 {
     Vector4f result;
         Containment containment = Intersect(ref point);
         if(containment != Containment.Disjoint)
             result = point;
         else
             point.Clamp(ref Min, ref Max, out result);
         return result;
 }
Example #22
0
 public static Vector2f zw(this Vector4f v)
 {
     return(new Vector2f(v.z, v.w));
 }
Example #23
0
 public static Vector4f zywx(this Vector4f v)
 {
     return(new Vector4f(v.z, v.y, v.w, v.x));
 }
Example #24
0
 public static Vector4f xxwy(this Vector4f v)
 {
     return(new Vector4f(v.x, v.x, v.w, v.y));
 }
Example #25
0
 public static Vector3f xxx(this Vector4f v)
 {
     return(new Vector3f(v.x, v.x, v.x));
 }
Example #26
0
 public static Vector4f zxww(this Vector4f v)
 {
     return(new Vector4f(v.z, v.x, v.w, v.w));
 }
Example #27
0
        /// <summary>
        /// Screen (pixel) to world
        /// </summary>
        /// <param name="src"></param>
        /// <param name="frame"></param>
        /// <returns></returns>
        public Vector3f UnprojectedCoordinatesOf( Vector3f src, Frame frame )
        {
            float x = 2 * src.x / ScreenSize.x - 1;
            float y = 2 * src.y / ScreenSize.y - 1;
            float z = src.z;
           
            var clip = new Vector4f( x, y, z, 1 );
            var eye = InverseProjectionMatrix * clip;
            var world = ( InverseViewMatrix * eye ).Homogenized();

            if( frame != null )
            {
                return Frame.CoordinatesOf( world );
            }
            else
            {
                return world;
            }
        }        
Example #28
0
 public static Vector4f zwwz(this Vector4f v)
 {
     return(new Vector4f(v.z, v.w, v.w, v.z));
 }
Example #29
0
 public static Vector3f zwx(this Vector4f v)
 {
     return(new Vector3f(v.z, v.w, v.x));
 }
Example #30
0
 public static Vector3f yzx(this Vector4f v)
 {
     return(new Vector3f(v.y, v.z, v.x));
 }
Example #31
0
 public static Vector4f yxwz(this Vector4f v)
 {
     return(new Vector4f(v.y, v.x, v.w, v.z));
 }
Example #32
0
 public static Vector4f yzzz(this Vector4f v)
 {
     return(new Vector4f(v.y, v.z, v.z, v.z));
 }
Example #33
0
 /// <summary>Get whether this <see cref="Box4f"/> inclusively intersects with the <see cref="Vector4f"/>.</summary>
 public bool Overlaps( ref  Vector4f point)
 {
     return  point.X >= Min.X && point.X <= Max.X && point.Y >= Min.Y && point.Y <= Max.Y && point.Z >= Min.Z && point.Z <= Max.Z && point.W >= Min.W && point.W <= Max.W ;
 }
Example #34
0
 public static Vector4f xyww(this Vector4f v)
 {
     return(new Vector4f(v.x, v.y, v.w, v.w));
 }
Example #35
0
        private static Vector4f EvaluateSpline( Vector4f p0, Vector4f p1, Vector4f p2, Vector4f p3, float t )
        {
            var c0 = p1;
            var c1 = 0.5f * ( p2 - p0 );
            var c2 = p0 - 2.5f * p1 + 2 * p2 - 0.5f * p3;
            var c3 = -0.5f * p0 + 1.5f * p1 - 1.5f * p2 + 0.5f * p3;
            
            float t2 = t * t;
            float t3 = t2 * t;

            return c0 + c1 * t + c2 * t2 + c3 * t3;
        }
Example #36
0
 public static Vector4f yzww(this Vector4f v)
 {
     return(new Vector4f(v.y, v.z, v.w, v.w));
 }
Example #37
0
 public static Vector4f wzwy(this Vector4f v)
 {
     return(new Vector4f(v.w, v.z, v.w, v.y));
 }
Example #38
0
 /// <summary>
 /// Projects the point p to the point q closest to p on the plane.
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public Vector4f ClosestPointOnPlane( Vector4f p )
 {
     float d = Distance( p );
     return( p - d * UnitNormal );
 }
Example #39
0
 public static Vector4f zyzy(this Vector4f v)
 {
     return(new Vector4f(v.z, v.y, v.z, v.y));
 }
Example #40
0
        /// <summary>
        /// Sets the constant.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public unsafe void SetConstant(string name, object value)
        {
            AssertNotDisposed();
            if (lockedData == null)
            {
                throw new InvalidOperationException("The buffer is not mapped, cannot set constant.");
            }

            // We set constant (throws if not found).
            uint      offset, arraySize;
            PinFormat format;

            if (!layout.TryGetData(name, out offset, out format, out arraySize))
            {
                throw new ArgumentException(string.Format("Parameter {0} does not exist in " +
                                                          "parameter layout bound to constant buffer view.", name));
            }

            // We validate format.
            if (arraySize == Pin.NotArray)
            {
                if (!PinFormatHelper.IsCompatible(format, value))
                {
                    throw new ArgumentException("Data is not compatible with format.");
                }
            }
            else
            {
                uint arSize;
                if (!PinFormatHelper.IsCompatibleArray(format, value, out arSize) ||
                    (arraySize == Pin.DynamicArray && arSize != arraySize))
                {
                    throw new ArgumentException("Data is not compatible with format.");
                }
            }

            fixed(byte *pp = lockedData)
            {
                byte *ppp = pp + offset;

                // We get float pointer.
                float *p = (float *)ppp;

                // We now set data based on type.
                if (value is Matrix4x4f)
                {
                    // Not optimal setting ...
                    Matrix4x4f m = (Matrix4x4f)value;
                    p[0] = m[0, 0];
                    p[1] = m[0, 1];
                    p[2] = m[0, 2];
                    p[3] = m[0, 3];

                    p[4] = m[1, 0];
                    p[5] = m[1, 1];
                    p[6] = m[1, 2];
                    p[7] = m[1, 3];

                    p[8]  = m[2, 0];
                    p[9]  = m[2, 1];
                    p[10] = m[2, 2];
                    p[11] = m[2, 3];

                    p[12] = m[3, 0];
                    p[13] = m[3, 1];
                    p[14] = m[3, 2];
                    p[15] = m[3, 3];
                }
                else if (value is Vector4f)
                {
                    Vector4f v = (Vector4f)value;
                    p[0] = v.X;
                    p[1] = v.Y;
                    p[2] = v.Z;
                    p[3] = v.W;
                }
                else if (value is Vector3f)
                {
                    Vector3f v = (Vector3f)value;
                    p[0] = v.X;
                    p[1] = v.Y;
                    p[2] = v.Z;
                }
                else if (value is Vector2f)
                {
                    Vector2f v = (Vector2f)value;
                    p[0] = v.X;
                    p[1] = v.Y;
                }
                else if (value is float)
                {
                    float v = (float)value;
                    p[0] = v;
                }
                else if (value is int)
                {
                    int  i  = (int)value;
                    int *ip = (int *)p;
                    ip[0] = i;
                }
                else if (value is Vector2i)
                {
                    Vector2i i  = (Vector2i)value;
                    int *    ip = (int *)p;
                    ip[0] = i.X;
                    ip[1] = i.Y;
                }
                else if (value is Vector3i)
                {
                    Vector3i i  = (Vector3i)value;
                    int *    ip = (int *)p;
                    ip[0] = i.X;
                    ip[1] = i.Y;
                    ip[2] = i.Z;
                }
                else if (value is Vector4i)
                {
                    Vector4i i  = (Vector4i)value;
                    int *    ip = (int *)p;
                    ip[0] = i.X;
                    ip[1] = i.Y;
                    ip[2] = i.Z;
                    ip[3] = i.W;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Example #41
0
 public static Vector4f ywyy(this Vector4f v)
 {
     return(new Vector4f(v.y, v.w, v.y, v.y));
 }
Example #42
0
 public static Vector4f xwzx(this Vector4f v)
 {
     return(new Vector4f(v.x, v.w, v.z, v.x));
 }
Example #43
0
 public static Vector4f xzxy(this Vector4f v)
 {
     return(new Vector4f(v.x, v.z, v.x, v.y));
 }
Example #44
0
 /// <summary>Get the closest distance between this <see cref="Box4f"/> and the <see cref="Vector4f"/>.</summary>
 public Single Distance( ref  Vector4f point)
 {
     Vector4f nearest;
         NearestPointTo(ref point, out nearest);
         return point.Distance(ref nearest);
 }
Example #45
0
 public static Vector2f wx(this Vector4f v)
 {
     return(new Vector2f(v.w, v.x));
 }
Example #46
0
 public static Vector3f wyx(this Vector4f v)
 {
     return(new Vector3f(v.w, v.y, v.x));
 }
Example #47
0
 /// <summary>Create a <see cref="Box4f"/> by providing the minimum extent and the size of each side.</summary>
 public static void Relative( ref Vector4f min ,  ref Vector4f size  , out Box4f result)
 {
     result.Min.X = min.X;
                 result.Max.X = min.X + size.X;
                                     result.Min.Y = min.Y;
                 result.Max.Y = min.Y + size.Y;
                                     result.Min.Z = min.Z;
                 result.Max.Z = min.Z + size.Z;
                                     result.Min.W = min.W;
                 result.Max.W = min.W + size.W;
                                 return;
 }
Example #48
0
 public static Vector3f zzy(this Vector4f v)
 {
     return(new Vector3f(v.z, v.z, v.y));
 }
Example #49
0
 /// <summary>Get the intersection type between this box and the point.</summary>
 public Containment Intersect( ref  Vector4f point)
 {
     // Most points should be outside, so check that first.
         if ( point.X < Min.X || point.X > Max.X || point.Y < Min.Y || point.Y > Max.Y || point.Z < Min.Z || point.Z > Max.Z || point.W < Min.W || point.W > Max.W )
             return Containment.Disjoint;
         // Now check for boundaries, which will usually be cut short on the first axis.
         if ( (point.X == Min.X || point.X == Max.X) && (point.Y == Min.Y || point.Y == Max.Y) && (point.Z == Min.Z || point.Z == Max.Z) && (point.W == Min.W || point.W == Max.W) )
             return Containment.Intersects;
         return Containment.Contains;
 }
Example #50
0
 public static Vector3f wwy(this Vector4f v)
 {
     return(new Vector3f(v.w, v.w, v.y));
 }
Example #51
0
 /// <summary>Get the nearest point between this <see cref="Box4f"/> and a <see cref="Vector4f"/>. If the <see cref="Vector4f"/> is inside this <see cref="Box4f"/>, it is returned untouched.</summary>
 public void NearestPointTo( ref  Vector4f point , out Vector4f result)
 {
     Containment containment = Intersect(ref point);
         if(containment != Containment.Disjoint)
             result = point;
         else
             point.Clamp(ref Min, ref Max, out result);
         return;
 }
Example #52
0
 public static Vector2f xy(this Vector4f v)
 {
     return(new Vector2f(v.x, v.y));
 }
Example #53
0
 /// <summary>Get a random position within the box.</summary>
 public void Random(Random rng , out Vector4f result)
 {
     result.X = (Single)(rng.NextDouble() * (Max.X - Min.X) + Min.X);
                             result.Y = (Single)(rng.NextDouble() * (Max.Y - Min.Y) + Min.Y);
                             result.Z = (Single)(rng.NextDouble() * (Max.Z - Min.Z) + Min.Z);
                             result.W = (Single)(rng.NextDouble() * (Max.W - Min.W) + Min.W);
                         return;
 }
Example #54
0
        /// <summary>
        /// Divides two quantities. The same operations as for multiplication are supported.
        /// </summary>
        /// <param name="obj1">The first object.</param>
        /// <param name="obj2">The second object.</param>
        /// <returns>Result cast into object.</returns>
        public static object Div(object obj1, object obj2)
        {
            if (obj1.GetType() != obj2.GetType())
            {
                throw new ArgumentException("Object are not of the same type.");
            }

            if (obj1 is BigNum)
            {
                return((BigNum)obj1 + (BigNum)obj2);
            }

            // Float version:
            if (obj1 is float)
            {
                return((float)obj1 / (float)obj2);
            }
            if (obj1 is Vector2f)
            {
                return(Vector2f.ComponentDivision((Vector2f)obj1, (Vector2f)obj2));
            }
            if (obj1 is Vector3f)
            {
                return(Vector3f.ComponentDivision((Vector3f)obj1, (Vector3f)obj2));
            }
            if (obj1 is Vector4f)
            {
                return(Vector4f.ComponentDivision((Vector4f)obj1, (Vector4f)obj2));
            }
            if (obj1 is Matrix.Matrix2x2f)
            {
                return((Matrix.Matrix2x2f)obj1 / (Matrix.Matrix2x2f)obj2);
            }
            if (obj1 is Matrix.Matrix3x3f)
            {
                return((Matrix.Matrix3x3f)obj1 / (Matrix.Matrix3x3f)obj2);
            }
            if (obj1 is Matrix.Matrix4x4f)
            {
                return((Matrix.Matrix4x4f)obj1 / (Matrix.Matrix4x4f)obj2);
            }
            if (obj1 is Complexf)
            {
                return((Complexf)obj1 / (Complexf)obj2);
            }
            if (obj1 is Quaternionf)
            {
                return((Quaternionf)obj1 / (Quaternionf)obj2);
            }

            // Double version:
            if (obj1 is double)
            {
                return((double)obj1 / (double)obj2);
            }
            if (obj1 is Vector2d)
            {
                return(Vector2d.ComponentDivision((Vector2d)obj1, (Vector2d)obj2));
            }
            if (obj1 is Vector3d)
            {
                return(Vector3d.ComponentDivision((Vector3d)obj1, (Vector3d)obj2));
            }
            if (obj1 is Vector4d)
            {
                return(Vector4d.ComponentDivision((Vector4d)obj1, (Vector4d)obj2));
            }
            if (obj1 is Matrix.Matrix2x2d)
            {
                return((Matrix.Matrix2x2d)obj1 / (Matrix.Matrix2x2d)obj2);
            }
            if (obj1 is Matrix.Matrix3x3d)
            {
                return((Matrix.Matrix3x3d)obj1 / (Matrix.Matrix3x3d)obj2);
            }
            if (obj1 is Matrix.Matrix4x4d)
            {
                return((Matrix.Matrix4x4d)obj1 / (Matrix.Matrix4x4d)obj2);
            }
            if (obj1 is Complexd)
            {
                return((Complexd)obj1 / (Complexd)obj2);
            }
            if (obj1 is Quaterniond)
            {
                return((Quaterniond)obj1 / (Quaterniond)obj2);
            }

            // Integer version:
            if (obj1 is int)
            {
                return((int)obj1 / (int)obj2);
            }

            // Other types.
            if (obj1 is uint)
            {
                return((uint)obj1 / (uint)obj2);
            }
            if (obj1 is short)
            {
                return((short)obj1 / (short)obj2);
            }
            if (obj1 is ushort)
            {
                return((ushort)obj1 / (ushort)obj2);
            }
            if (obj1 is byte)
            {
                return((byte)obj1 / (byte)obj2);
            }
            if (obj1 is ulong)
            {
                return((ulong)obj1 / (ulong)obj2);
            }
            if (obj1 is long)
            {
                return((long)obj1 / (long)obj2);
            }


            throw new NotSupportedException("Unsupported type " + obj1.GetType());
        }
Example #55
0
 public static Vector4f xzyx(this Vector4f v)
 {
     return(new Vector4f(v.x, v.z, v.y, v.x));
 }
Example #56
0
        public override object Load(LoadedAsset asset)
        {
            if (!File.Exists(asset.FilePath))
            {
                return(materials);
            }

            StreamReader reader = new StreamReader(asset.Data);
            string       line;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(' ');
                tokens = RemoveEmptyStrings(tokens);
                if (tokens.Length == 0 || tokens[0] == "#")
                {
                }
                else if (tokens[0] == "newmtl")
                {
                    string name = tokens[1];
                    materials.Add(new Material());

                    materials[materials.Count - 1].SetName(name);
                }
                else if (tokens[0] == "Ka") // ambient color
                {
                    string x_str = tokens[1];
                    string y_str = tokens[2];
                    string z_str = tokens[3];
                    float  x, y, z;
                    x = float.Parse(x_str);
                    y = float.Parse(y_str);
                    z = float.Parse(z_str);
                    Vector4f color = new Vector4f(x, y, z, 1.0f);
                    // materials[materials.Count - 1].SetValue(Material.COLOR_AMBIENT, color);
                }
                else if (tokens[0] == "Kd") // ambient color
                {
                    string x_str = tokens[1];
                    string y_str = tokens[2];
                    string z_str = tokens[3];
                    float  x, y, z;
                    x = float.Parse(x_str);
                    y = float.Parse(y_str);
                    z = float.Parse(z_str);
                    Vector4f color = new Vector4f(x, y, z, 1.0f);
                    materials[materials.Count - 1].SetValue(Material.COLOR_DIFFUSE, color);
                }
                else if (tokens[0] == "Ks") // ambient color
                {
                    string x_str = tokens[1];
                    string y_str = tokens[2];
                    string z_str = tokens[3];
                    float  x, y, z;
                    x = float.Parse(x_str);
                    y = float.Parse(y_str);
                    z = float.Parse(z_str);
                    Vector4f color = new Vector4f(x, y, z, 1.0f);
                    materials[materials.Count - 1].SetValue(Material.COLOR_SPECULAR, color);
                }
                else if (tokens[0] == "Ns") // ambient color
                {
                    string spec   = tokens[1];
                    float  spec_f = float.Parse(spec);
                    materials[materials.Count - 1].SetValue(Material.SHININESS, spec_f / 1000.0f);
                }
                else if (tokens[0].ToLower() == "map_kd") // diffuse map
                {
                    string texName    = tokens[tokens.Length - 1];
                    string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString();
                    string texPath    = parentPath + "\\" + texName;
                    if (File.Exists(texPath))
                    {
                        Texture tex = AssetManager.LoadTexture(texPath);
                        materials[materials.Count - 1].SetValue(Material.TEXTURE_DIFFUSE, tex);
                    }
                    else if (File.Exists(texName))
                    {
                        Texture tex = AssetManager.LoadTexture(texName);
                        materials[materials.Count - 1].SetValue(Material.TEXTURE_DIFFUSE, tex);
                    }
                }
                else if (tokens[0].ToLower() == "map_bump") // normal map
                {
                    string texName    = tokens[tokens.Length - 1];
                    string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString();
                    string texPath    = parentPath + "\\" + texName;
                    if (File.Exists(texPath))
                    {
                        Texture tex = AssetManager.LoadTexture(texPath);
                        materials[materials.Count - 1].SetValue(Material.TEXTURE_NORMAL, tex);
                    }
                    else if (File.Exists(texName))
                    {
                        Texture tex = AssetManager.LoadTexture(texName);
                        materials[materials.Count - 1].SetValue(Material.TEXTURE_NORMAL, tex);
                    }
                }
            }
            reader.Close();
            return(materials);
        }
Example #57
0
 public static Vector4f wwww(this Vector4f v)
 {
     return(new Vector4f(v.w, v.w, v.w, v.w));
 }
Example #58
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Colour"/> class.
 /// </summary>
 /// <param name="v">The vector.</param>
 public Colour(Vector4f v)
 {
     c = v;
 }
Example #59
0
 /// <summary>
 /// Returns the *signed* shortest distance between p and the plane.
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public float Distance( Vector4f p )
 {
     // pick a point x on the plane
     // get the vector x --> p
     // distance is the projection on the unit normal
     // xp dot unitNormal
     var x = PointOnPlane();
     var xp = p - x;
     return Vector4f.Dot( xp, UnitNormal );
 }
Example #60
0
 public static Vector3f yyy(this Vector4f v)
 {
     return(new Vector3f(v.y, v.y, v.y));
 }