classVector3

Constructors

note_add Vector3( x, y, z )note_add Vector3( x, y )note_add Vector3( other )note_add Vector3( other, z )note_add Vector3( all )

Fields

push_pin Backwardpush_pin Downpush_pin Forwardpush_pin Leftpush_pin Onepush_pin Rightpush_pin Uppush_pin Zero

Properties

push_pin Randomdata_object EulerAnglesdata_object IsNaNdata_object IsNearZeroLengthdata_object Lengthdata_object LengthSquareddata_object Normaldata_object xdata_object ydata_object z

Methods

push_pin Cross( a, b ) push_pin CubicBeizer( source, target, sourceTangent, targetTangent, t ) push_pin DistanceBetween( a, b ) push_pin DistanceBetweenSquared( a, b ) push_pin Dot( a, b ) push_pin GetAngle( v1, v2 ) push_pin Lerp( a, b, frac, clamp ) push_pin Lerp( a, b, frac, clamp ) push_pin Max( a, b ) push_pin Min( a, b ) push_pin Parse( str, provider ) push_pin Parse( str ) push_pin Read( reader ) push_pin Reflect( direction, normal ) push_pin SmoothDamp( current, target, velocity, smoothTime, deltaTime ) push_pin Sort( min, max ) push_pin TryParse( str, result ) push_pin TryParse( str, provider, result ) push_pin VectorAngle( vec ) push_pin VectorPlaneProject( v, planeNormal ) code Abs() code AddClamped( toAdd, maxLength ) code AlmostEqual( v, delta ) code Angle( v2 ) code Approach( length, amount ) code Clamp( otherMin, otherMax ) code Clamp( min, max ) code ClampLength( maxLength ) code ClampLength( minLength, maxLength ) code ComponentMax( other ) code ComponentMin( other ) code Cross( b ) code Distance( target ) code DistanceSquared( target ) code Dot( b ) code IsNearlyZero( tolerance ) code LerpTo( target, frac, clamp ) code LerpTo( target, frac, clamp ) code ProjectOnNormal( normal ) code RotateAround( center, rot ) code SnapToGrid( gridSize, sx, sy, sz ) code SubtractDirection( direction, strength ) code WithX( x ) code WithY( y ) code WithZ( z ) code Write( writer ) integration_instructions Equals( obj ) integration_instructions Equals( o ) integration_instructions GetHashCode() integration_instructions ToString()

Extensions

code ToScreen() code ToScreen( screenSize )
Vector3
Derives from ValueType
Implements IEquatable<Vector3>, IParsable<Vector3>

Summary

A point in 3D space.

Constructors

Vector3( float x, float y, float z, )

Initializes a vector with given components.

Vector3( float x, float y, )

Initializes a vector with given components and Z set to 0.

Vector3( Vector3 other, )

Initializes a vector3 from a given vector3, i.e. a copy.

Vector3( Vector2 other, float z, )

Initializes a vector3 from given vector2 and the given Z component.

Vector3( float all = 0, )

Initializes the vector with all components set to given value.

Fields

static readonly Vector3 Backward

A vector with X set to -1. This represents the backwards direction.

static readonly Vector3 Down

A vector with Z set to -1. This represents the downwards direction.

static readonly Vector3 Forward

A vector with X set to 1. This represents the forwards direction.

static readonly Vector3 Left

A vector with Y set to 1. This represents the left hand direction.

static readonly Vector3 One

A vector with all components set to 1.

static readonly Vector3 Up

A vector with Z set to 1. This represents the upwards direction.

static readonly Vector3 Zero

A vector with all components set to 0.

Properties

static Vector3 Random { get; }

Uniformly samples a 3D position from all points with distance at most 1 from the origin.

Angles EulerAngles { get; set; }

The Euler angles of this direction vector.

bool IsNaN { get; }

Returns true if x, y or z are NaN

bool IsNearZeroLength { get; }

Whether length of this vector is nearly zero.

float Length { get; }

Length (or magnitude) of the vector (Distance from 0,0,0).

float LengthSquared { get; }

