Struct float4
Represents a 4D vector using four single-precision floating-point numbers.
Implements
Inherited Members
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public struct float4 : IEquatable<float4>
Remarks
The float4 structure is suitable for interoperation with unmanaged code requiring four consecutive floats.
Constructors
float4(double4)
Constructs a new float4 by converting from a double4.
Declaration
public float4(double4 d4)
Parameters
Type | Name | Description |
---|---|---|
double4 | d4 | The double4 to copy components from. |
float4(float2)
Constructs a new float4 from the given float2.
Declaration
public float4(float2 v)
Parameters
Type | Name | Description |
---|---|---|
float2 | v | The float2 to copy components from. |
float4(float3)
Constructs a new float4 from the given float3.
Declaration
public float4(float3 v)
Parameters
Type | Name | Description |
---|---|---|
float3 | v | The float3 to copy components from. |
float4(float3, Single)
Constructs a new float4 from the specified float3 and ww component.
Declaration
public float4(float3 v, float ww)
Parameters
Type | Name | Description |
---|---|---|
float3 | v | The float3 to copy components from. |
System.Single | ww | The ww component of the new float4. |
float4(float4)
Constructs a new float4 from the given float4.
Declaration
public float4(float4 v)
Parameters
Type | Name | Description |
---|---|---|
float4 | v | The float4 to copy components from. |
float4(Single)
Constructs a new float4.
Declaration
public float4(float val)
Parameters
Type | Name | Description |
---|---|---|
System.Single | val | This value will be set for the x, y, z and w component. |
float4(Single, Single, Single, Single)
Constructs a new float4.
Declaration
public float4(float x, float y, float z, float w)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The x component of the float4. |
System.Single | y | The y component of the float4. |
System.Single | z | The z component of the float4. |
System.Single | w | The w component of the float4. |
Fields
One
Defines an instance with all components set to 1.
Declaration
public static readonly float4 One
Field Value
Type | Description |
---|---|
float4 |
UnitW
Defines a unit-length float4 that points towards the w-axis.
Declaration
public static readonly float4 UnitW
Field Value
Type | Description |
---|---|
float4 |
UnitX
Defines a unit-length float4 that points towards the x-axis.
Declaration
public static readonly float4 UnitX
Field Value
Type | Description |
---|---|
float4 |
UnitY
Defines a unit-length float4 that points towards the y-axis.
Declaration
public static readonly float4 UnitY
Field Value
Type | Description |
---|---|
float4 |
UnitZ
Defines a unit-length float4 that points towards the z-axis.
Declaration
public static readonly float4 UnitZ
Field Value
Type | Description |
---|---|
float4 |
w
The w component of the float4.
Declaration
public float w
Field Value
Type | Description |
---|---|
System.Single |
x
The x component of the float4.
Declaration
public float x
Field Value
Type | Description |
---|---|
System.Single |
y
The y component of the float4.
Declaration
public float y
Field Value
Type | Description |
---|---|
System.Single |
z
The z component of the float4.
Declaration
public float z
Field Value
Type | Description |
---|---|
System.Single |
Zero
Defines a zero-length float4.
Declaration
public static readonly float4 Zero
Field Value
Type | Description |
---|---|
float4 |
Properties
a
The alpha component (same as w)
Declaration
public float a { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
b
The blue component (same as z)
Declaration
public float b { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
g
The green component (same as y)
Declaration
public float g { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
Item[Int32]
Gets or sets the individual components x, y, z, or w, depending on their index.
Declaration
public float this[int idx] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | idx | The index (between 0 and 3). |
Property Value
Type | Description |
---|---|
System.Single | The x or y component of the float4. |
Length
Gets the length (magnitude) of the vector.
Declaration
public readonly float Length { get; }
Property Value
Type | Description |
---|---|
System.Single |
Length1
Gets the length in 1-norm.
Declaration
public readonly float Length1 { get; }
Property Value
Type | Description |
---|---|
System.Single |
LengthSquared
Gets the square of the vector length (magnitude).
Declaration
public readonly float LengthSquared { get; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
This property avoids the costly square root operation required by the Length property. This makes it more suitable for comparisons.
ParseConverter
Gets and sets the Converter object. Has the ability to convert a string to a float4.
Declaration
public static Converter<string, float4> ParseConverter { get; set; }
Property Value
Type | Description |
---|---|
Converter<System.String, float4> | The parse property. |
r
The red component (same as x)
Declaration
public float r { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
rg
The rg component (same as xy)
Declaration
public float2 rg { get; set; }
Property Value
Type | Description |
---|---|
float2 |
rgb
The rgb component (same as xyz)
Declaration
public float3 rgb { get; set; }
Property Value
Type | Description |
---|---|
float3 |
xy
Gets and sets an OpenTK.float2 with the x and y components of this instance.
Declaration
public float2 xy { get; set; }
Property Value
Type | Description |
---|---|
float2 |
xyz
Gets and sets an OpenTK.float3 with the x, y and z components of this instance.
Declaration
public float3 xyz { get; set; }
Property Value
Type | Description |
---|---|
float3 |
Methods
Add(float4, float4)
Adds two vectors.
Declaration
public static float4 Add(float4 a, float4 b)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | Left operand. |
float4 | b | Right operand. |
Returns
Type | Description |
---|---|
float4 | Result of operation. |
BaryCentric(float4, float4, float4, Single, Single)
Interpolate 3 Vectors using Barycentric coordinates
Declaration
public static float4 BaryCentric(float4 a, float4 b, float4 c, float u, float v)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | First input Vector |
float4 | b | Second input Vector |
float4 | c | Third input Vector |
System.Single | u | First Barycentric Coordinate |
System.Single | v | Second Barycentric Coordinate |
Returns
Type | Description |
---|---|
float4 | a when u=1, v=0, b when v=1,u=0, c when u=v=0, and a linear combination of a,b,c otherwise |
Clamp(float4, float4, float4)
Clamp a vector to the given minimum and maximum vectors
Declaration
public static float4 Clamp(float4 vec, float4 min, float4 max)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | Input vector |
float4 | min | Minimum vector |
float4 | max | Maximum vector |
Returns
Type | Description |
---|---|
float4 | The clamped vector |
Divide(float4, float4)
Divides a vector by the components of a vector (scale).
Declaration
public static float4 Divide(float4 vector, float4 scale)
Parameters
Type | Name | Description |
---|---|---|
float4 | vector | Left operand. |
float4 | scale | Right operand. |
Returns
Type | Description |
---|---|
float4 | Result of the operation. |
Divide(float4, Single)
Divides a vector by a scalar.
Declaration
public static float4 Divide(float4 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
float4 | vector | Left operand. |
System.Single | scale | Right operand. |
Returns
Type | Description |
---|---|
float4 | Result of the operation. |
Dot(float4, float4)
Calculate the dot product of two vectors
Declaration
public static float Dot(float4 left, float4 right)
Parameters
Type | Name | Description |
---|---|---|
float4 | left | First operand |
float4 | right | Second operand |
Returns
Type | Description |
---|---|
System.Single | The dot product of the two inputs |
Equals(float4)
Indicates whether the current vector is equal to another vector.
Declaration
public bool Equals(float4 other)
Parameters
Type | Name | Description |
---|---|---|
float4 | other | A vector to compare with this vector. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current vector is equal to the vector parameter; otherwise, false. |
Equals(Object)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to compare to. |
Returns
Type | Description |
---|---|
System.Boolean | True if the instances are equal; false otherwise. |
Overrides
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 containing the unique hashcode for this instance. |
Overrides
Lerp(float4, float4, float4)
Returns a new Vector that is the linear blend of the 2 given Vectors. Each component of vector a is blended with its equivalent in vector b.
Declaration
public static float4 Lerp(float4 a, float4 b, float4 blend)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | First input vector |
float4 | b | Second input vector |
float4 | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
float4 |
Lerp(float4, float4, Single)
Returns a new Vector that is the linear blend of the 2 given Vectors
Declaration
public static float4 Lerp(float4 a, float4 b, float blend)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | First input vector |
float4 | b | Second input vector |
System.Single | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
float4 | a when blend=0, b when blend=1, and a linear combination otherwise |
LinearColorFromSRgb()
Converts this float4 - which is interpreted as a color - from sRgb space to linear color space.
Declaration
public float4 LinearColorFromSRgb()
Returns
Type | Description |
---|---|
float4 |
LinearColorFromSRgb(float4)
Converts a color value from sRgb to linear space.
Declaration
public static float4 LinearColorFromSRgb(float4 sRGBCol)
Parameters
Type | Name | Description |
---|---|---|
float4 | sRGBCol | The sRgb color value as float4. |
Returns
Type | Description |
---|---|
float4 |
LinearColorFromSRgb(Int32, Int32, Int32, Int32)
Converts a color value from sRgb to linear space.
Declaration
public static float4 LinearColorFromSRgb(int r, int g, int b, int a)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | r | The red color value in range 0 - 255. |
System.Int32 | g | The green color value in range 0 - 255. |
System.Int32 | b | The blue color value in range 0 - 255. |
System.Int32 | a | The alpha value in range 0 - 255. |
Returns
Type | Description |
---|---|
float4 |
LinearColorFromSRgb(String)
Converts a color value from sRgb to linear space.
Declaration
public static float4 LinearColorFromSRgb(string hex)
Parameters
Type | Name | Description |
---|---|---|
System.String | hex | The color value as hex code in form of a "FFFFFFFF" string. |
Returns
Type | Description |
---|---|
float4 |
LinearColorFromSRgb(UInt32)
Converts a color value from sRgb to linear space.
Declaration
public static float4 LinearColorFromSRgb(uint col)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | col | The color value as uint. |
Returns
Type | Description |
---|---|
float4 |
Max(float4, float4)
Calculate the component-wise maximum of two vectors
Declaration
public static float4 Max(float4 a, float4 b)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | First operand |
float4 | b | Second operand |
Returns
Type | Description |
---|---|
float4 | The component-wise maximum |
Min(float4, float4)
Calculate the component-wise minimum of two vectors
Declaration
public static float4 Min(float4 a, float4 b)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | First operand |
float4 | b | Second operand |
Returns
Type | Description |
---|---|
float4 | The component-wise minimum |
Multiply(float4, float4)
Multiplies a vector by the components a vector (scale).
Declaration
public static float4 Multiply(float4 vector, float4 scale)
Parameters
Type | Name | Description |
---|---|---|
float4 | vector | Left operand. |
float4 | scale | Right operand. |
Returns
Type | Description |
---|---|
float4 | Result of the operation. |
Multiply(float4, Single)
Multiplies a vector by a scalar.
Declaration
public static float4 Multiply(float4 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
float4 | vector | Left operand. |
System.Single | scale | Right operand. |
Returns
Type | Description |
---|---|
float4 | Result of the operation. |
Normalize()
Scales the float4 to unit length.
Declaration
public float4 Normalize()
Returns
Type | Description |
---|---|
float4 |
Normalize(float4)
Scale a vector to unit length
Declaration
public static float4 Normalize(float4 vec)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The input vector |
Returns
Type | Description |
---|---|
float4 | The normalized vector |
Normalize1()
Scales the float4 to unit length in 1-norm.
Declaration
public float4 Normalize1()
Returns
Type | Description |
---|---|
float4 |
Normalize1(float4)
Scales the vector to unit length in 1-norm.
Declaration
public static float4 Normalize1(float4 vec)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The input vector. |
Returns
Type | Description |
---|---|
float4 | The scaled vector. |
NormalizeFast()
Scales the float4 to approximately unit length.
Declaration
public float4 NormalizeFast()
Returns
Type | Description |
---|---|
float4 |
NormalizeFast(float4)
Scale a vector to approximately unit length
Declaration
public static float4 NormalizeFast(float4 vec)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The input vector |
Returns
Type | Description |
---|---|
float4 | The normalized vector |
Parse(String, IFormatProvider)
Parses a string into a float4.
Declaration
public static float4 Parse(string source, IFormatProvider provider = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | |
System.IFormatProvider | provider |
Returns
Type | Description |
---|---|
float4 |
Pow(float4, Single)
Returns a float4 where all components are raised to the specified power.
Declaration
public static float4 Pow(float4 val, float exp)
Parameters
Type | Name | Description |
---|---|---|
float4 | val | The float4 to be raised to a power. |
System.Single | exp | A float that specifies a power. |
Returns
Type | Description |
---|---|
float4 |
Round()
Rounds the float4 to 6 digits (max float precision).
Declaration
public float4 Round()
Returns
Type | Description |
---|---|
float4 |
Round(float4)
Rounds a vector to 6 digits (max float precision).
Declaration
public static float4 Round(float4 vec)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The input vector. |
Returns
Type | Description |
---|---|
float4 | The rounded vector. |
SRgbFromLinearColor()
Converts this float4 - which is interpreted as a color - from linear color space to sRgb space.
Declaration
public float4 SRgbFromLinearColor()
Returns
Type | Description |
---|---|
float4 |
SRgbFromLinearColor(float4)
Converts a color value from linear to sRgb space.
Declaration
public static float4 SRgbFromLinearColor(float4 sRGBCol)
Parameters
Type | Name | Description |
---|---|---|
float4 | sRGBCol | The linear color value as float4. |
Returns
Type | Description |
---|---|
float4 |
SRgbFromLinearColor(Int32, Int32, Int32, Int32)
Converts a color value from linear to sRgb space.
Declaration
public static float4 SRgbFromLinearColor(int r, int g, int b, int a)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | r | The red color value in range 0 - 255. |
System.Int32 | g | The green color value in range 0 - 255. |
System.Int32 | b | The blue color value in range 0 - 255. |
System.Int32 | a | The alpha value in range 0 - 255. |
Returns
Type | Description |
---|---|
float4 |
SRgbFromLinearColor(String)
Converts a color value from linear to sRgb space.
Declaration
public static float4 SRgbFromLinearColor(string hex)
Parameters
Type | Name | Description |
---|---|---|
System.String | hex | The color value as hex code in form of a "FFFFFFFF" string. |
Returns
Type | Description |
---|---|
float4 |
SRgbFromLinearColor(UInt32)
Converts a color value from linear to sRgb space.
Declaration
public static float4 SRgbFromLinearColor(uint col)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | col | The color value as uint. |
Returns
Type | Description |
---|---|
float4 |
Step(float4, float4)
Performs Step(Single, Single) for each component of the input vectors.
Declaration
public static float4 Step(float4 edge, float4 val)
Parameters
Type | Name | Description |
---|---|---|
float4 | edge | Specifies the location of the edge of the step function. |
float4 | val | Specifies the value to be used to generate the step function. |
Returns
Type | Description |
---|---|
float4 |
Subtract(float4, float4)
Subtract one Vector from another
Declaration
public static float4 Subtract(float4 a, float4 b)
Parameters
Type | Name | Description |
---|---|---|
float4 | a | First operand |
float4 | b | Second operand |
Returns
Type | Description |
---|---|
float4 | Result of subtraction |
ToArray()
XML-Comment
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
System.Single[] | An float array of size 4 that cobtains the x,y,z,w components. |
ToString()
Returns a System.String that represents the current float4.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Overrides
ToString(IFormatProvider)
Returns a System.String that represents the current float4.
Declaration
public string ToString(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider | Provides information about a specific culture. |
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Operators
Addition(float4, float4)
Adds two instances.
Declaration
public static float4 operator +(float4 left, float4 right)
Parameters
Type | Name | Description |
---|---|---|
float4 | left | The first instance. |
float4 | right | The second instance. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |
Division(float4, Single)
Divides an instance by a scalar.
Declaration
public static float4 operator /(float4 vec, float scale)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The instance. |
System.Single | scale | The scalar. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |
Equality(float4, float4)
Compares two instances for equality.
Declaration
public static bool operator ==(float4 left, float4 right)
Parameters
Type | Name | Description |
---|---|---|
float4 | left | The first instance. |
float4 | right | The second instance. |
Returns
Type | Description |
---|---|
System.Boolean | True, if left equals right; false otherwise. |
Explicit(double4 to float4)
Explicit cast operator to cast a double4 into a float4 value.
Declaration
public static explicit operator float4(double4 d4)
Parameters
Type | Name | Description |
---|---|---|
double4 | d4 | The double4 value to cast. |
Returns
Type | Description |
---|---|
float4 | A float4 value. |
Inequality(float4, float4)
Compares two instances for inequality.
Declaration
public static bool operator !=(float4 left, float4 right)
Parameters
Type | Name | Description |
---|---|---|
float4 | left | The first instance. |
float4 | right | The second instance. |
Returns
Type | Description |
---|---|
System.Boolean | True, if left does not equal right; false otherwise. |
Multiply(float4, float4)
Multiplies two instances (componentwise).
Declaration
public static float4 operator *(float4 left, float4 right)
Parameters
Type | Name | Description |
---|---|---|
float4 | left | The first instance. |
float4 | right | The second instance. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |
Multiply(float4, Single)
Multiplies an instance by a scalar.
Declaration
public static float4 operator *(float4 vec, float scale)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The instance. |
System.Single | scale | The scalar. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |
Multiply(Single, float4)
Multiplies an instance by a scalar.
Declaration
public static float4 operator *(float scale, float4 vec)
Parameters
Type | Name | Description |
---|---|---|
System.Single | scale | The scalar. |
float4 | vec | The instance. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |
Subtraction(float4, float4)
Subtracts two instances.
Declaration
public static float4 operator -(float4 left, float4 right)
Parameters
Type | Name | Description |
---|---|---|
float4 | left | The first instance. |
float4 | right | The second instance. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |
UnaryNegation(float4)
Negates an instance.
Declaration
public static float4 operator -(float4 vec)
Parameters
Type | Name | Description |
---|---|---|
float4 | vec | The instance. |
Returns
Type | Description |
---|---|
float4 | The result of the calculation. |