public WorldSizeRelativeValue(string expression) { expression = expression.ToLower().Trim(); this.expression = expression; if (expression.IndexOf('*') <= 0) { if (Char.IsDigit(expression[0]) == true) { relativeTo = RelativeTo.Nothing; value = float.Parse(expression, System.Globalization.CultureInfo.InvariantCulture); } else { relativeTo = (RelativeTo)System.Enum.Parse(typeof(RelativeTo), expression, true); value = 1.0f; } } else { string[] strs = expression.Split('*'); if (strs.Length != 2) throw new Exception("Invalid relative value string: " + expression); relativeTo = (RelativeTo)System.Enum.Parse(typeof(RelativeTo), strs[0], true); value = float.Parse(strs[1].Trim(), System.Globalization.CultureInfo.InvariantCulture); } }
void Awake() { if (m_awake) { return; } m_awake = true; IUseCamera uc = (IUseCamera)GetComponent("IUseCamera"); if (uc != null) { renderCamera = uc.RenderCamera; } if (renderCamera == null) { renderCamera = Camera.main; } if (relativeTo == null) { relativeTo = new RelativeTo(this); } else if (relativeTo.Script != this) { // This appears to be a duplicate object, // so create our own copy of the relativeTo: RelativeTo newRT = new RelativeTo(this, relativeTo); relativeTo = newRT; } }
public WorldSizeRelativeValue(string expression) { expression = expression.ToLower().Trim(); this.expression = expression; if (expression.IndexOf('*') <= 0) { if (Char.IsDigit(expression[0]) == true) { relativeTo = RelativeTo.Nothing; value = float.Parse(expression, System.Globalization.CultureInfo.InvariantCulture); } else { relativeTo = (RelativeTo)System.Enum.Parse(typeof(RelativeTo), expression, true); value = 1.0f; } } else { string[] strs = expression.Split('*'); if (strs.Length != 2) { throw new Exception("Invalid relative value string: " + expression); } relativeTo = (RelativeTo)System.Enum.Parse(typeof(RelativeTo), strs[0], true); value = float.Parse(strs[1].Trim(), System.Globalization.CultureInfo.InvariantCulture); } }
/// <summary> /// Collects samples for angular velocity. /// </summary> /// <param name="factor">The multiplier to apply to the transform difference.</param> protected virtual void EstimateAngularVelocity(float factor) { if (angularVelocitySamples.Length == 0) { return; } Quaternion currentRelativeRotation = RelativeTo.TryGetRotation(); Quaternion relativeDeltaRotation = currentRelativeRotation * Quaternion.Inverse(previousRelativeRotation); Quaternion currentRotation = Source.TryGetRotation(); Quaternion deltaRotation = Quaternion.Inverse(relativeDeltaRotation) * (currentRotation * Quaternion.Inverse(previousRotation)); float theta = 2.0f * Mathf.Acos(Mathf.Clamp(deltaRotation.w, -1.0f, 1.0f)); if (theta > Mathf.PI) { theta -= 2.0f * Mathf.PI; } Vector3 angularVelocity = new Vector3(deltaRotation.x, deltaRotation.y, deltaRotation.z); if (angularVelocity.sqrMagnitude > 0.0f) { angularVelocity = theta * factor * angularVelocity.normalized; } int sampleIndex = currentSampleCount % angularVelocitySamples.Length; angularVelocitySamples[sampleIndex] = angularVelocity; previousRotation = currentRotation; previousRelativeRotation = currentRelativeRotation; }
public override void ShowGUI(List <ActionParameter> parameters) { isPlayer = EditorGUILayout.Toggle("Affect Player?", isPlayer); if (!isPlayer) { charToMoveParameterID = Action.ChooseParameterGUI("Character to turn:", parameters, charToMoveParameterID, ParameterType.GameObject); if (charToMoveParameterID >= 0) { charToMoveID = 0; charToMove = null; } else { charToMove = (Char)EditorGUILayout.ObjectField("Character to turn:", charToMove, typeof(Char), true); charToMoveID = FieldToID <Char> (charToMove, charToMoveID); charToMove = IDToField <Char> (charToMove, charToMoveID, false); } } direction = (CharDirection)EditorGUILayout.EnumPopup("Direction to face:", direction); relativeTo = (RelativeTo)EditorGUILayout.EnumPopup("Direction is relative to:", relativeTo); isInstant = EditorGUILayout.Toggle("Is instant?", isInstant); if (!isInstant) { willWait = EditorGUILayout.Toggle("Wait until finish?", willWait); } AfterRunningOption(); }
void OnValidate() { if (useRelativeObject == RelativeTo.selected && relativeToObject == null) { useRelativeObject = RelativeTo.nothing; } }
/// <summary> /// Gets new range from the current hashes object. /// </summary> /// <param name="startsAt">Start at (as relative to <see cref="RelativeTo"/>.</param> /// <param name="length">Length in seconds of the new <see cref="Hashes"/> object.</param> /// <returns>New hashes object.</returns> public Hashes GetRange(DateTime startsAt, float length) { if (IsEmpty) { return(GetEmpty(MediaType)); } var endsAt = startsAt.AddSeconds(length); var ordered = fingerprints.OrderBy(_ => _.SequenceNumber).ToList(); var lengthOfOneFingerprint = DurationInSeconds - ordered.Last().StartsAt; var filtered = ordered.Where(fingerprint => { var fingerprintStartsAt = RelativeTo.AddSeconds(fingerprint.StartsAt); var fingerprintEndsAt = RelativeTo.AddSeconds(fingerprint.StartsAt + lengthOfOneFingerprint); return(fingerprintStartsAt >= startsAt && fingerprintEndsAt <= endsAt); }) .ToList(); if (!filtered.Any()) { return(new Hashes(Enumerable.Empty <HashedFingerprint>(), 0, MediaType, startsAt)); } var relativeTo = RelativeTo.AddSeconds(filtered.First().StartsAt); var duration = filtered.Last().StartsAt - filtered.First().StartsAt + lengthOfOneFingerprint; var shifted = ShiftStartsAtAccordingToSelectedRange(filtered); return(new Hashes(shifted, duration, MediaType, relativeTo, Origins, StreamId, additionalProperties ?? emptyDictionary, 0)); }
// Use this for initialization void Start() { fileName = this.gameObject.name + ".txt"; if (!File.Exists(fileName)) { FileWriter = File.CreateText(fileName); FileWriter.AutoFlush = true; FileWriter.WriteLine("RelativeTo\tRelativePos\tX\tY\tZ\tRelativeVel\tApoapsisHeight\tPeriapsisHeight\tCurrentDistance\tStartTheta\tStartPhi\tcurrentTheta\tcurrentPhi\tmaxDistanceAngleTheta\tmaxDistanceAnglePhi\tminDistanceAngleTheta\tminDistanceAnglePhi\tperiod\tspin\tlastPos\tlastPhi\tperiodSum"); } else { FileWriter = File.AppendText(fileName); FileWriter.AutoFlush = true; } RelativePos = RelativeTo.gameObject.transform.position - this.transform.position; RelativePos /= (PlanetData.AE / PlanetData.distanceUmrechnung); RelativeVel = RelativeTo.GetComponent <Rigidbody>().velocity - this.GetComponent <Rigidbody>().velocity; StartTheta = Mathf.Asin(RelativePos.y / RelativePos.magnitude); StartPhi = Mathf.Atan2(RelativePos.z, RelativePos.x); ApoapsisHeight = RelativePos.magnitude; MaxDistanceAngleTheta = StartTheta; MaxDistanceAnglePhi = StartPhi; PeriapsisHeight = RelativePos.magnitude; MinDistanceAngleTheta = StartTheta; MinDistanceAngleTheta = StartPhi; }
public Point GetCornerPoint(FoldPosition corner, RelativeTo relativeTo) { Point point; switch (corner) { case FoldPosition.TopLeft: point = relativeTo == RelativeTo.Book ? new Point(-1.0 * (this.book.ActualWidth / 2.0), 0.0) : new Point(0.0, 0.0); break; case FoldPosition.TopRight: point = relativeTo == RelativeTo.Book ? new Point(this.book.ActualWidth, 0.0) : new Point(this.book.ActualWidth / 2.0, 0.0); break; case FoldPosition.BottomRight: point = relativeTo == RelativeTo.Book ? new Point(this.book.ActualWidth, this.book.ActualHeight) : new Point(this.book.ActualWidth / 2.0, this.book.ActualHeight); break; case FoldPosition.BottomLeft: point = relativeTo == RelativeTo.Book ? new Point(-1.0 * (this.book.ActualWidth / 2.0), this.book.ActualHeight) : new Point(0.0, this.book.ActualHeight); break; default: point = new Point(); break; } return(point); }
public override void Start() { Zoom = new Vector2(1.0f, 1.0f); SmoothFollow = false; relativeTo = RelativeTo.WORLD; base.Start(); }
public bool Equals(RelativeTo rt) { if (rt == null) { return(false); } return(horizontal == rt.horizontal && vertical == rt.vertical); }
public void Copy(RelativeTo rt) { if (rt == null) { return; } horizontal = rt.horizontal; vertical = rt.vertical; }
protected virtual void OnEnable() { velocitySamples = new Vector3[VelocityAverageFrames]; angularVelocitySamples = new Vector3[AngularVelocityAverageFrames]; previousPosition = Source.TryGetPosition(); previousRotation = Source.TryGetRotation(); previousRelativePosition = RelativeTo.TryGetPosition(); previousRelativeRotation = RelativeTo.TryGetRotation(); }
/// <summary> /// Sets the screen corner or side the element will be positioned relative to. /// </summary> /// <param name="relativeTo">Screen corner or side.</param> /// <param name="updatePosition">if set to <c>true</c> update position.</param> public void SetRelativeTo(RelativeTo relativeTo, bool updatePosition = true) { bool changed = (m_relativeTo != relativeTo); m_relativeTo = relativeTo; if (updatePosition && changed) { UpdateScreenPosition(); } }
public float y() { if (RelativeTo != null) { return(RelativeTo.y() + Y); } else { return(Y); } }
public float x() { if (RelativeTo != null) { return(RelativeTo.x() + X); } else { return(X); } }
private double GetRelativePriority(int index, RelativeTo relativeTo) { IResult iResult = parts[index] as IResult; if (iResult == null) { return(0); } return(iResult.GetRelativePriority(relativeTo)); }
/// <summary> /// Collects samples for velocity. /// </summary> /// <param name="factor">The multiplier to apply to the transform difference.</param> protected virtual void EstimateVelocity(float factor) { if (velocitySamples.Length == 0) { return; } Vector3 currentRelativePosition = RelativeTo.TryGetPosition(); Vector3 relativeDeltaPosition = currentRelativePosition - previousRelativePosition; Vector3 currentPosition = Source.TryGetPosition(); int sampleIndex = currentSampleCount % velocitySamples.Length; velocitySamples[sampleIndex] = factor * (currentPosition - previousPosition - relativeDeltaPosition); previousPosition = currentPosition; previousRelativePosition = currentRelativePosition; }
public double GetRelativePriority(RelativeTo relativeTo) { int priority = GetPriorityValue(); switch (GetPriorityType()) { case PriorityType.Same: return(priority); case PriorityType.LeftHigher: return(priority + (relativeTo == RelativeTo.Left ? 0.1 : -0.1)); case PriorityType.RightHigher: return(priority + (relativeTo == RelativeTo.Right ? 0.1 : -0.1)); } return(priority); }
public void Translate(Vector2 t, RelativeTo relativeTo = RelativeTo.WORLD) { if (relativeTo == RelativeTo.WORLD) { position += t; foreach (GameObject o in this.gameObject.Children) { o.transform.position += t; } } else { //Rotational correction code position += t.ToObjectSpace(gameObject); foreach (GameObject o in this.gameObject.Children) { o.transform.position += t.ToObjectSpace(gameObject); } } }
public float CalculateBestPlace(HandSnapPose userPose, out (Vector3, Quaternion) bestPlace) { float bestScore = 0f; HandSnapPose snapPose = _snapPoseVolume.pose; if (snapPose.handeness != userPose.handeness && !_snapPoseVolume.ambydextrous) { bestPlace = (Vector3.zero, Quaternion.identity); return(bestScore); } Vector3 globalPosDesired = RelativeTo.TransformPoint(userPose.relativeGripPos); Quaternion globalRotDesired = RelativeTo.rotation * userPose.relativeGripRot; (Vector3, Quaternion)desiredPlace = (globalPosDesired, globalRotDesired); var similarPlace = SimilarPlaceAtVolume(userPose, snapPose); var nearestPlace = NearestPlaceAtVolume(userPose, snapPose); bestPlace = GetBestPlace(similarPlace, nearestPlace, desiredPlace, out bestScore); if (_snapPoseVolume.handCanInvert) { HandSnapPose invertedPose = _snapPoseVolume.InvertedPose(RelativeTo); var similarInvertedPlace = SimilarPlaceAtVolume(userPose, invertedPose); var nearestInvertedPlace = NearestPlaceAtVolume(userPose, invertedPose); var bestInvertedPlace = GetBestPlace(similarInvertedPlace, nearestInvertedPlace, desiredPlace, out float bestInvertedScore); if (bestInvertedScore > bestScore) { bestPlace = bestInvertedPlace; return(bestInvertedScore); } } return(bestScore); }
// Update is called once per frame void FixedUpdate() { //RelativePos = RelativeTo.gameObject.transform.position - this.transform.position; //RelativePos = RelativePos * PlanetData.distanceUmrechnung / PlanetData.AE; RelativePos = (this.transform.position - RelativeTo.gameObject.transform.position) * PlanetData.distanceUmrechnung / PlanetData.AE; RelativeVel = RelativeTo.GetComponent <Rigidbody>().velocity - this.GetComponent <Rigidbody>().velocity; CurrentDistance = RelativePos.magnitude; CurrentTheta = Mathf.Asin(RelativePos.y / RelativePos.magnitude); CurrentPhi = Mathf.Atan2(RelativePos.z, RelativePos.x); if (RelativePos.magnitude > ApoapsisHeight) { ApoapsisHeight = RelativePos.magnitude; MaxDistanceAngleTheta = CurrentTheta; MaxDistanceAnglePhi = CurrentPhi; } else if (RelativePos.magnitude < PeriapsisHeight) { PeriapsisHeight = RelativePos.magnitude; MinDistanceAngleTheta = CurrentTheta; MinDistanceAnglePhi = CurrentPhi; } PeriodSum += Time.deltaTime; if (LastPhi > CurrentPhi) { Period = PeriodSum; PeriodSum = 0; } LastPhi = CurrentPhi; Tagecounter += tickDays; }
public FolderPathAttribute(string defaultPath = DefaultLocalPath, RelativeTo relativeTo = RelativeTo.None, bool displayWarning = true) { DefaultPath = defaultPath; PathRelativeTo = relativeTo; IsWarningDisplayed = displayWarning; }
public void TurnPage(FoldPosition to, RelativeTo relativeTo) { this.TurnPage(this.GetCornerPoint(to, relativeTo)); }
public void TurnPage(FoldPosition from, Point to, RelativeTo relativeTo) { this.TurnPage(this.GetCornerPoint(from, relativeTo), to); }
public void TurnPage(Point from, FoldPosition to, RelativeTo relativeTo) { Point cornerPoint = this.GetCornerPoint(to, relativeTo); this.TurnPage(from, cornerPoint); }
public void TurnPage(FoldPosition from, FoldPosition to, RelativeTo cornerFromRelativeness, RelativeTo cornerToRelativeness) { this.TurnPage(this.GetCornerPoint(from, cornerFromRelativeness), this.GetCornerPoint(to, cornerToRelativeness)); }
public override void ShowGui(RuleData ruleData) { GUILayout.Label("move", RuleGUI.ruleLabelStyle); int resultIndex = actorDropDown.Draw(); if (resultIndex > -1) { int resultId = generator.Gui.GetActorDataByLabel(actorDropDown.Content[resultIndex].text).id; if (resultId != Reactor.Id) generator.ChangeActor(this, resultId); (ruleData as ReactionData).actorId = resultId; } GUILayout.Label("relative to", RuleGUI.ruleLabelStyle); DirectionRelativeTo = (RelativeTo)relativeToDropdown.Draw(); ChangeParameter("DirectionRelativeTo", (ruleData as ReactionData).parameters, DirectionRelativeTo); if (DirectionRelativeTo == RelativeTo.ACTOR) { resultIndex = relativeActorDropDown.Draw(); if (resultIndex > -1) { int resultId = generator.Gui.GetActorDataByLabel(relativeActorDropDown.Content[resultIndex].text).id; ActorDirectionIsRelativeTo = generator.GetActor(resultId); ChangeParameter("ActorDirectionIsRelativeTo", (ruleData as ReactionData).parameters, ActorDirectionIsRelativeTo.Id); } } GUILayout.Label("in direction: ", RuleGUI.ruleLabelStyle); MoveDirection = (Direction)moveDirectionDropdown.Draw(); ChangeParameter("MoveDirection", (ruleData as ReactionData).parameters, MoveDirection); GUILayout.Label("with a speed of", RuleGUI.ruleLabelStyle); MoveSpeed = RuleGUI.ShowParameter((float)MoveSpeed); ChangeParameter("MoveSpeed", (ruleData as ReactionData).parameters, MoveSpeed); GUILayout.Label("units.", RuleGUI.ruleLabelStyle); }
/** * <summary>Creates a new instance of the 'Character: Face direction' Action</summary> * <param name = "characterToTurn">The character to affect</param> * <param name = "directionToFace">The direction to face</param> * <param name = "relativeTo">What the supplied direction is relative to</param> * <param name = "isInstant">If True, the character will stop turning their head instantly</param> * <param name = "waitUntilFinish">If True, then the Action will wait until the transition is complete</param> * <returns>The generated Action</returns> */ public static ActionCharFaceDirection CreateNew(AC.Char characterToTurn, CharDirection directionToFace, RelativeTo relativeTo = RelativeTo.Camera, bool isInstant = false, bool waitUntilFinish = false) { ActionCharFaceDirection newAction = (ActionCharFaceDirection)CreateInstance <ActionCharFaceDirection>(); newAction.charToMove = characterToTurn; newAction.direction = directionToFace; newAction.relativeTo = relativeTo; newAction.isInstant = isInstant; newAction.willWait = waitUntilFinish; return(newAction); }
protected virtual void OnAfterRelativeToChange() { previousRelativePosition = RelativeTo.TryGetPosition(); previousRelativeRotation = RelativeTo.TryGetRotation(); }
public PixelConstraint(int value, RelativeTo relation, Direction direction) { Value = value; this.relation = relation; this.direction = direction; }
public void Copy(RelativeTo rt) { if (rt == null) return; horizontal = rt.horizontal; vertical = rt.vertical; }
public bool Equals(RelativeTo rt) { if (rt == null) return false; return (horizontal == rt.horizontal && vertical == rt.vertical); }
// Copy constructor public RelativeTo(EZScreenPlacement sp, RelativeTo rt) { script = sp; Copy(rt); }