/// 三角形と点との内外判定 static private bool checkInsideTriangle(GeometryTriangle trgTri, Vector3 crossPos) { int type; float d1, d2, d3; if (FMath.Abs(trgTri.Plane.Nor.X) < FMath.Abs(trgTri.Plane.Nor.Y)) { type = (FMath.Abs(trgTri.Plane.Nor.Y) < FMath.Abs(trgTri.Plane.Nor.Z)) ? 3 : 2; } else { type = (FMath.Abs(trgTri.Plane.Nor.X) < FMath.Abs(trgTri.Plane.Nor.Z)) ? 3 : 1; } switch (type) { /// X方向に面が傾いているためX軸を破棄 case 1: d1 = ((crossPos.Y - trgTri.Pos1.Y) * (crossPos.Z - trgTri.Pos2.Z)) - ((crossPos.Z - trgTri.Pos1.Z) * (crossPos.Y - trgTri.Pos2.Y)); d2 = ((crossPos.Y - trgTri.Pos2.Y) * (crossPos.Z - trgTri.Pos3.Z)) - ((crossPos.Z - trgTri.Pos2.Z) * (crossPos.Y - trgTri.Pos3.Y)); d3 = ((crossPos.Y - trgTri.Pos3.Y) * (crossPos.Z - trgTri.Pos1.Z)) - ((crossPos.Z - trgTri.Pos3.Z) * (crossPos.Y - trgTri.Pos1.Y)); break; /// y方向に面が傾いているためY軸を破棄 case 2: d1 = ((crossPos.X - trgTri.Pos1.X) * (crossPos.Z - trgTri.Pos2.Z)) - ((crossPos.Z - trgTri.Pos1.Z) * (crossPos.X - trgTri.Pos2.X)); d2 = ((crossPos.X - trgTri.Pos2.X) * (crossPos.Z - trgTri.Pos3.Z)) - ((crossPos.Z - trgTri.Pos2.Z) * (crossPos.X - trgTri.Pos3.X)); d3 = ((crossPos.X - trgTri.Pos3.X) * (crossPos.Z - trgTri.Pos1.Z)) - ((crossPos.Z - trgTri.Pos3.Z) * (crossPos.X - trgTri.Pos1.X)); break; /// Z方向に面が傾いているためZ軸を破棄 case 3: d1 = ((crossPos.X - trgTri.Pos1.X) * (crossPos.Y - trgTri.Pos2.Y)) - ((crossPos.Y - trgTri.Pos1.Y) * (crossPos.X - trgTri.Pos2.X)); d2 = ((crossPos.X - trgTri.Pos2.X) * (crossPos.Y - trgTri.Pos3.Y)) - ((crossPos.Y - trgTri.Pos2.Y) * (crossPos.X - trgTri.Pos3.X)); d3 = ((crossPos.X - trgTri.Pos3.X) * (crossPos.Y - trgTri.Pos1.Y)) - ((crossPos.Y - trgTri.Pos3.Y) * (crossPos.X - trgTri.Pos1.X)); break; default: return(true); } /// 全て符号が同じなら当り。 if ((d1 >= -epsilon && d2 >= -epsilon && d3 >= -epsilon) || (d1 <= epsilon && d2 <= epsilon && d3 <= epsilon)) { return(true); } return(false); }
public void adjustPositions() { for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++) { float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing) - levelSelection * (thumbnailSize + thumbnailSpacing); MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction( new MoveTo( new Vector2( newX, MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y), transitionDuration)); float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize); MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction( new ScaleTo(new Vector2(scaleFactor, scaleFactor), 0.5f)); //adjust labels float labelScaleFactor = FMath.Clamp(1.0f - FMath.Abs((960.0f / 2.0f) - newX) / 1000.0f, 0.0f, 1.0f); labels [i].RunAction( new MoveTo( new Vector2( newX, MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y - thumbnailSize * 0.65f * labelScaleFactor), transitionDuration)); labels [i].RunAction(new ScaleTo(new Vector2(labelScaleFactor, labelScaleFactor), 0.5f)); } }
public bool SE_CheckForPinHasFallen() { //GetOwner().PrintString("SE_CheckForPinHasFallen", FLinearColor.Green, printToLog: true); FVector _rotationInEuler = MyOwner.GetActorRotation().Euler(); float _tiltInX = FMath.Abs(_rotationInEuler.X); float _tiltInY = FMath.Abs(_rotationInEuler.Y); bool _previouslyFallen = bPinHasFallen; bPinHasFallen = _tiltInX > standingThreshold || _tiltInY > standingThreshold; if (bDebugInstantStrike) { bPinHasFallen = true; } if (bPinHasFallen && _previouslyFallen != bPinHasFallen) { gamemaster.CallOnPinHasFallen(this); } else if (bPinHasFallen == false && _previouslyFallen != bPinHasFallen && bDebugInstantStrike == false) { //If Pin Has Gotten Back Up Because //Pin Has Fallen, But Now PinHasFallen Equals False //MyOwner.PrintString("Pin has gotten back up", FLinearColor.Green, printToLog: true); gamemaster.CallOnPinHasGottenBackUp(this); } return(bPinHasFallen); }
public bool IsOrthonormal(float epsilon) { Matrix3.coord_sys_error = 0u; bool result; if (this.Z.Z != 1f || this.X.Z != 0f || this.Y.Z != 0f) { Matrix3.coord_sys_error |= Matrix3.LastRowNot001; result = false; } else if (FMath.Abs(this.X.Length() - 1f) >= epsilon) { Matrix3.coord_sys_error |= Matrix3.XNotUnitLen; result = false; } else if (FMath.Abs(this.Y.Length() - 1f) >= epsilon) { Matrix3.coord_sys_error |= Matrix3.YNotUnitLen; result = false; } else if (FMath.Abs(this.X.Dot(this.Y)) >= epsilon) { Matrix3.coord_sys_error |= Matrix3.XYNotPerpendicular; result = false; } else { result = true; } return(result); }
private float age_to_alpha(float x, float dx) { x = FMath.Abs(x - 0.5f); float num = 0.5f - dx; return(1f - FMath.Max(0f, (x - num) * (1f / dx))); }
public static Vector2 FromVector(Vector3 v) { float num = -Math.Angle(v.Zy); v = v.RotateX(-num); Common.Assert(FMath.Abs(v.Y) < 0.001f); float num2 = Math.Angle(v.Zx); return(new Vector2(num, num2)); }
private float zoom_curve(float x, float a, float right_scale) { float num = 1f; if (x > 0f) { num = right_scale; } float num2 = Math.Sign(x); return(1f + num * num2 * (1f - FMath.Exp(-a * FMath.Abs(x / num)))); }
public void CheckMultiplyWithScalar <V> () where V : struct, IVec <V, float> { (from vec in Prop.ForAll <V> () from scalar in Prop.ForAll <float> () let len = vec.Length let scaled = vec.Multiply(scalar) let len_scaled = scaled.Length let scalar_x_len = FMath.Abs(scalar * len) select new { vec, scalar, len, scaled, len_scaled, scalar_x_len }) .Check(p => p.len_scaled.ApproxEquals(p.scalar_x_len), label: $"{typeof (V).Name}: | vec * scalar | = scalar * | vec |"); }
public void initLevelSelect() { this.levelSelection = 0; this.Camera2D.SetViewFromViewport(); //labels labels = new List <Support.CustomLabel> (); //mini background discofloor var tex = new Texture2D("/Application/data/tiles/simple5.png", false); var texture = new TextureInfo(tex, new Vector2i(1, 13)); var menuBackground = new SpriteList(texture); for (int x = 0; x < 30; x++) { for (int y = 0; y < 17; y++) { SpriteTile bgTile = new SpriteTile(texture); bgTile.TileIndex1D = Support.random.Next(4, 13); bgTile.Position = new Vector2((float)x * 32.0f, (float)y * 32.0f); bgTile.Scale = bgTile.TextureInfo.TileSizeInPixelsf * 2.0f; bgTile.ScheduleInterval((dt) => { bgTile.TileIndex1D = Support.random.Next(4, 13); }, 0.2f, -1); menuBackground.AddChild(bgTile); } } Background.AddChild(menuBackground); for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++) { //add thumbnail float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing); float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize); MapManager.Instance.predefinedMaps [i].thumbnailSprite.Scale = new Vector2(scaleFactor, scaleFactor); MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position = new Vector2(newX, 544.0f / 2.0f); Foreground.AddChild(MapManager.Instance.predefinedMaps [i].thumbnailSprite); //add label: var tempLabel = new Support.CustomLabel(new Vector2(newX, 544.0f / 2.0f - thumbnailSize * 0.6f), "Level " + (i + 1) + "\nHighscore: 0", SceneManager.UIFontMap); labels.Add(tempLabel); Foreground.AddChild(tempLabel); } }
public void CheckMultiplyWithScalar <V> () where V : struct, IVec <V, float> { var prop = from vec in Prop.Choose <V> () from scalar in Prop.Choose <float> () let len = vec.Length let scaled = vec.Multiply(scalar) let len_scaled = scaled.Length let scalar_x_len = FMath.Abs(scalar * len) select new { vec, scalar, len, scaled, len_scaled, scalar_x_len }; prop.Label("{0}: | vec * scalar | = scalar * | vec |", typeof(V).Name) .Check(p => p.len_scaled.ApproxEquals(p.scalar_x_len)); }
private void ScrollOffset(float offsetY) { this.scrollPosition -= offsetY; if (0f < this.scrollPosition && this.scrollPosition < this.MaxScrollPosition) { using (List <LiveListPanel.ListItemData> .Enumerator enumerator = this.usingItemDataList.GetEnumerator()) { while (enumerator.MoveNext()) { LiveListPanel.ListItemData current = enumerator.Current; current.totalScrollIncrement += FMath.Abs(offsetY); } } } }
static Fixed Atan1(Fixed d) { // https://en.wikipedia.org/wiki/Inverse_trigonometric_functions // Make sure |d| <= 1 bool inversed; if (FMath.Abs(d) > Fixed.One) { d = Fixed.One / d; inversed = true; } else { inversed = false; } var v = d.RawValue; var square = (v * v) >> Fixed.SHIFT_BITS; var r = v; var n = 3L; for (int i = 0; i < 15; i++) { v = (v * square) >> Fixed.SHIFT_BITS; r -= v / n; n += 2; v = (v * square) >> Fixed.SHIFT_BITS; r += v / n; n += 2; } if (inversed) { if (r > 0) { r = FMath.PI.RawValue / 2 - r; } else { r = -FMath.PI.RawValue / 2 - r; } } return(new Fixed(r)); }
/// Camera control static void ctrlCamera() { foreach (var touchData in Touch.GetData(0)) { if (idTouch == -1) { if (touchData.Status == TouchStatus.Down) { idTouch = touchData.ID; float pointX = (touchData.X + 0.5f) * DspWidth; float pointY = (touchData.Y + 0.5f) * DspHeight; ptPrev.X = pointX; ptPrev.Y = pointY; isMove = false; } } else if (idTouch == touchData.ID) { if (touchData.Status == TouchStatus.Up) { idTouch = -1; if (isMove == false) { callNextScene(1); } } else if (touchData.Status == TouchStatus.Move) { float pointX = (touchData.X + 0.5f) * DspWidth; float pointY = (touchData.Y + 0.5f) * DspHeight; Vector2 ptNow = new Vector2(pointX, pointY); float dx = (ptPrev.X - ptNow.X) / (float)DspWidth; float dy = (ptPrev.Y - ptNow.Y) / (float)DspHeight; // input on X axis become the amount of rotation around Y axis if (FMath.Abs(dx) >= (1.0 / (float)DspWidth) || FMath.Abs(dy) >= (1.0 / (float)DspHeight)) { isMove = true; camera.OnRotate(((float)FMath.PI * 2.0f) * dy, ((float)FMath.PI * 2.0f) * dx); ptPrev = ptNow; } } } } }
void PlayPinStrikeSounds(AActor _other) { int _settledPins = gamemode.lastSettledCount; float _center = 50f; float _otherYLoc = _other.GetActorLocation().Y; float _offset = _otherYLoc >= 0 ? FMath.Abs(_otherYLoc - _center) : FMath.Abs(_otherYLoc + _center); float _highoffset = 350f; float _offsetAsPercentageDecimal = (_offset / _highoffset); float _highVelX = 2500f; float _lowVelX = 1000f; float _velX = FMath.Clamp(_other.GetVelocity().X, _lowVelX, _highVelX); float _velXAsPercentageDecimal = ((_velX - _lowVelX) / (_highVelX - _lowVelX)); //The Less Pins, The Higher The Percentage float _pinSettledPenaltyAsPercentage = 1 - (_settledPins / 10); float _VelXMinusOffsetYDecimal = _velXAsPercentageDecimal - (_offsetAsPercentageDecimal * offsetAsPercentageMultplier) - _pinSettledPenaltyAsPercentage; if (_offsetAsPercentageDecimal > 0.80f) { _VelXMinusOffsetYDecimal = FMath.Min(-0.5f, _VelXMinusOffsetYDecimal - 0.5f); } //MyOwner.PrintString($"Pin Strike. Vel: {_velX} VelAsPerc: {_velXAsPercentageDecimal} Off: {_offset} OffAsPerc: {_offsetAsPercentageDecimal} VelMinusOffset: {_VelXMinusOffsetYDecimal}", FLinearColor.Green, printToLog: true); Random _ran = new Random(); if (_VelXMinusOffsetYDecimal <= -0.5) { MyAudioSourceComponent.Sound = _ran.Next(0, 2) == 0 ? PinStrikeSoundVolume1 : PinStrikeSoundVolume2; } else if (_VelXMinusOffsetYDecimal <= 0.2) { MyAudioSourceComponent.Sound = _ran.Next(0, 2) == 0 ? PinStrikeSoundVolume3 : PinStrikeSoundVolume4; } else { MyAudioSourceComponent.Sound = PinStrikeSoundVolume5; } MyAudioSourceComponent.Play(); }
/// private メンバ ///--------------------------------------------------------------------------- /// レイと球との交差を求める /** * 返り値:交点との距離を返す */ static private float checkRayCrossSphere(Vector3 trgRayPos, Vector3 trgRayVec, GeometrySphere trgSph) { float a, b, c, d; float t; Vector3 q; q = trgRayPos - trgSph.Pos; // 球の式にレイを代入。 // x^2 + y^2 + z^2 = r^2 a = ((trgRayVec.X * trgRayVec.X) + (trgRayVec.Y * trgRayVec.Y) + (trgRayVec.Z * trgRayVec.Z)); b = 2 * ((q.X * trgRayVec.X) + (q.Y * trgRayVec.Y) + (q.Z * trgRayVec.Z)); c = ((q.X * q.X) + (q.Y * q.Y) + (q.Z * q.Z)) - (trgSph.R * trgSph.R); // 判別式。 // D = b^2 -4ac; d = (b * b) + (-4 * (a * c)); // d < 0 ならば、交差はない。 // d = 0 ならば、球に接する。 // d > 0 ならば、2つの異なる点が存在する。 if (d < 0.0f || a <= 0.0f) { return(-1.0f); } // -b -sqrt (d) // t = -------------- // 2a t = (-b - FMath.Sqrt(d)) / (a * 2); return(FMath.Abs(t)); }
public static Matrix4 LookAt(Vector3 eye, Vector3 center, Vector3 _Up) { Vector3 vector = _Up.Normalize(); Common.Assert(vector.IsUnit(0.001f)); float num = 1E-05f; Vector3 vector2; Vector3 vector3; Vector3 vector4; if ((eye - center).Length() > num) { vector2 = (eye - center).Normalize(); if (FMath.Abs(vector2.Dot(vector)) > 0.9999f) { vector3 = vector2.Perpendicular(); vector4 = vector3.Cross(vector2); } else { vector4 = vector.Cross(vector2).Normalize(); vector3 = vector2.Cross(vector4); } } else { vector3 = vector; vector4 = vector3.Perpendicular(); vector2 = vector4.Cross(vector3); } Matrix4 matrix = default(Matrix4); matrix.ColumnX = vector4.Xyz0; matrix.ColumnY = vector3.Xyz0; matrix.ColumnZ = vector2.Xyz0; matrix.ColumnW = eye.Xyz1; Matrix4 result = matrix; Common.Assert(result.IsOrthonormal(0.001f)); return(result); }
protected internal override GestureDetectorResponse OnTouchEvent(TouchEventCollection touchEvents) { GestureDetectorResponse result = base.State; TouchEventCollection touchEventCollection = new TouchEventCollection(); foreach (TouchEvent touchEvent in touchEvents) { if (touchEvent.Type != TouchEventType.Enter && touchEvent.Type != TouchEventType.Leave && touchEvent.Type != TouchEventType.None) { touchEventCollection.Add(touchEvent); } } if (touchEventCollection.Count >= 2) { bool flag = false; Vector2[] array = new Vector2[2]; Vector2[] array2 = new Vector2[2]; for (int i = 0; i < 2; i++) { TouchEvent touchEvent2 = touchEventCollection[i]; array[i] = touchEvent2.LocalPosition; array2[i] = touchEvent2.WorldPosition; if (touchEvent2.Type == TouchEventType.Up) { flag = true; } } float num = array[0].Distance(array[1]); if (this.firstDistance < 0f) { this.firstDistance = num; this.firstTouchVector = array[1] - array[0]; } if (base.State == GestureDetectorResponse.UndetectedAndContinue || base.State == GestureDetectorResponse.None) { if (FMath.Abs(num - this.firstDistance) > this.MinPinchDistance) { Vector2 localCenter = (array[0] + array[1]) / 2f; Vector2 worldCenter = (array2[0] + array2[1]) / 2f; if (this.PinchStartDetected != null) { this.PinchStartDetected.Invoke(this, new PinchEventArgs(base.TargetWidget, num, 1f, 0f, worldCenter, localCenter)); } result = GestureDetectorResponse.DetectedAndContinue; } else { result = GestureDetectorResponse.UndetectedAndContinue; } } else if (base.State == GestureDetectorResponse.DetectedAndContinue) { Vector2 vector = array[1] - array[0]; float scale = num / this.firstDistance; float angle = this.firstTouchVector.Angle(vector); Vector2 localCenter2 = (array[0] + array[1]) / 2f; Vector2 worldCenter2 = (array2[0] + array2[1]) / 2f; if (flag) { if (this.PinchEndDetected != null) { this.PinchEndDetected.Invoke(this, new PinchEventArgs(base.TargetWidget, num, scale, angle, worldCenter2, localCenter2)); } result = GestureDetectorResponse.DetectedAndStop; this.firstDistance = -1f; this.firstTouchVector = Vector2.Zero; } else { if (this.PinchDetected != null) { this.PinchDetected.Invoke(this, new PinchEventArgs(base.TargetWidget, num, scale, angle, worldCenter2, localCenter2)); } result = GestureDetectorResponse.DetectedAndContinue; } } } else if (base.State == GestureDetectorResponse.DetectedAndContinue) { result = GestureDetectorResponse.FailedAndStop; } else { result = GestureDetectorResponse.UndetectedAndContinue; } return(result); }
public override void Tick(float dt) { base.Tick(dt); if (Input2.GamePad0.Up.Press) { menuSelection = (menuSelection + 1) % 2; } if (Input2.GamePad0.Down.Press) { menuSelection = (int)FMath.Abs((menuSelection - 1) % 2); } if (Input2.GamePad0.Cross.Press) { switch (menuSelection) { case 0: SceneManager.Instance.popScene(); break; case 1: SceneManager.Instance.popScene(); Game.Instance.paused = false; Game.Instance.OnExit(); SceneManager.Instance.changeSceneTo(MainMenu.Instance); break; } } if (Input2.Touch00.Down && sprite_button_returntogame.IsWorldPointInsideContentLocalBounds(GetTouchPos())) { menuSelection = 0; } else if (Input2.Touch00.Down && sprite_button_returntomenu.IsWorldPointInsideContentLocalBounds(GetTouchPos())) { menuSelection = 1; } switch (menuSelection) { case 0: sprite_button_returntogame.Scale = sprite_button_returntogame.TextureInfo.TextureSizef * 1.7f; sprite_button_returntogame.Color = new Vector4(1.0f, 1.0f, 0.0f, 1.0f); sprite_button_returntomenu.Scale = sprite_button_returntomenu.TextureInfo.TextureSizef * 1.5f; sprite_button_returntomenu.Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); break; case 1: sprite_button_returntogame.Scale = sprite_button_returntogame.TextureInfo.TextureSizef * 1.5f; sprite_button_returntogame.Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); sprite_button_returntomenu.Scale = sprite_button_returntomenu.TextureInfo.TextureSizef * 1.7f; sprite_button_returntomenu.Color = new Vector4(1.0f, 1.0f, 0.0f, 1.0f); break; } if (Input2.Touch00.Release && sprite_button_returntogame.IsWorldPointInsideContentLocalBounds(GetTouchPos())) { SceneManager.Instance.popScene(); } else if (Input2.Touch00.Release && sprite_button_returntomenu.IsWorldPointInsideContentLocalBounds(GetTouchPos())) { Game.Instance.paused = false; Game.Instance.OnExit(); SceneManager.Instance.changeSceneTo(MainMenu.Instance); } }
public static float SafeAcos(float x) { Common.Assert(FMath.Abs(x) - 1f < 1E-05f); return(FMath.Acos(FMath.Clamp(x, -1f, 1f))); }
private float GetItemPosYWithSpring(LiveListPanel.ListItemData data, float scrollPos, float elapsedTime) { ListPanelItem item = data.item; float num = 0f; if (this.scrollDirection == FourWayDirection.Up) { if (item.Index <= this.ScrollAreaFirstItemIndex) { num = item.Y - ((float)item.Index * this.LineHeight + this.LineHeight / 2f - scrollPos); } else { ListPanelItem item2 = this.GetItem(item.Index - 1); if (item2 != null) { num = item.Y - (item2.Y + this.LineHeight); } } } else if (this.scrollDirection == FourWayDirection.Down) { if (item.Index >= this.ScrollAreaLastItemIndex) { num = item.Y - ((float)item.Index * this.LineHeight + this.LineHeight / 2f - scrollPos); } else { ListPanelItem item3 = this.GetItem(item.Index + 1); if (item3 != null) { num = item.Y - (item3.Y - this.LineHeight); } } } float num2; if (this.animationState == LiveListPanel.AnimationState.Drag) { num2 = this.scrollGravity + 0.01f * (FMath.Abs((float)(this.scrollBaseIndex - item.Index)) - 1f); } else if (this.animationState == LiveListPanel.AnimationState.Flick) { num2 = this.scrollGravity + 0.05f * FMath.Abs((float)(this.scrollBaseIndex - item.Index)); } else { num2 = this.scrollGravity + 0.05f * FMath.Abs((float)(this.scrollBaseIndex - item.Index)); } float num3 = elapsedTime / 16.6f; num2 = FMath.Clamp(num2, -1f, 1f); float num4 = num * num2 * num3; if (num < 0f) { num4 = FMath.Clamp(num4, num, 0f); } else { num4 = FMath.Clamp(num4, 0f, num); } data.IsScrolling = (FMath.Abs(num) > 1f); return(item.Y - num4); }
/** * Checks whether two planes are equal within specified tolerance. * * @param V The other plane. * @param Tolerance Error Tolerance. * @return true if the two planes are equal within specified tolerance, otherwise false. */ public bool Equals(FPlane V, float Tolerance = Const.KINDA_SMALL_NUMBER) { return(FMath.Abs(X - V.X) < Tolerance && FMath.Abs(Y - V.Y) < Tolerance && FMath.Abs(Z - V.Z) < Tolerance && FMath.Abs(W - V.W) < Tolerance); }
public void CheckMultiplyWithVector <V> () where V : struct, IVec <V, float> { (from vec in Prop.ForAll <V> () from scalar in Prop.ForAll <float> () let len = vec.Length let scaleVec = Vec.FromArray <V, float> (scalar.Duplicate(vec.Dimensions)) let scaled = vec.Multiply(scaleVec) let len_scaled = scaled.Length let scalar_x_len = FMath.Abs(scaleVec[0] * len) select new { vec, scaleVec, len, scaled, len_scaled, scalar_x_len }) .Check(p => p.len_scaled.ApproxEquals(p.scalar_x_len), label: $"{typeof (V).Name}: | vec * scale | = scale.x * | vec | when scale is uniform"); }
private float CalculateExternalAcceleration(LiveSpringPanel.WidgetInfo info, SpringType type) { float acceleration = 0f; switch (type) { case SpringType.AngleAxisX: case SpringType.PositionY: acceleration = this.sensorAcceleration.Y + this.moveAcceleration.Y + this.userAcceleration.Y; break; case SpringType.AngleAxisY: acceleration = -(this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X); break; case SpringType.AngleAxisZ: { bool flag = false; bool[] useSpecifiedValues = info.useSpecifiedValues; for (int i = 0; i < useSpecifiedValues.Length; i++) { bool flag2 = useSpecifiedValues[i]; flag |= flag2; } if (!flag) { float num = info.displacements[3]; float num2 = info.displacements[4]; float num3 = FMath.Abs(num); float num4 = FMath.Abs(num2); bool flag3; if (num * num2 > 0f) { flag3 = (num3 > num4); } else { flag3 = (num3 < num4); } float num5 = FMath.Min(FMath.Abs(num3 - num4), FMath.Min(num3, num4)) / 200f; float num6 = flag3 ? num5 : (-num5); float num7 = info.displacements[0]; float num8 = info.displacements[1]; float num9 = FMath.Abs(num7); float num10 = FMath.Abs(num8); if (-num7 * num8 > 0f) { flag3 = (num9 < num10); } else { flag3 = (num9 > num10); } num5 = FMath.Min(FMath.Abs(num9 - num10), FMath.Min(num9, num10)) / 20f; float num11 = flag3 ? num5 : (-num5); acceleration = num6 + num11; } break; } case SpringType.PositionX: acceleration = this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X; break; case SpringType.PositionZ: acceleration = this.sensorAcceleration.Z + this.moveAcceleration.Z + this.userAcceleration.Z; break; } if (type == SpringType.PositionX || type == SpringType.PositionY || type == SpringType.PositionZ) { return(this.ClipAcceleration(acceleration)); } return(this.ClipAcceleration(acceleration) * 0.0125663709f); }
public void CheckMultiplyWithVector <V> () where V : struct, IVec <V, float> { var prop = from vec in Prop.Choose <V> () from scalar in Prop.Choose <float> () let len = vec.Length let scaleVec = Vec.FromArray <V, float> (scalar.Duplicate(vec.Dimensions)) let scaled = vec.Multiply(scaleVec) let len_scaled = scaled.Length let scalar_x_len = FMath.Abs(scaleVec[0] * len) select new { vec, scaleVec, len, scaled, len_scaled, scalar_x_len }; prop.Label("{0}: | vec * scale | = scale.x * | vec | when scale.xyzw are equal", typeof(V).Name) .Check(p => p.len_scaled.ApproxEquals(p.scalar_x_len)); }
public override void Tick(float dt) { base.Tick(dt); if (Input2.GamePad0.Left.Press) { if (levelSelection > 0) { levelSelection -= 1; adjustPositions(); } } if (Input2.GamePad0.Right.Press) { if (levelSelection + 1 < MapManager.Instance.predefinedMaps.Count) { levelSelection += 1; adjustPositions(); } } if (Input2.GamePad0.Circle.Press) { SceneManager.Instance.changeSceneTo(MainMenu.Instance); } if (Input2.GamePad0.Cross.Press) { MapManager.Instance.currentMap = MapManager.Instance.predefinedMaps [levelSelection]; SceneManager.Instance.changeSceneTo(Game.Instance); } if (Input2.Touch00.Down) { if (Input2.Touch00.Press) { originalTouch = GetTouchPos(); } for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++) { float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing) - levelSelection * (thumbnailSize + thumbnailSpacing) - (originalTouch.X - GetTouchPos().X) * 2.0f; MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction( new MoveTo( new Vector2( newX, MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y), transitionDuration)); float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize); MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction( new ScaleTo(new Vector2(scaleFactor, scaleFactor), 0.5f)); //adjust labels float labelScaleFactor = FMath.Clamp(1.0f - FMath.Abs((960.0f / 2.0f) - newX) / 1000.0f, 0.0f, 1.0f); labels [i].RunAction( new MoveTo( new Vector2( newX, MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y - thumbnailSize * 0.65f * labelScaleFactor), transitionDuration)); labels [i].RunAction(new ScaleTo(new Vector2(labelScaleFactor, labelScaleFactor), 0.5f)); } } if (Input2.Touch00.Release) { levelSelection += (int)((originalTouch.X - GetTouchPos().X) * 2.0f / (thumbnailSize * 0.75f)); levelSelection = (int)FMath.Clamp(levelSelection, 0, MapManager.Instance.predefinedMaps.Count - 1); adjustPositions(); } }