Squared length of the vector. This is faster than Length, and can be used for things like comparing distances, as long as only squared values are used.

Vector3 Normal { get; }

Returns a unit version of this vector. A unit vector has length of 1.

float x { get; set; }

The X component of this Vector.

float y { get; set; }

The Y component of this Vector.

float z { get; set; }

The Z component of this Vector.

Methods

static Vector3 Cross( Vector3 a, Vector3 b, )

Returns the cross product of the 2 given vectors. If the given vectors are linearly independent, the resulting vector is perpendicular to them both, also known as a normal of a plane.

static Vector3 CubicBeizer( Vector3 source, Vector3 target, Vector3 sourceTangent, Vector3 targetTangent, float t, )

Calculates position of a point on a cubic beizer curve at given fraction.

static float DistanceBetween( Vector3 a, Vector3 b, )

Returns distance between the 2 given vectors.

static float DistanceBetweenSquared( Vector3 a, Vector3 b, )

Returns squared distance between the 2 given vectors. This is faster than DistanceBetween, and can be used for things like comparing distances, as long as only squared values are used.

static float Dot( Vector3 a, Vector3 b, )

Returns the scalar/dot product of the 2 given vectors.

static float GetAngle( Vector3 v1, Vector3 v2, )

Return the distance between the two direction vectors in degrees.

static Vector3 Lerp( Vector3 a, Vector3 b, float frac, bool clamp = true, )

Performs linear interpolation between 2 given vectors.

static Vector3 Lerp( Vector3 a, Vector3 b, Vector3 frac, bool clamp = true, )

Performs linear interpolation between 2 given vectors, with separate fraction for each vector component.

static Vector3 Max( Vector3 a, Vector3 b, )

Returns a vector that has the maximum values on each axis between the 2 given vectors.

static Vector3 Min( Vector3 a, Vector3 b, )

Returns a vector that has the minimum values on each axis between the 2 given vectors.

static Vector3 Parse( string str, IFormatProvider provider, )
Implements IParsable`1.Parse
static Vector3 Parse( string str, )
static Vector3 Read( BinaryReader reader, )

Read a vector3 from given binary reader.

static Vector3 Reflect( Vector3 direction, Vector3 normal, )

Returns a reflected vector based on incoming direction and plane normal. Like a ray reflecting off of a mirror.

static Vector3 SmoothDamp( Vector3 current, Vector3 target, ref Vector3 velocity, float smoothTime, float deltaTime, )

Smoothly move towards the target vector

static void Sort( ref Vector3 min, ref Vector3 max, )

Sort these two vectors into min and max. This doesn't just swap the vectors, it sorts each component. So that min will come out containing the minimum x, y and z values.

static bool TryParse( string str, out Vector3 result, )
static bool TryParse( string str, IFormatProvider provider, out Vector3 result, )
Implements IParsable`1.TryParse

Given a string, try to convert this into a vector. Example input formats that work would be "1,1,1", "1;1;1", "[1 1 1]".

This handles a bunch of different separators ( ' ', ',', ';', '\n', '\r' ).

It also trims surrounding characters ('[', ']', ' ', '\n', '\r', '\t', '"').

static Angles VectorAngle( Vector3 vec, )

Converts a direction vector to an angle.

static Vector3 VectorPlaneProject( Vector3 v, Vector3 planeNormal, )

Projects given vector on a plane defined by planeNormal.

Returns a new vector with all values positive. -5 becomes 5, etc.

Vector3 AddClamped( Vector3 toAdd, float maxLength, )

Try to add to this vector. If we're already over max then don't add. If we're over max when we add, clamp in that direction so we're not.

bool AlmostEqual( Vector3 v, float delta = 0.0001, )

Returns true if we're nearly equal to the passed vector.

float Angle( Vector3 v2, )

Return the distance between the two direction vectors in degrees.

Vector3 Approach( float length, float amount, )

Returns a new vector whose length is closer to given target length by given amount.

Vector3 Clamp( Vector3 otherMin, Vector3 otherMax, )

Returns a vector each axis of which is clamped to between the 2 given vectors. Basically clamps a point to an Axis Aligned Bounding Box (AABB).

