static int test_0_vector4i_one_element_ctor () { Vector4i a = new Vector4i (99); if (a.X != 99) return 1; if (a.Y != 99) return 2; if (a.Z != 99) return 3; if (a.W != 99) return 4; return 0; }
static int test_0_vector4i_cmp_gt () { Vector4i a = new Vector4i (10, 5, 12, -1); Vector4i b = new Vector4i (-1, 5, 10, 10); Vector4i c = a.CompareGreaterThan (b); if (c.X != -1) return 1; if (c.Y != 0) return 2; if (c.Z != -1) return 3; if (c.W != 0) return 4; return 0; }
public DynamicTexture(Context context, Format format, Vector4i size) { if (context == null) throw new ArgumentNullException("context"); if (format == null) throw new ArgumentNullException("format"); this.format = format; this.frameBuffer = new FrameBuffer(); this.mainProgram = new Program(); this.dimensions = size; var builder = ShaderBuilder.CreateFromAssemblyResource("Glare.Graphics.Shaders.DynamicTexture.glsl"); mainProgram.Shaders.AddRange( builder.VertexShader("Common", "Vertex"), builder.FragmentShader("Common", "Fragment")); mainProgram.MustLink(); mainProgramAction = mainProgram.FragmentStage.Uniforms["Act"]; mainProgram.Attributes["Position"].BindArray(new Vector2f[] { new Vector2f(-1, 1), new Vector2f(-1, -1), new Vector2f(1, 1), new Vector2f(1, -1) }); }
public static int test_0_accessor_vecto4i () { Vector4i a = new Vector4i (0x70000000, -1, 3, 4); if (a.X != 0x70000000) return 1; if (a.Y != -1) return 2; if (a.Z != 3) return 3; if (a.W != 4) return 4; a.X = 11; a.Y = 22; a.Z = 33333344; a.W = -44444444; if (a.X != 11) return 5; if (a.Y != 22) return 6; if (a.Z != 33333344) return 7; if (a.W != -44444444) return 8; return 0; }
public Vector4i Div(Vector4i factor) { return new Vector4i(x / factor.x, y / factor.y, z / factor.z, w / factor.w); }
/// <summary>Get the nearest point between this <see cref="Box4i"/> and a <see cref="Vector4i"/>. If the <see cref="Vector4i"/> is inside this <see cref="Box4i"/>, it is returned untouched.</summary> public Vector4i NearestPointTo( Vector4i point ) { Vector4i result; Containment containment = Intersect(ref point); if(containment != Containment.Disjoint) result = point; else point.Clamp(ref Min, ref Max, out result); return result; }
public override void Storage(int levels, Format format, Vector4i dimensions) { throw new NotImplementedException(); }
public void BlendPixel(byte[] pDestBuffer, int bufferOffset, RGBA_Bytes sourceColor) { //unsafe { int oneOverAlpha = base_mask - sourceColor.alpha; unchecked { #if false Vector4i sourceColors = new Vector4i(sourceColor.m_B, sourceColor.m_G, sourceColor.m_R, sourceColor.m_A); Vector4i destColors = new Vector4i( pDestBuffer[bufferOffset + ImageBuffer.OrderB], pDestBuffer[bufferOffset + ImageBuffer.OrderG], pDestBuffer[bufferOffset + ImageBuffer.OrderB], pDestBuffer[bufferOffset + ImageBuffer.OrderA]); Vector4i oneOverAlphaV = new Vector4i(oneOverAlpha, oneOverAlpha, oneOverAlpha, oneOverAlpha); Vector4i rounding = new Vector4i(255, 255, 255, 255); Vector4i temp = destColors * oneOverAlphaV + rounding; temp = temp >> 8; temp = temp + sourceColors; Vector8us packed8Final = Vector4i.PackWithUnsignedSaturation(temp, temp); Vector16b packed16Final = Vector8us.SignedPackWithUnsignedSaturation(packed8Final, packed8Final); pDestBuffer[bufferOffset + ImageBuffer.OrderR] = packed16Final.V2; pDestBuffer[bufferOffset + ImageBuffer.OrderG] = packed16Final.V1; pDestBuffer[bufferOffset + ImageBuffer.OrderB] = packed16Final.V0; pDestBuffer[bufferOffset + ImageBuffer.OrderA] = 255; #else int r = m_Saturate9BitToByte[((pDestBuffer[bufferOffset + ImageBuffer.OrderR] * oneOverAlpha + 255) >> 8) + sourceColor.red]; int g = m_Saturate9BitToByte[((pDestBuffer[bufferOffset + ImageBuffer.OrderG] * oneOverAlpha + 255) >> 8) + sourceColor.green]; int b = m_Saturate9BitToByte[((pDestBuffer[bufferOffset + ImageBuffer.OrderB] * oneOverAlpha + 255) >> 8) + sourceColor.blue]; int a = pDestBuffer[bufferOffset + ImageBuffer.OrderA]; pDestBuffer[bufferOffset + ImageBuffer.OrderR] = (byte)r; pDestBuffer[bufferOffset + ImageBuffer.OrderG] = (byte)g; pDestBuffer[bufferOffset + ImageBuffer.OrderB] = (byte)b; pDestBuffer[bufferOffset + ImageBuffer.OrderA] = (byte)(base_mask - m_Saturate9BitToByte[(oneOverAlpha * (base_mask - a) + 255) >> 8]); #endif } } }
/// <summary>Create a <see cref="Box4i"/> by providing the minimum extent and the size of each side.</summary> public static Box4i Relative( ref Vector4i min , ref Vector4i size ) { Box4i 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 result; }
public static Vector4f LerpClamped(Vector4i a, Vector4i b, float alpha) { return(a + (Math.Clamp01(alpha) * (b - a))); }
static unsafe void FromUInt32(int first, int count, IList<Vector4i> data) { for(int index = 0; index < count; index++)data[first + index] = new Vector4i((int)( *((System.UInt32*)list.ToPointer() + (index + 0) * 4 * 4) ), (int)( *((System.UInt32*)list.ToPointer() + (index + 1) * 4 * 4) ), (int)( *((System.UInt32*)list.ToPointer() + (index + 2) * 4 * 4) ), (int)( *((System.UInt32*)list.ToPointer() + (index + 3) * 4 * 4) )); }
public static Vector4f Mix(Vector4i a, Vector4i b, float alpha) { return(Lerp(a, b, alpha)); }
public static Vector4f Lerp(Vector4i a, Vector4i b, float alpha) { return(a + (alpha * (b - a))); }
public static float Dot(Vector4i a, Vector4i b) { return((a.x * b.x + a.y * b.y) + (a.z * b.z + a.w * b.w)); }
public static float DistanceSqr(Vector4i a, Vector4i b) { return((a - b).lengthSqr); }
internal Texture(Format format, Vector4i dimensions) : this() { Storage(format, dimensions); }
public void Storage(Format format, Vector4i dimensions) { Storage(CalculateLevels(dimensions), format, dimensions); }
public static Vector4f Reflect(Vector4i incident, Vector4i normal) { return(incident - 2 * Dot(normal, incident) * normal); }
public void Set(ref Vector4i value) { unsafe { fixed(Vector4i* pointer = &value) Set4(1, (int*)pointer); } }
/// <summary> /// Constructs a new Vector2f from the given Vector4i. /// </summary> /// <param name="v">The Vector4i to copy components from.</param> public Vector2i(Vector4i vec) { X = vec.X; Y = vec.Y; }
/// <summary>Read a <see cref="Vector4i"/>.</summary> public static void ReadVector4i(this BinaryReader reader , out Vector4i result) { result.X = reader.ReadInt32(); result.Y = reader.ReadInt32(); result.Z = reader.ReadInt32(); result.W = reader.ReadInt32(); return; }
/// <summary> /// Loads the specified x. /// </summary> /// <remarks>Loading x may fail in CPU (if no read access) or may be very slow. /// If GPU Assembling is used, this method is replaced with GPU eqiuvaled.</remarks> /// <param name="x">The x.</param> /// <returns></returns> public abstract Vector4f Load(Vector4i x);
/// <summary> /// Inclusive on left, exclusive on right. /// </summary> /// <param name="p"></param> /// <returns></returns> public bool ContainsPoint( Vector4i p ) { return ( origin.x <= p.x && origin.y <= p.y && origin.z <= p.z && origin.w <= p.w && p.x < origin.x + delta.x && p.y < origin.y + delta.y && p.z < origin.z + delta.z && p.z < origin.w + delta.w ); }
/// <summary> /// Multiplies two objects. Scalar scalar, scalar vector, scalar matrix, vector vector (component), /// vector matrix, matrix vector matrix matrix multiplications 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 Mul(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.ComponentMultiply((Vector2f)obj1, (Vector2f)obj2)); } if (obj1 is Vector3f) { return(Vector3f.ComponentMultiply((Vector3f)obj1, (Vector3f)obj2)); } if (obj1 is Vector4f) { return(Vector4f.ComponentMultiply((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.ComponentMultiply((Vector2d)obj1, (Vector2d)obj2)); } if (obj1 is Vector3d) { return(Vector3d.ComponentMultiply((Vector3d)obj1, (Vector3d)obj2)); } if (obj1 is Vector4d) { return(Vector4d.ComponentMultiply((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); } if (obj1 is Vector2i) { return(Vector2i.ComponentMultiply((Vector2i)obj1, (Vector2i)obj2)); } if (obj1 is Vector3i) { return(Vector3i.ComponentMultiply((Vector3i)obj1, (Vector3i)obj2)); } if (obj1 is Vector4i) { return(Vector4i.ComponentMultiply((Vector4i)obj1, (Vector4i)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()); }
/// <summary>Get the closest distance between this <see cref="Box4i"/> and the <see cref="Vector4i"/>.</summary> public double Distance( ref Vector4i point) { Vector4i nearest; NearestPointTo(ref point, out nearest); return point.Distance(ref nearest); }
public int AlignedByteSize(Vector4i size) { return(AlignedByteSize(size.X, size.Y, size.Z, size.W)); }
/// <summary>Get whether this <see cref="Box4i"/> inclusively intersects with the <see cref="Vector4i"/>.</summary> public bool Overlaps( ref Vector4i 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 ; }
public int ByteSize(Vector4i size) { return(ByteSize(size.X, size.Y, size.Z, size.W)); }
public static int test_0_i_to_f () { var a = new Vector4i (1, 2, 3, 4); var b = a.ConvertToFloat (); if (b.X != 1) return 1; if (b.Y != 2) return 2; if (b.Z != 3) return 3; if (b.W != 4) return 4; return 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(); } } }
internal LayeredTexture(Format format, Vector4i dimensions) : base(format, dimensions) { }
public static Vector4i Vector4i(Vector4i min, Vector4i max, System.Random random = null) { return(min + new Vector4i(Int(max.x - min.x, random), Int(max.y - min.y, random), Int(max.z - min.z, random), Int(max.w - min.w, random))); }
public Vector4i Mul(Vector4i factor) { return new Vector4i(x * factor.x, y * factor.y, z * factor.z, w * factor.w); }
public static Vector4i zwwy(this Vector4i v) { return(new Vector4i(v.z, v.w, v.w, v.y)); }
public void Set(Vector4i value) { unsafe { Set4(1, (int*)&value); } }
public static Vector4i xxxz(this Vector4i v) { return(new Vector4i(v.x, v.x, v.x, v.z)); }
static unsafe void FromBoolean(int first, int count, IList<Vector4i> data) { for(int index = 0; index < count; index++)data[first + index] = new Vector4i((int)( Marshal.ReadInt32(list, (index + 0) * 4 * 4 * 4) != 0 ? 1 : 0 ), (int)( Marshal.ReadInt32(list, (index + 1) * 4 * 4 * 4) != 0 ? 1 : 0 ), (int)( Marshal.ReadInt32(list, (index + 2) * 4 * 4 * 4) != 0 ? 1 : 0 ), (int)( Marshal.ReadInt32(list, (index + 3) * 4 * 4 * 4) != 0 ? 1 : 0 )); }
public static Vector3i zyx(this Vector4i v) { return(new Vector3i(v.z, v.y, v.x)); }
public void SetGrabStats(Vector4i qualityStats) { int total = Mathf.Max (qualityStats.x + qualityStats.y + qualityStats.z, 1); perfectCount.SetText("{0}% Perfect", (qualityStats.z / (float)total) * 100); greatCount.SetText("{0}% Great", (qualityStats.y / (float)total) * 100); okCount.SetText("{0}% OK", (qualityStats.x / (float)total) * 100); }
public static Vector4i zwyz(this Vector4i v) { return(new Vector4i(v.z, v.w, v.y, v.z)); }
/// <summary>Read an array of <c>Vector4i</c> values.</summary> public static Vector4i[] ReadArrayVector4i(this BinaryReader reader, int count) { Vector4i[] array = new Vector4i[count]; reader.ReadArray(array, 0, count); return array; }
public static Vector4i yxzz(this Vector4i v) { return(new Vector4i(v.y, v.x, v.z, v.z)); }
public Box4i( Vector4i origin, Vector4i delta ) { this.origin = origin; this.delta = delta; }
public static Vector4i zzzz(this Vector4i v) { return(new Vector4i(v.z, v.z, v.z, v.z)); }
/// <summary>Create a <see cref="Box4i"/> by providing minimum and maximum extents.</summary> public Box4i( ref Vector4i min, ref Vector4i max) { this.Min = min; this.Max = max; }
public static Vector4i xywz(this Vector4i v) { return(new Vector4i(v.x, v.y, v.w, v.z)); }
/// <summary>Create a <see cref="Box4i"/> by providing the minimum extent and the size of each side.</summary> public static void Relative( ref Vector4i min , ref Vector4i size , out Box4i 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; }
public static Vector4i wwwz(this Vector4i v) { return(new Vector4i(v.w, v.w, v.w, v.z)); }
/// <summary>Get the intersection type between this box and the point.</summary> public Containment Intersect( ref Vector4i 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; }
public static Vector4i wxxw(this Vector4i v) { return(new Vector4i(v.w, v.x, v.x, v.w)); }
/// <summary>Get the nearest point between this <see cref="Box4i"/> and a <see cref="Vector4i"/>. If the <see cref="Vector4i"/> is inside this <see cref="Box4i"/>, it is returned untouched.</summary> public void NearestPointTo( ref Vector4i point , out Vector4i result) { Containment containment = Intersect(ref point); if(containment != Containment.Disjoint) result = point; else point.Clamp(ref Min, ref Max, out result); return; }
public static Vector3i wzx(this Vector4i v) { return(new Vector3i(v.w, v.z, v.x)); }
/// <summary>Get a random position within the box.</summary> public void Random(Random rng , out Vector4i result) { result.X = (Int32)(rng.NextDouble() * (Max.X - Min.X) + Min.X); result.Y = (Int32)(rng.NextDouble() * (Max.Y - Min.Y) + Min.Y); result.Z = (Int32)(rng.NextDouble() * (Max.Z - Min.Z) + Min.Z); result.W = (Int32)(rng.NextDouble() * (Max.W - Min.W) + Min.W); return; }
public static Vector4i zyxw(this Vector4i v) { return(new Vector4i(v.z, v.y, v.x, v.w)); }
public static int test_0_i_to_d () { var a = new Vector4i (1, 2, 3, 4); var b = a.ConvertToDouble (); if (b.X != 1) return 1; if (b.Y != 2) return 2; return 0; }
/// <summary>Set the dimensions of the entire texture, assigning level-of-detail chains appropriately. Unused dimensions need to be 1.</summary> /// <param name="dimensions">The dimensions of the <see cref="Texture"/>.</param> /// <param name="format"></param> public abstract void Storage(int levels, Format format, Vector4i dimensions);
static void InitByRef (out Vector4i v) { v = new Vector4i (99); if (ddd > 10) throw new Exception ("ddd"); }
public static Vector4i Min(Vector4i a, Vector4i b) { return new Vector4i(Mathf.Min(a.x, b.x), Mathf.Min(a.y, b.y), Mathf.Min(a.z, b.z), Mathf.Min (a.w, b.w)); }
public static Vector4f Reflect(Vector4i incident, Vector4i normal) { return(Vector4i.Reflect(incident, normal)); }
internal FlatTexture(Format format, Vector4i dimensions) : base(format, dimensions) { }