private void OnGizmoScale(ITransformable transformable, TransformationEventArgs e) { var delta = (Vector3)e.Value * transformScaleFactor; if (Gizmo.ActiveMode == GizmoMode.UniformScale) { if (transformable is SceneEntity entity) { STATIC_EDITOR_MODE.ExecuteOnSelfAndChildEntities(entity, sceneEntity => sceneEntity.Scale *= 1 + ((delta.X + delta.Y + delta.Z) / 3)); } else { transformable.Scale *= 1 + ((delta.X + delta.Y + delta.Z) / 3); } } else { if (transformable is SceneEntity entity) { STATIC_EDITOR_MODE.ExecuteOnSelfAndChildEntities(entity, sceneEntity => sceneEntity.Scale += delta); } else { transformable.Scale += delta; } } transformable.Scale = Vector3.Clamp(transformable.Scale, Vector3.Zero, transformable.Scale); }
public Rgb(Vector3 vector, IRgbWorkingSpace workingSpace) : this() { // Clamp to 0-1 range. this.backingVector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One); this.WorkingSpace = workingSpace; }
public void Intersects(ref BoundingSphere sphere, out bool result) { Vector3 v; Vector3.Clamp(ref sphere.Center, ref Min, ref Max, out v); result = ((sphere.Center - v).LengthSquared <= sphere.Radius * sphere.Radius); }
public static Vector3 HSV2RGB(Vector3 hsv) { Vector4 K = new Vector4(1.0f, 2.0f / 3.0f, 1.0f / 3.0f, 3.0f); Vector3 p = Abs(Fract(Fill(hsv.X) + K.Xyz) * 6.0f - Fill(K.W)); return(hsv.Z * Mix(Fill(K.X), Vector3.Clamp(p - Fill(K.X), Fill(0.0f), Fill(1.0f)), hsv.Y)); }
public override void DragDeltaIndicatorAxis(Vector3 dragDeltaScreen) { if (dragDeltaScreen == Vector3.zero) { return; } //World-View space only use half width and half height dragDeltaScreen[0] /= (Screen.width / 2); // To viewport coordinate dragDeltaScreen[1] /= (Screen.height / 2); // to calculate selected axis's delta position from startPoint to endPoint in screen coordinate axisStartPointWorld = indicatorAxisTrans.position + scalingDirection; axisEndPointWorld = indicatorAxisTrans.position - scalingDirection; axisStartPointViewport = MainManager.Instance.worldCamera.WorldToViewportPoint(axisStartPointWorld); axisEndPointViewport = MainManager.Instance.worldCamera.WorldToViewportPoint(axisEndPointWorld); axisDeltaViewport = axisStartPointViewport - axisEndPointViewport; //axis start/end point position delta in screen coordinate // project dragDeltaPosScreen on axisDeltaScreen, use the result as the coefficient // e.g axisDeltaScreen -> (0,1,0) && dragDeltaScreen -> (1,0,0) ==> projectionValue -> 0 ==> should not move target projectionValue = Vector3.Dot(dragDeltaScreen, axisDeltaViewport); // move targetTranspos targetGOTransScale = targetModel.localScale; targetGOTransScale += projectionValue * scalingDirection * axisCoefficient * 0.5f; targetGOTransScale.Clamp(0.05f, float.MaxValue); targetModel.localScale = targetGOTransScale; }
private Vector3 LimitAngle(Vector3 angle, bool axis_lim, Vector3 low, Vector3 high) { if (!axis_lim) { return(Vector3.Clamp(angle, low, high)); } Vector3 vecL1 = 2.0f * low - angle; Vector3 vecH1 = 2.0f * high - angle; if (angle.X < low.X) { angle.X = (vecL1.X <= high.X) ? vecL1.X : low.X; } else if (angle.X > high.X) { angle.X = (vecH1.X >= low.X) ? vecH1.X : high.X; } if (angle.Y < low.Y) { angle.Y = (vecL1.Y <= high.Y) ? vecL1.Y : low.Y; } else if (angle.Y > high.Y) { angle.Y = (vecH1.Y >= low.Y) ? vecH1.Y : high.Y; } if (angle.Z < low.Z) { angle.Z = (vecL1.Z <= high.Z) ? vecL1.Z : low.Z; } else if (angle.Z > high.Z) { angle.Z = (vecH1.Z >= low.Z) ? vecH1.Z : high.Z; } return(angle); }
public void MoveToPoint(Vector3 destination, float dt) { Velocity += Objective(true, destination); CheckBoundaries(); Velocity = Vector3.Clamp(Velocity, -Vector3.One * MAX_SPEED, Vector3.One * MAX_SPEED); CalculatePositionAndRotation(dt); }
private Vector3 ComputeBaseThrust(Vector3 direction) { Matrix invWorldRot = m_grid.PositionComp.GetWorldMatrixNormalizedInv().GetOrientation(); Vector3 localVelocity = Vector3.Transform(m_grid.Physics.LinearVelocity, ref invWorldRot); Vector3 positiveControl = Vector3.Clamp(direction, Vector3.Zero, Vector3.One); Vector3 negativeControl = Vector3.Clamp(direction, -Vector3.One, Vector3.Zero); Vector3 slowdownControl = Vector3.Zero; if (DampenersEnabled) { slowdownControl = Vector3.IsZeroVector(direction, 0.001f) * Vector3.IsZeroVector(m_totalThrustOverride); } Vector3 thrust = negativeControl * m_maxNegativeThrust + positiveControl * m_maxPositiveThrust; thrust = Vector3.Clamp(thrust, -m_maxNegativeThrust, m_maxPositiveThrust); const float STOPPING_TIME = 0.5f; var slowdownAcceleration = -localVelocity / STOPPING_TIME; var slowdownThrust = slowdownAcceleration * m_grid.Physics.Mass * slowdownControl; thrust = Vector3.Clamp(thrust + slowdownThrust, -m_maxNegativeThrust * MyFakes.SLOWDOWN_FACTOR_THRUST_MULTIPLIER, m_maxPositiveThrust * MyFakes.SLOWDOWN_FACTOR_THRUST_MULTIPLIER); return(thrust); }
/// <summary> /// Creates a new material with the specified properties. Components outside the range [0,1] will be clamped. /// </summary> /// <param name="diffuse">Diffuse reflection component</param> /// <param name="specular">Specular reflection component</param> /// <param name="emissive">Emissive component</param> /// <param name="texture">Texture</param> public Material(Vector3 diffuse, Vector3 specular, Vector3 emissive, Texture texture = null) { this.Diffuse = diffuse.Clamp(); this.Specular = specular.Clamp(); this.Emissive = emissive.Clamp(); this.Texture = texture; }
public void Overlap(ref BoundingSphere sphere, List <Collider> result) { Vector3 center = sphere.Center; center.Y = 0; Vector3 min = new Vector3(Min.X, 0, Min.Z); Vector3 max = new Vector3(Max.X, 0, Max.Z); Vector3 vector; Vector3.Clamp(ref center, ref min, ref max, out vector); if (Vector3.DistanceSquared(sphere.Center, vector) <= sphere.Radius * sphere.Radius) { foreach (Collider c in Colliders) { if (c.Overlap(ref sphere)) { result.Add(c); } } if (Children != null) { for (int i = 0; i < 4; ++i) { Children[i].Overlap(ref sphere, result); } } } }
public YCbCr(Vector3 vector) { vector = Vector3.Clamp(vector, Min, Max); this.Y = vector.X; this.Cb = vector.Y; this.Cr = vector.Z; }
/// <summary> /// A check to see if the given BoundingSphere is inside this BoundingBox. /// </summary> /// <param name="sphere">The BoundingSphere to check.</param> /// <returns>The result of the check.</returns> public ContainableTypes Contains(BoundingSphere sphere) { Vector3 closestPos = Vector3.Clamp(sphere.Center, Min, Max); float dist = Vector3.DistanceSquared(sphere.Center, closestPos); if (dist > sphere.Radius * sphere.Radius) { return(ContainableTypes.None); } else if (Min.X + sphere.Radius <= sphere.Center.X && sphere.Center.X <= Max.X - sphere.Radius && Max.X - Min.X > sphere.Radius && Min.Y + sphere.Radius <= sphere.Center.Y && sphere.Center.Y <= Max.Y - sphere.Radius && Max.Y - Min.Y > sphere.Radius && Min.Z + sphere.Radius <= sphere.Center.Z && sphere.Center.Z <= Max.Z - sphere.Radius && Max.Z - Min.Z > sphere.Radius) { return(ContainableTypes.Fully); } else { return(ContainableTypes.Partial); } }
private static int EncodeAC(Vector3 value, float maximumValue) { Vector3 scaledValue = value / maximumValue; Vector3 calc = Vector3.Clamp(CopySign(Vector3.SquareRoot(Vector3.Abs(scaledValue)), scaledValue) * 9 + vector95, Vector3.Zero, vector18); return((int)calc.X * 19 * 19 + (int)calc.Y * 19 + (int)calc.Z); }
public static Vector3 GetNeighbourSectorShipPosition(Vector3 currentShipPosition) { Vector3 abs = new Vector3(Math.Abs(currentShipPosition.X), Math.Abs(currentShipPosition.Y), Math.Abs(currentShipPosition.Z)); if (abs.X > abs.Y) { if (abs.X > abs.Z) { // X is biggest currentShipPosition.X = -currentShipPosition.X; } else { // Z is biggest currentShipPosition.Z = -currentShipPosition.Z; } } else if (abs.Y > abs.Z) { // Y is biggest currentShipPosition.Y = -currentShipPosition.Y; } else { // Z is biggest currentShipPosition.Z = -currentShipPosition.Z; } // Clamp all direction to prevent automatic travel when position is diagonally outside sector float maxDistance = MyMwcSectorConstants.SECTOR_SIZE_HALF; Vector3 border = new Vector3(maxDistance, maxDistance, maxDistance); return(Vector3.Clamp(currentShipPosition, -border, border)); }
// also call this when scale is changed? public void ClampSize() { if (MapBuilder.instance.ShapeConstraints.TryGetValue(Shape, out ShapeSizeConstraint ssc)) { Scale = Scale.Clamp(ssc.min, ssc.max); } }
/// <summary> /// </summary> /// <param name="minPoint"> /// </param> /// <param name="maxPoint"> /// </param> /// <param name="sphereCenter"> /// </param> /// <param name="sphereRadius"> /// </param> /// <returns> /// </returns> public static bool IntersectsSphere(Vector3 minPoint, Vector3 maxPoint, Vector3 sphereCenter, double sphereRadius) { var vector = Vector3.Clamp(sphereCenter, minPoint, maxPoint); var num = Vector3.DistanceSquared(sphereCenter, vector); return(num <= (sphereRadius * sphereRadius)); }
/// <summary> /// To limit the amount of rotation /// </summary> /// <param name="ikLink">IKLink</param> private void RestrictRotation(IkLink ikLink) { if (!ikLink.isLimited) { return; } float xRotation, yRotation, zRotation; var type = SplitRotation(ikLink.ikLinkBone.Rotation, out xRotation, out yRotation, out zRotation); var clamped = Vector3.Clamp(new Vector3(xRotation, yRotation, zRotation).NormalizeEular(), ikLink.minRot, ikLink.maxRot); xRotation = clamped.X; yRotation = clamped.Y; zRotation = clamped.Z; switch (type) { case 0: ikLink.ikLinkBone.Rotation = Quaternion.RotationMatrix(Matrix.RotationX(xRotation) * Matrix.RotationY(yRotation) * Matrix.RotationZ(zRotation)); break; case 1: ikLink.ikLinkBone.Rotation = Quaternion.RotationMatrix(Matrix.RotationY(yRotation) * Matrix.RotationZ(zRotation) * Matrix.RotationX(xRotation)); break; case 2: ikLink.ikLinkBone.Rotation = Quaternion.RotationYawPitchRoll(yRotation, xRotation, zRotation); break; } }
public static Vector3UByte Normalize(Vector3 vec, float range) { Vector3 vector = (Vector3)((((vec / range) / 2f) + new Vector3(0.5f)) * 255f); Vector3.Clamp(ref vector, ref Vector3.Zero, ref m_clampBoundary, out vector); return(new Vector3UByte((byte)vector.X, (byte)vector.Y, (byte)vector.Z)); }
private void RecomputeThrustParameters() // Only gets called when m_thrustsChanged is set { m_totalThrustOverride = Vector3.Zero; m_totalThrustOverridePower = 0; m_maxPositiveThrust = new Vector3(); m_maxNegativeThrust = new Vector3(); MaxRequiredPowerInput = 0.0f; MinRequiredPowerInput = 0.0f; foreach (FuelTypeData dataByType in m_dataByFuelType) { dataByType.MaxRequiredPowerInput = 0f; dataByType.MaxPositiveThrust = new Vector3(); dataByType.MaxNegativeThrust = new Vector3(); dataByType.MaxRequirementsByDirection.Clear(); foreach (var dir in dataByType.ThrustsByDirection) { if (!dataByType.MaxRequirementsByDirection.ContainsKey(dir.Key)) { dataByType.MaxRequirementsByDirection[dir.Key] = 0f; } float maxRequiredPower = 0; foreach (MyEntity thrustEntity in dir.Value) { if (RecomputeOverriddenParameters(thrustEntity)) { continue; } if (!IsUsed(thrustEntity)) { continue; } var forceMagnitude = ForceMagnitude(thrustEntity); var forceMultiplier = CalculateForceMultiplier(thrustEntity); dataByType.MaxPositiveThrust += Vector3.Clamp(-dir.Key * forceMagnitude, Vector3.Zero, Vector3.PositiveInfinity); dataByType.MaxNegativeThrust += -Vector3.Clamp(-dir.Key * forceMagnitude, Vector3.NegativeInfinity, Vector3.Zero); maxRequiredPower += MaxPowerConsumption(thrustEntity) * forceMultiplier; dataByType.MinRequiredPowerInput = MinPowerConsumption(thrustEntity); } dataByType.MaxRequirementsByDirection[dir.Key] += maxRequiredPower; } dataByType.MaxRequiredPowerInput += Math.Max(dataByType.MaxRequirementsByDirection[Vector3I.Forward], dataByType.MaxRequirementsByDirection[Vector3I.Backward]); dataByType.MaxRequiredPowerInput += Math.Max(dataByType.MaxRequirementsByDirection[Vector3I.Left], dataByType.MaxRequirementsByDirection[Vector3I.Right]); dataByType.MaxRequiredPowerInput += Math.Max(dataByType.MaxRequirementsByDirection[Vector3I.Up], dataByType.MaxRequirementsByDirection[Vector3I.Down]); MaxRequiredPowerInput += dataByType.MaxRequiredPowerInput; MinRequiredPowerInput += dataByType.MinRequiredPowerInput; m_maxPositiveThrust += dataByType.MaxPositiveThrust; m_maxNegativeThrust += dataByType.MaxNegativeThrust; } m_thrustsChanged = false; }
private static Struct888 Pack(ref Vector3 vector) { vector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One); vector *= MaxBytes; vector += Half; return(new Struct888((byte)vector.X, (byte)vector.Y, (byte)vector.Z)); }
private Vector3 ComputeBaseThrust(Vector3 controlThrust) { if (Entity.Physics == null) { return(Vector3.Zero); } Matrix invWorldRot = Entity.PositionComp.GetWorldMatrixNormalizedInv().GetOrientation(); //Matrix invWorldRot = Matrix.Invert(m_grid.Physics.RigidBody.GetRigidBodyMatrix());// m_grid.PositionComp.GetWorldMatrixNormalizedInv().GetOrientation(); Vector3 gravityVector = Entity.Physics.IsMoving ? Entity.Physics.Gravity / 2.0f : Vector3.Zero; Vector3 localVelocity = Vector3.TransformNormal(Entity.Physics.LinearVelocity + gravityVector, invWorldRot); Vector3 positiveControl = Vector3.Clamp(controlThrust, Vector3.Zero, Vector3.One); Vector3 negativeControl = Vector3.Clamp(controlThrust, -Vector3.One, Vector3.Zero); Vector3 slowdownControl = Vector3.Zero; if (DampenersEnabled) { slowdownControl = Vector3.IsZeroVector(controlThrust, 0.001f) * Vector3.IsZeroVector(m_totalThrustOverride); } Vector3 thrust = negativeControl * m_maxNegativeThrust + positiveControl * m_maxPositiveThrust; thrust = Vector3.Clamp(thrust, -m_maxNegativeThrust, m_maxPositiveThrust); const float STOPPING_TIME = 0.5f; Vector3 slowdownAcceleration = -localVelocity / STOPPING_TIME; Vector3 slowdownThrust = slowdownAcceleration * Entity.Physics.Mass * slowdownControl; thrust = Vector3.Clamp(thrust + slowdownThrust, -m_maxNegativeThrust * SlowdownFactor, m_maxPositiveThrust * SlowdownFactor); return(thrust); }
public bool Intersects(BoundingSphere sphere) { Vector3 v; Vector3.Clamp(ref sphere.Center, ref Min, ref Max, out v); return((sphere.Center - v).LengthSquared <= sphere.Radius * sphere.Radius); }
Vector3 getColorFromPos(Vector2 pos, float iTime) { Vector3 col = new Vector3(0.01f); Vector3 ro = new Vector3(0f, 1f, 0f); if (!rayDirections.TryGetValue(pos, out Vector3 rd)) { throw new ArgumentNullException(String.Format("Unable to get Ray Direction for x:{0} y:{1}", pos.X - .5f, pos.Y - .5f)); } float t = RayMarch(ro, rd); if (t < 100) { Vector3 p = Vector3.Add(ro, Vector3.Multiply(rd, t)); Vector3 lightPos = new Vector3(0, 5, 6); Vector3 lightColor = new Vector3(0, 0, 1f); lightPos.X += (float)Complex.Sin(iTime).Real; lightPos.Z += (float)Complex.Multiply(Complex.Cos(iTime), 2f).Real; Vector3 l = Vector3.Normalize(Vector3.Subtract(lightPos, p)); Vector3 n = GetNormal(p); float dif = Clamp(Vector3.Dot(n, l), 0f, 1f); float d = RayMarch(p + n * 0.01f, l); if (d < Vector3.Distance(lightPos, p)) { dif *= .1f; } col += dif * lightColor; } return(Vector3.Clamp(Vector3.Multiply(255f, col), Vector3.Zero, new Vector3(255f))); }
public Hsl(Vector3 vector) { vector = Vector3.Clamp(vector, Min, Max); this.H = vector.X; this.S = vector.Y; this.L = vector.Z; }
public override void Update(TimeSpan elapsed) { transform.Scale = Vector3.Clamp( transform.Scale += Amount * (float)elapsed.TotalSeconds, Minimum, Maximum); }
private Quaternion ClampEular(Quaternion rot, Vector3 min, Vector3 max) { Vector3 eular = RotationEularMatrixXZY(rot); eular = Vector3.Clamp(eular, min, max); return(RotationEularXZY(eular)); }
public void SpawnTrileAt(int id, string actorTypeName) { BoundingBox boundingBox = this.LevelManager.Volumes[id].BoundingBox; Vector3 position1 = (boundingBox.Min + boundingBox.Max) / 2f; Trile trile = Enumerable.FirstOrDefault <Trile>(this.LevelManager.ActorTriles((ActorType)Enum.Parse(typeof(ActorType), actorTypeName, true))); if (trile == null) { return; } Vector3 vector3 = position1 - Vector3.One / 2f; NearestTriles nearestTriles = this.LevelManager.NearestTrile(position1); TrileInstance trileInstance = nearestTriles.Surface ?? nearestTriles.Deep; if (trileInstance != null) { vector3 = FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint) * vector3 + trileInstance.Center * FezMath.DepthMask(this.CameraManager.Viewpoint) - FezMath.ForwardVector(this.CameraManager.Viewpoint) * 2f; } Vector3 position2 = Vector3.Clamp(vector3, Vector3.Zero, this.LevelManager.Size - Vector3.One); ServiceHelper.AddComponent((IGameComponent) new GlitchyRespawner(ServiceHelper.Game, new TrileInstance(position2, trile.Id) { OriginalEmplacement = new TrileEmplacement(position2) })); }
private static void optimizeEndPoints4(Vector3 *points, CMPRBlock *block) { float alpha2_sum = 0.0f; float beta2_sum = 0.0f; float alphabeta_sum = 0.0f; Vector3 alphax_sum = new Vector3(); Vector3 betax_sum = new Vector3(); uint indices = block->_lookup; for (int i = 0, bi = 30; i < 16; ++i, bi -= 2) { uint bits = indices >> bi; float beta = bits & 1; if ((bits & 2) != 0) { beta = (1 + beta) / 3.0f; } float alpha = 1.0f - beta; alpha2_sum += alpha * alpha; beta2_sum += beta * beta; alphabeta_sum += alpha * beta; alphax_sum += alpha * points[i]; betax_sum += beta * points[i]; } float denom = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; if (Math.Abs(denom) <= 0.0001f) { return; } float factor = 1.0f / denom; Vector3 a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor; Vector3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor; a.Clamp(0.0f, 255.0f); b.Clamp(0.0f, 255.0f); ushort color0 = roundAndExpand(&a); ushort color1 = roundAndExpand(&b); if (color0 < color1) { Vector3 t = a; a = b; b = t; VoidPtr.Swap(&color0, &color1); } //CMPRBlock block = new CMPRBlock(); block->_root0._data = color0; block->_root1._data = color1; block->_lookup = computeIndices4(points, &a, &b); }
private static ushort Pack(ref Vector3 vector) { vector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One); return((ushort)( (((uint)Math.Round(vector.X * 31F) & 31) << 10) | (((uint)Math.Round(vector.Y * 31F) & 31) << 5) | ((uint)Math.Round(vector.Z * 31F) & 31))); }
private static uint Pack(ref Vector3 vector) { vector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One); return((uint)( ((uint)Math.Round(vector.X * 255F) & 255) | (((uint)Math.Round(vector.Y * 255F) & 255) << 8) | (((uint)Math.Round(vector.Z * 255F) & 255) << 16))); }
/// <summary> /// Adjusts the contrast of a pixel. /// </summary> /// <param name="argb">The ARGB pixel to adjust.</param> /// <param name="scale">The value to scale the contrast by.</param> /// <returns>The adjusted ARGB pixel.</returns> public static int AdjustContrast(int argb, float scale) { int a = (argb >> 24) & 0xFF; int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = (argb) & 0xFF; Vector3 res = new Vector3(r, g, b); res.Multiply(1 / 255.0f); res.Subtract(0.5f); res.Multiply(scale); res.Add(0.5f); res.Multiply(255.0f); res.Clamp(0, 255); r = (int)res.X; g = (int)res.Y; b = (int)res.Z; return (a << 24) | (r << 16) | (g << 8) | b; }
/// <summary> /// Finds the closest point on a bounding box from another point /// </summary> /// <param name="box"></param> /// <param name="point"></param> /// <returns></returns> public static Vector3 ClosestPoint(this BoundingBox box, Vector3 point) { return point.Clamp(box.Min, box.Max); }