Vector3 Clamp( float min, float max, )

Returns a vector each axis of which is clamped to given min and max values.

Vector3 ClampLength( float maxLength, )

Returns a vector whose length is limited to given maximum.

Vector3 ClampLength( float minLength, float maxLength, )

Returns a vector whose length is limited between given minimum and maximum.

Returns a vector that has the maximum values on each axis between this vector and given vector.

Returns a vector that has the minimum values on each axis between this vector and given vector.

Returns the cross product of this and the given vector. If this and the given vectors are linearly independent, the resulting vector is perpendicular to them both, also known as a normal of a plane.

float Distance( Vector3 target, )

Returns distance between this vector to given vector.

float DistanceSquared( Vector3 target, )

Returns squared distance between this vector to given vector. This is faster than Distance, and can be used for things like comparing distances, as long as only squared values are used.

float Dot( Vector3 b, )

Returns the scalar/dot product of this and the given vectors.

bool IsNearlyZero( float tolerance = 1E-45, )

Returns true if value on every axis is less than tolerance away from zero

Vector3 LerpTo( Vector3 target, float frac, bool clamp = true, )

Performs linear interpolation between this and given vectors.

Vector3 LerpTo( Vector3 target, Vector3 frac, bool clamp = true, )

Performs linear interpolation between this and given vectors, with separate fraction for each vector component.

Projects this vector onto another vector.

Basically extends the given normal/unit vector to be as long as necessary to make a right triangle (a triangle which has a 90 degree corner) between (0,0,0), this vector and the projected vector.

Vector3 RotateAround( Vector3 center, Rotation rot, )

Rotate this vector around given point by given rotation and return the result as a new vector.

See Transform.RotateAround for similar method that also transforms rotation.

Vector3 SnapToGrid( float gridSize, bool sx = true, bool sy = true, bool sz = true, )

Snap to grid along any of the 3 axes.

Vector3 SubtractDirection( Vector3 direction, float strength = 1, )

Given a vector like 1,1,1 and direction 1,0,0, will return 0,1,1. This is useful for velocity collision type events, where you want to cancel out velocity based on a normal. For this to work properly, direction should be a normal, but you can scale how much you want to subtract by scaling the direction. Ie, passing in a direction with a length of 0.5 will remove half the direction.

Vector3 WithX( float x, )

Returns this vector with given X component.

Vector3 WithY( float y, )

Returns this vector with given Y component.

Vector3 WithZ( float z, )

Returns this vector with given Z component.

void Write( BinaryWriter writer, )

Write this vector3 to a System.IO.BinaryWriter.

override bool Equals( object obj, )
Overrides ValueType.Equals
override bool Equals( Vector3 o, )
Overrides ValueType.Equals
override int GetHashCode( )
Overrides ValueType.GetHashCode
override string ToString( )
Overrides ValueType.ToString

Formats the Vector into a string "x,y,z"

Extensions

Clientside, returns position of this 3D vector on local clients' screen in 2D coordinates based on the Sandbox.Camera.

Vector2? ToScreen( Vector2 screenSize, )

Same as SandboxGameExtensions.ToScreen, but return value is in absolute coordinates.

Operators

float this[ int index,  ]
Vector3 +( Vector3 c1, Vector3 c2,  )
Vector3 /( Vector3 c1, float f,  )
bool ==( Vector3 left, Vector3 right,  )
bool !=( Vector3 left, Vector3 right,  )
Vector3 *( Vector3 c1, float f,  )
Vector3 *( Vector3 c1, Rotation f,  )
Vector3 *( Vector3 c1, Vector3 c2,  )
Vector3 *( float f, Vector3 c1,  )
Vector3 -( Vector3 c1, Vector3 c2,  )
Vector3 -( Vector3 value,  )
implicit Vector3 =( Color value,  )
implicit Vector3 =( float value,  )
implicit Vector3 =( Vector2 value,  )
implicit Vector3 =( Vector4 vec,  )
implicit Vector3 =( Vector3 value,  )
implicit Vector3 =( Vector3 value,  )

