static byte PaethVec(byte a, byte b, byte c) { var p = a + b - c; var resVec = Vector3.Abs(new Vector3(p, p, p) - new Vector3(a, b, c)); return(resVec.X <= resVec.Y && resVec.X <= resVec.Z ? a : (resVec.Y <= resVec.Z ? b : c)); }
// Manipulation, highlight protected override Axis GetInferredManipulationAxis( Vector3 primary, Vector3 secondary, bool secondaryInside) { if (secondaryInside) { return(Axis.Invalid); } Vector3 vHandsInObjectSpace = transform.InverseTransformDirection(primary - secondary); Vector3 vAbs = vHandsInObjectSpace.Abs(); Axis bestAxis = Axis.Invalid; float bestDot = 0; for (int i = 0; i < sm_AxisDirections.Length; ++i) { float dot = Vector3.Dot(vAbs, sm_AxisDirections[i].direction); if (dot > bestDot) { bestDot = dot; bestAxis = sm_AxisDirections[i].axis; } } return(bestAxis); }
public async static Task <bool> WithinCuboid( [InputPin(PropertyMode = PropertyMode.Never)] PoseModel source, [InputPin(PropertyMode = PropertyMode.Default, Editor = "Pose")] PoseProperty center, [InputPin(PropertyMode = PropertyMode.Default)] double width = 0.1, [InputPin(PropertyMode = PropertyMode.Default)] double height = 0.1, [InputPin(PropertyMode = PropertyMode.Default)] double depth = 0.1, CancellationToken cancel = default(CancellationToken)) { if (center == null) { throw new ArgumentNullException(nameof(center), "Required property 'center' of CheckCurrentPose module was not specified."); } if (source == null) { throw new ArgumentNullException(nameof(source), "Required property 'source' of CheckCurrentPose module was not specified."); } var centerPose = await ResolveProperty(center); var currentPose = source.ToPose(); var dist = Vector3.Abs(Vector3.Subtract(centerPose.Translation, currentPose.Translation)); return(dist.X < width && dist.Y < height && dist.Z < depth); }
public float ProjectedArea(Vector3 viewDir) { Vector3 span = Max - Min; Vector3 size = new Vector3(span.Y, span.Z, span.X) * new Vector3(span.Z, span.X, span.Y); return(Vector3.Abs(viewDir).Dot(size)); }
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 bool ContainsPoint(Vector3 point) { Matrix4x4.Invert(Transformation, out var invMatrix); var local = Vector3.Abs(Vector3.Transform(point, invMatrix)); return(local.X <= HalfExtents.X && local.Y <= HalfExtents.Y && local.Z <= HalfExtents.Z); }
/// <inheritdoc /> public override void Refresh() { base.Refresh(); if (!HasDifferentValues) { var value = (Vector4)Values[0]; var color = new Vector3(value); var scale = value.W; float min = color.MinValue; float max = color.MaxValue; if (min < 0.0f) { // Negative color case (e.g. offset) } else if (max > 1.0f) { // HDR color case color /= max; scale *= max; } _xElement.Value = color.X; _yElement.Value = color.Y; _zElement.Value = color.Z; _wElement.Value = scale; _trackball.CustomControl.Color = Vector3.Abs(color); } }
public static void PerpendicularBasis(this Vector3 vector, out Vector3 outA, out Vector3 outB) { Vector3 a = vector.Abs(); Vector3 q; if (a.x <= a.y) { if (a.x <= a.z) { q = Vector3.right; } else { q = Vector3.forward; } } else if (a.y <= a.z) { q = Vector3.up; } else { q = Vector3.forward; } outA = Vector3.Cross(vector, q).normalized; outB = Vector3.Cross(vector, outA).normalized; }
private BoundingBox CalculateBoundingBox(MyObjectBuilder_CubeGrid grid) { float cubeSize = MyDefinitionManager.Static.GetCubeSize(grid.GridSizeEnum); BoundingBox boundingBox = new BoundingBox(Vector3.MaxValue, Vector3.MinValue); try { foreach (MyObjectBuilder_CubeBlock cubeBlock in grid.CubeBlocks) { MyCubeBlockDefinition blockDefinition; if (!MyDefinitionManager.Static.TryGetCubeBlockDefinition(cubeBlock.GetId(), out blockDefinition)) { continue; } MyBlockOrientation blockOrientation = (MyBlockOrientation)cubeBlock.BlockOrientation; Vector3 vector3 = Vector3.Abs(Vector3.TransformNormal(new Vector3(blockDefinition.Size) * cubeSize, blockOrientation)); Vector3 point1 = new Vector3((Vector3I)cubeBlock.Min) * cubeSize - new Vector3(cubeSize / 2f); Vector3 point2 = point1 + vector3; boundingBox.Include(point1); boundingBox.Include(point2); } } catch (Exception e) { Core.GeneralLog.WriteToLog("CalculateBoundingBox", $"Exception:\t{e}"); return(new BoundingBox()); } return(boundingBox); }
private static Vector3 CopySign(Vector3 value, Vector3 sign) { Vector3 signs = new Vector3(MathF.Sign(sign.X), MathF.Sign(sign.Y), MathF.Sign(sign.Z)); Vector3 valueAbs = Vector3.Abs(value); return(valueAbs * signs); }
public static Vector3 RandomVector3(Vector3 minRange, Vector3 maxRange) { minRange = -minRange.Abs(); minRange = maxRange.Abs(); return(new Vector3(RandomRange(minRange.x, maxRange.x), CGRandom.RandomRange(minRange.y, maxRange.y), CGRandom.RandomRange(minRange.z, maxRange.z))); }
private int GetStepsFromOrigin() { var absValue = Vector3.Abs(_coordinates); var steps = (absValue.X + absValue.Y + absValue.Z) / 2; return(Convert.ToInt32(steps)); }
private HkdBreakableShape AddMountForShape(HkdBreakableShape shape, Matrix transform, ref BoundingBox blockBB) { Vector4 min; Vector4 max; shape.GetShape().GetLocalAABB(0.01f, out min, out max);//.Transform(CubeGrid.PositionComp.WorldMatrix); var bb = new BoundingBox(new Vector3(min), new Vector3(max)); bb = bb.Transform(transform); bb.Min /= CubeGrid.GridSize; //normalize for mount point bb.Max /= CubeGrid.GridSize; bb.Inflate(0.04f);//add tolerance (fracture shapes are smaller than block) bb.Min += blockBB.HalfExtents; bb.Max += blockBB.HalfExtents; if (blockBB.Contains(bb) == ContainmentType.Intersects) { bb.Inflate(-0.04f); foreach (var directionEnum in Base6Directions.EnumDirections) { int dirEnum = (int)directionEnum; Vector3 direction = Base6Directions.Directions[dirEnum]; Vector3 absDir = Vector3.Abs(direction); var mp = new MyCubeBlockDefinition.MountPoint(); mp.Start = bb.Min; mp.End = bb.Max; mp.Enabled = true; var start = mp.Start * absDir / (blockBB.HalfExtents * 2) - absDir * 0.04f; var end = mp.End * absDir / (blockBB.HalfExtents * 2) + absDir * 0.04f; bool add = false; bool one = false; if (start.Max() < 1 && end.Max() > 1 && direction.Max() > 0) { add = true; one = true; } else if (start.Min() < 0 && end.Max() > 0 && direction.Min() < 0) { add = true; } if (!add) { continue; } mp.Start -= mp.Start * absDir - absDir * 0.04f; mp.End -= mp.End * absDir + absDir * 0.04f; if (one) { mp.Start += absDir * blockBB.HalfExtents * 2; mp.End += absDir * blockBB.HalfExtents * 2; } mp.Start -= blockBB.HalfExtents - Vector3.One / 2; mp.End -= blockBB.HalfExtents - Vector3.One / 2; mp.Normal = new Vector3I(direction); MountPoints.Add(mp); } } return(shape); }
/// <summary> /// Returns the inputs required to rotate the car to a desired orientation. /// </summary> /// <param name="car">The car that needs to be rotated.</param> /// <param name="target">The desired rotation.</param> /// <param name="dt">The time till the next frame in seconds.</param> /// <returns>Returns a Vector3 where X is roll, Y is pitch and Z is yaw.</returns> public static Vector3 GetInputs(Car car, Quaternion target, float dt) { Quaternion relativeRotation = Quaternion.Multiply(Quaternion.Inverse(car.Rotation), target); Vector3 geodesicLocal = relativeRotation.ToRotationAxis(); // figure out the axis of minimal rotation to target Vector3 geodesicWorld = Vector3.Transform(geodesicLocal, car.Rotation); // get the angular acceleration Vector3 alpha = new Vector3(Controller(geodesicWorld.X, car.AngularVelocity.X, dt), Controller(geodesicWorld.Y, car.AngularVelocity.Y, dt), Controller(geodesicWorld.Z, car.AngularVelocity.Z, dt)); // reduce the corrections for when the solution is nearly converged Vector3 error = Vector3.Abs(geodesicWorld) + Vector3.Abs(car.AngularVelocity); alpha = q(error) * alpha; // set the desired next angular velocity Vector3 omega_next = car.AngularVelocity + alpha * dt; // determine the controls that produce that angular velocity Vector3 rollPitchYaw = AerialRollPitchYaw(car.AngularVelocity, omega_next, car.Rotation, dt); return(rollPitchYaw); }
public static float CosAngleBetween(this Vector3 start, Vector3 to) { float num1 = Vector3.Dot(start, to); float num2 = start.Abs() * to.Abs(); return(num1 / num2); }
public void Render(ITransformation camera) { #if SOLUTION for (int i = 0; i < instanceCount; ++i) { instancePositions[i] += instanceVelocity[i]; var abs = Vector3.One - Vector3.Abs(instancePositions[i]); if (abs.X < 0 || abs.Y < 0 || abs.Z < 0) { instanceVelocity[i] = -instanceVelocity[i]; } instanceRotation[i] += 0.1f; } geometry.SetAttribute(shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, "instancePosition"), instancePositions, true); geometry.SetAttribute(shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, "instanceRotation"), instanceRotation, true); #endif GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shaderProgram.Activate(); #if SOLUTION shaderProgram.Uniform("camera", camera); #endif geometry.Draw(); shaderProgram.Deactivate(); }
public static void PointOutsideBox(ref Vector3 position, Vector3 boxSize) { Vector3 distanceToCenter = position.Abs(); if (distanceToCenter.x < boxSize.x && distanceToCenter.y < boxSize.y && distanceToCenter.z < boxSize.z) { Vector3 distance = (distanceToCenter - boxSize).Abs(); if (distance.x < distance.y) { if (distance.x < distance.z) { position.x = Mathf.Sign(position.x) * boxSize.x; } else { position.z = Mathf.Sign(position.z) * boxSize.z; } } else { if (distance.y < distance.z) { position.y = Mathf.Sign(position.y) * boxSize.y; } else { position.z = Mathf.Sign(position.z) * boxSize.z; } } } }
public static void CalculateTexcoordForFace(ref Vector3 localPos, int face, out Vector2 texCoord) { Vector3 abs = Vector3.Abs(localPos); switch (face) { case (int)Faces.XPositive: localPos /= abs.X; texCoord.Y = -localPos.Y; texCoord.X = -localPos.Z; break; case (int)Faces.XNegative: localPos /= abs.X; texCoord.Y = -localPos.Y; texCoord.X = localPos.Z; break; case (int)Faces.YPositive: localPos /= abs.Y; texCoord.Y = -localPos.Z; texCoord.X = -localPos.X; break; case (int)Faces.YNegative: localPos /= abs.Y; texCoord.Y = -localPos.Z; texCoord.X = localPos.X; break; case (int)Faces.ZPositive: localPos /= abs.Z; texCoord.Y = -localPos.Y; texCoord.X = localPos.X; break; case (int)Faces.ZNegative: localPos /= abs.Z; texCoord.Y = -localPos.Y; texCoord.X = -localPos.X; break; default: Debug.Fail("Bad face number!!!!!"); texCoord = Vector2.Zero; break; } texCoord = ((texCoord + 1f) * .5f); if (texCoord.X == 1) { texCoord.X = 0.999999f; } if (texCoord.Y == 1) { texCoord.Y = 0.999999f; } }
public void GetBoxFromMatrix(MatrixD m, out Vector3 halfExtents, out Vector3D position, out Quaternion orientation) { var world = MatrixD.Normalize(m) * this.WorldMatrix; orientation = Quaternion.CreateFromRotationMatrix(world); halfExtents = Vector3.Abs(m.Scale) / 2; position = world.Translation; }
public static void CalcRightTexcoord(ref Vector3 localPos, out Vector2 texCoord) { Vector3 vector = Vector3.Abs(localPos); texCoord.Y = -localPos.Y / vector.X; texCoord.X = localPos.Z / vector.X; texCoord = (texCoord + 1f) * 0.5f; }
public static float AngleBetween(this Vector3 start, Vector3 to, bool returndegree = true) { float num1 = Vector3.Dot(start, to); float num2 = start.Abs() * to.Abs(); var num3 = num1 / num2; return(returndegree ? (float)(Math.Acos(num3) / Math.PI * 180) : (float)Math.Acos(num3)); }
public static void CalcFrontTexcoord(ref Vector3 localPos, out Vector2 texCoord) { Vector3 vector = Vector3.Abs(localPos); texCoord.Y = -localPos.Y / vector.Z; texCoord.X = -localPos.X / vector.Z; texCoord = (texCoord + 1f) * 0.5f; }
private static bool AreNearlyEqual(Vector3 a, Vector3 b) { Vector3 delta = Vector3.Abs(a - b); return(delta.X < Epsilon && delta.Y < Epsilon && delta.Z < Epsilon); }
/// <inheritdoc/> public bool AlmostEquals(Hsl other, float precision) { Vector3 result = Vector3.Abs(this.backingVector - other.backingVector); return(result.X < precision && result.Y < precision && result.Z < precision); }
public static Func <Vector3, float> Box(Vector3 b) { return(p => { Vector3 d = Vector3.Abs(p) - b; return Vector3.Max(d, Vector3.Zero).Length() + (float)Math.Min(Math.Max(d.X, Math.Max(d.Y, d.Z)), 0.0); }); }
public override bool CanDrag(MapViewport viewport, OrthographicCamera camera, ViewportEvent e, Vector3 position) { var width = Width; var screenPosition = camera.WorldToScreen(Position); var diff = Vector3.Abs(e.Location - screenPosition); return(diff.X < width && diff.Y < width); }
/// <summary> /// Returns whether the given world-space point projects inside this Rect. Optionally /// also outputs the calculated rect-space point to point_rect. /// </summary> public bool ContainsProjectedPoint(Vector3 point, out Vector3 point_rect) { point_rect = this.matrix.inverse.MultiplyPoint3x4(point); var absPoint_rect = point_rect.Abs(); return(absPoint_rect.x <= radii.x && absPoint_rect.y <= radii.y); }
private void GetBoxFromMatrix(Matrix m, out Vector3 halfExtents, out Vector3 position, out Quaternion orientation) { MatrixD matrix = Matrix.Normalize(m) * base.WorldMatrix; orientation = Quaternion.CreateFromRotationMatrix(matrix); halfExtents = Vector3.Abs(m.Scale) / 2f; halfExtents = new Vector3(halfExtents.X, halfExtents.Y, halfExtents.Z); position = (Vector3)matrix.Translation; }
private void GetBoxFromMatrix(Matrix m, out Vector3 halfExtents, out Vector3 position, out Quaternion orientation) { var world = Matrix.Normalize(m) * this.WorldMatrix; orientation = Quaternion.CreateFromRotationMatrix(world); halfExtents = Vector3.Abs(m.Scale) / 2; halfExtents = new Vector3(halfExtents.X, halfExtents.Y, halfExtents.Z); position = world.Translation; }
public override bool CanDrag(MapViewport viewport, OrthographicCamera camera, ViewportEvent e, Vector3 position) { const int width = 8; var pos = GetWorldPositionAndScreenOffset(viewport.Viewport.Camera); var screenPosition = camera.WorldToScreen(pos.Item1) + pos.Item2; var diff = Vector3.Abs(e.Location - screenPosition); return(diff.X < width && diff.Y < width); }
public static float sdHexPrism(Vector3 p, Vector2 h) { Vector3 q = p.Abs(); return Math.Max(q.Z - h.Y, Math.Max((q.X * 0.866025f + q.Y * 0.5f), q.Y) - h.X); }