Referencing Members

Vector3 = AudioMaterial.Absorption { get; set; }
virtual void WalkController.Accelerate( Vector3, float, float, float, )
PhysicsShape = PhysicsBody.AddMeshShape( List<Vector3>, List<int>, )
PhysicsShape = PhysicsBody.AddMeshShape( Span<Vector3>, Span<int>, )
static Vector3 = Input.AnalogMove { get; set; }
bool = GizmoControls.Arrow( string, Vector3, out float, float, float, float, float, float, string, )
void DebugOverlay.Axis( Vector3, Rotation, float, float, bool, )
Vector3 = Entity.BaseVelocity { get; set; }
BBox.BBox( Vector3, float, )
Bone.Bone( string, string, Vector3, Rotation, )
static Trace = Trace.Box( Vector3, in Vector3, in Vector3, )
static Trace = Trace.Box( Vector3, in Ray, in float, )
void DebugOverlay.Box( Vector3, Vector3, Color, float, bool, )
void DebugOverlay.Box( Vector3, Vector3, Vector3, Color, float, bool, )
void DebugOverlay.Box( Vector3, Rotation, Vector3, Vector3, Color, float, bool, )
static Vector3[] = NavMesh.BuildPath( Vector3, Vector3, )
static bool = NavMesh.BuildPath( Vector3, Vector3, List<Vector3>, )
Vector3 = BBox.Center { get; }
Vector3 = Line.Center { get; }
Vector3 = Sphere.Center { get; set; }
Vector3 = Node.Center { get; }
Vector3 = NavArea.Center { get; }
void GizmoHitbox.Circle( Vector3, Vector3, float, float, )
void DebugOverlay.Circle( Vector3, Rotation, float, Color, float, bool, )
bool = BBox.Contains( Vector3, )
IEnumerable<Vector3> = BBox.Corners { get; }
static Particles = Particles.Create( string, Vector3, )
static Matrix = Matrix.CreateRotationX( float, Vector3, )
static Matrix = Matrix.CreateRotationY( float, Vector3, )
static Matrix = Matrix.CreateRotationZ( float, Vector3, )
Vector3 = Line.Delta { get; }
float = Line.Distance( Vector3, )
float = Line.Distance( Vector3, out Vector3, )
float = Node.Distance( Vector3, )
Vector3 = Rotation.Down { get; }
Vector3 = Transform.Down { get; }
static void ToolRender.DrawBox( Vector3, Vector3, Color, )
static void ToolRender.DrawWorldSpaceText( string, Vector3, Vector2, Color, float, )
Vector3 = Line.End { get; }
Vector3 = NavigationPath.EndPoint { get; set; }
Vector3 = Result.EndPosition { get; set; }
Vector3 = Player.EyeLocalPosition { get; set; }
Vector3 = Player.EyePosition { get; set; }
Vector3 = ShatterGlass.FaceCenter { get; set; }
Vector3 = VoxelSurface.FaceCenter { get; set; }
static Vector3 = Noise.FbmVector( int, float, float, )
static IEnumerable<Entity> = Entity.FindInSphere( Vector3, float, )
Vector3 = DamageInfo.Force { get; set; }
Vector3 = Angles.Forward { get; set; }
Vector3 = Ray.Forward { get; set; }
Vector3 = Rotation.Forward { get; }
static Rotation = Rotation.FromAxis( Vector3, float, )
static BBox = BBox.FromPoints( IEnumerable<Vector3>, float, )
static BBox = BBox.FromPositionAndSize( Vector3, float, )
static Sound = Sound.FromWorld( To, string, Vector3, )
static Sound = Sound.FromWorld( string, Vector3, )
GenericEvent.GenericEvent( string, int, float, string, Vector3, )
static NavArea = NavArea.GetClosestNav( Vector3, NavAgentHull, GetNavAreaFlags, ref Vector3, float, float, float, float, )
static NavArea = NavArea.GetClosestNav( Vector3, NavAgentHull, GetNavAreaFlags, float, float, float, float, )
static Vector3 = Screen.GetDirection( Vector2, float, )
static Vector3 = Screen.GetDirection( Vector2, float, Rotation, )
float = Plane.GetDistance( Vector3, )
static float = Gizmo.GetMouseDistance( Vector3, Vector3, )
static Vector3? = NavMesh.GetPointWithinRadius( Vector3, float, float, )
static Vector3? = NavMesh.GetPointWithinRadius( Vector3, float, float, )
Vector3 = PhysicsWorld.Gravity { get; set; }
Vector3 = PhysicsSettings.Gravity { get; set; }
Vector3 = Result.HitNormal { get; set; }
Vector3 = Result.HitPosition { get; set; }
Vector3 = Player.InputDirection { get; protected set; }
bool = Plane.IsInFront( Vector3, )
bool = Frustum.IsInside( Vector3, )
Vector3 = Rotation.Left { get; }
Vector3 = Transform.Left { get; }
Line.Line( Vector3, Vector3, float, )
void DebugOverlay.Line( Vector3, Vector3, Color, float, bool, )
void DebugOverlay.Line( Vector3, Vector3, float, bool, )
void GizmoDraw.LineCylinder( Vector3, Vector3, float, float, int, )
Task<bool> = KeyframeEntity.LocalKeyframeTo( Vector3, float, Function, )
virtual Vector3 = Entity.LocalPosition { get; set; }
override Vector3 = ModelEntity.LocalPosition { get; set; }
virtual Vector3 = Entity.LocalVelocity { get; set; }
void FlyingController.Move( Vector3, int, )
Vector3 = Triangle.Normal { get; }
Vector3 = Node.Normal { get; }
Vector3 = VertexDetail.Normal { get; set; }
Vector3 = NavArea.Normal { get; }
Vector3 = SkyboxAccessor.Offset { get; set; }
Vector3 = ModelBreakPiece.Offset { get; set; }
virtual void ModelEntity.OnAnimEventFootstep( Vector3, int, float, )
override void Player.OnAnimEventFootstep( Vector3, int, float, )
virtual void ModelEntity.OnAnimEventGeneric( string, int, float, Vector3, string, )
protected virtual void AnimatedEntity.OnAnimFootstep( bool, Vector3, )
static BBox = BBox.op_Addition( BBox, Vector3, )
Vector3 = Plane.Origin { get; }
static Vector3 = Selection.PivotPosition { get; set; }
static void Decal.Place( DecalDefinition, Entity, int, Vector3, Rotation, )
Plane.Plane( Vector3, double, )
abstract void AnimGraphDirectPlayback.Play( string, Vector3, float, float, )
Vector3 = PhysicsGroup.Pos { get; }
Vector3 = Ray.Position { get; set; }
static Vector3 = Camera.Position { get; set; }
abstract Vector3 = IEntity.Position { get; set; }
Vector3 = PhysicsBody.Position { get; set; }
Vector3 = SceneCamera.Position { get; set; }
Vector3 = SceneObject.Position { get; set; }
Vector3 = MusicPlayer.Position { get; set; }
bool = GizmoControls.Position( string, Vector3, out Vector3, Rotation?, float, )
Vector3 = Bone.Position { get; init; }
Vector3 = SkyboxAccessor.Position { get; set; }
Vector3 = SoundEvent.Position { get; set; }
abstract Vector3 = EntityObject.Position { get; set; }
Vector3 = VertexDetail.Position { get; set; }
virtual Vector3 = Entity.Position { get; set; }
override Vector3 = ModelEntity.Position { get; set; }
Vector3 = DamageInfo.Position { get; set; }
Vector3 = MapNode.Position { get; set; }
Vector3 = BasePathNode.Position { get; set; }
abstract Vector3 = ISoundscapeEntity.Position { get; }
Vector3 = PawnController.Position { get; set; }
Vector3 = WorldPanel.Position { get; set; }
Vector3 = Ray.Project( float, )
static Vector3 = SandboxSystemExtensions.ReadVector3( BinaryReader, )
Vector3 = Rotation.Right { get; }
Vector3 = Transform.Right { get; }
abstract Vector3 = EntityObject.Scale { get; set; }
Vector3 = MapNode.Scale { get; set; }
static IDisposable = Gizmo.Scope( string, Vector3, )
static IDisposable = Gizmo.Scope( string, Vector3, Rotation, float, )
protected virtual float = NavigationPath.ScoreFor( in Connection, Vector3, )
bool = Material.Set( string, Vector3, )
void Particles.SetEntity( int, Entity, Vector3, bool, )
void Particles.SetForward( int, Vector3, )
void Particles.SetPosition( int, Vector3, )
Vector3 = BBox.Size { get; }
Vector3 = SceneCullingBox.Size { get; set; }
void GizmoDraw.SolidCapsule( Vector3, Vector3, float, int, int, )
void GizmoDraw.SolidCircle( Vector3, float, float, float, int, )
void GizmoDraw.SolidCone( Vector3, Vector3, float, int?, )
void GizmoDraw.SolidCylinder( Vector3, Vector3, float, int, )
void GizmoDraw.SolidRing( Vector3, float, float, float, float, int, )
void GizmoDraw.SolidSphere( Vector3, float, int, int, )
SoundEvent.SoundEvent( string, Vector3, string, )
Sphere.Sphere( Vector3, float, )
void DebugOverlay.Sphere( Vector3, float, Color, float, bool, )
void GizmoDraw.Sprite( Vector3, float, string, )
void GizmoDraw.Sprite( Vector3, float, Texture, )
float = Line.SqrDistance( Vector3, )
Vector3 = Line.Start { get; }
Vector3 = Result.StartPosition { get; set; }
Vector3 = BasePathNode.TangentIn { get; set; }
Vector3 = BasePathNode.TangentOut { get; set; }
static bool = Trace.TestPoint( Vector3, string, float, )
abstract bool = ISoundscapeEntity.TestPosition( Vector3, )
void DebugOverlay.Text( string, Vector3, int, Color, float, float, )
void DebugOverlay.Text( string, Vector3, Color, float, float, )
void DebugOverlay.Text( string, Vector3, float, float, )
Vector3? = Plane.Trace( Ray, bool, double, )
virtual IEnumerable<TraceResult> = BaseWeapon.TraceBullet( Vector3, Vector3, float, )
virtual bool = KeyframeEntity.TryLocalKeyframeTo( Vector3, float, )
Vector3 = Rotation.Up { get; }
Vector3 = Transform.Up { get; }
void PhysicsShape.UpdateMesh( List<Vector3>, List<int>, )
void PhysicsShape.UpdateMesh( Span<Vector3>, Span<int>, )
Vector3 = Vector3Property.Value { get; set; }
Vector3 = GenericEvent.Vector { get; set; }
Vector3 = AsAccessor.Vector3 { get; set; }
static Vector3 = SandboxSystemExtensions.VectorInCube( Random, float, )
static Vector3 = SandboxSystemExtensions.VectorInSphere( Random, float, )
abstract Vector3 = IEntity.Velocity { get; set; }
Vector3 = PhysicsBody.Velocity { get; set; }
Vector3 = VrHand.Velocity { get; }
virtual Vector3 = Entity.Velocity { get; set; }
override Vector3 = ModelEntity.Velocity { get; set; }
Vector3 = VrHand.Velocity { get; set; }
Vector3 = PawnController.Velocity { get; set; }
Vector3 = Result.VertexInfluence { get; set; }
List<Vector3> = Node.Vertices { get; }
Vector3 = ScenePortal.ViewPosition { get; set; }
void CitizenAnimationHelper.WithLookAt( Vector3, float, float, float, )
abstract Vector3 = IBasePathNode.WorldPosition { get; }
virtual Vector3 = BasePathNode.WorldPosition { get; }
abstract Vector3 = IBasePathNode.WorldTangentIn { get; }
virtual Vector3 = BasePathNode.WorldTangentIn { get; }
abstract Vector3 = IBasePathNode.WorldTangentOut { get; }
virtual Vector3 = BasePathNode.WorldTangentOut { get; }
static void SandboxSystemExtensions.Write( BinaryWriter, Vector3, )