public void It_Returns_A_Vector_Rotated_By_An_Angle() { // Arrange Vector3 vector = new Vector3(-7, 10, -5); double rotationAngle1 = GSharkMath.ToRadians(-0.0000125); Vector3 expectedResult1 = new Vector3(-7.0, 10.0, -5.0); double rotationAngle2 = GSharkMath.ToRadians(0.0); Vector3 expectedResult2 = new Vector3(-7.0, 10.0, -5.0); double rotationAngle3 = GSharkMath.ToRadians(12.5); Vector3 expectedResult3 = new Vector3(-7.454672, 10.649531, -2.239498); double rotationAngle4 = GSharkMath.ToRadians(450); Vector3 expectedResult4 = new Vector3(-2.867312, 4.09616, 12.206556); Vector3 axis = new Vector3(10, 7, 0); // Act Vector3 result1 = vector.Rotate(axis, rotationAngle1); Vector3 result2 = vector.Rotate(axis, rotationAngle2); Vector3 result3 = vector.Rotate(axis, rotationAngle3); Vector3 result4 = vector.Rotate(axis, rotationAngle4); // Assert result1.EpsilonEquals(expectedResult1, 1e-6).Should().Be(true); result2.EpsilonEquals(expectedResult2, 1e-6).Should().Be(true); result3.EpsilonEquals(expectedResult3, 1e-6).Should().Be(true); result4.EpsilonEquals(expectedResult4, 1e-6).Should().Be(true); }
private void UpdateCameraVectors() { Vector3 Vaxis = new Vector3(0.0f, 1.0f, 0.0f); Vector3 View = new Vector3(1.0f, 0.0f, 0.0f); View.Rotate(_angleHorizontal, Vaxis); View.Normalize(); Vector3 Haxis = Vaxis.CrossProduct(View); Haxis.Normalize(); View.Rotate(_angleVertical, Haxis); View.Normalize(); _cameraTarget = View; _cameraTarget.Normalize(); _cameraUp = _cameraTarget.CrossProduct(Haxis); _cameraUp.Normalize(); _cameraUp.Roll(_angleClockwise); openGLControl_Resized(null, null); }
protected override Vector3 GetRollDir() { Vector3 targetPos = Vector3.zero; bool found = false; if (Agent.BlackBoard.desiredTarget != null) { targetPos = Agent.BlackBoard.desiredTarget.Position - Agent.Position; targetPos = Agent.Position + (targetPos.normalized * Agent.BlackBoard.rollDistance); for (int degree = 20; degree < 40; ++degree) { targetPos = targetPos.Rotate(Vector3.up, degree); if (CheckTargetPos(targetPos)) { found = true; break; } targetPos = targetPos.Rotate(Vector3.up, -degree); if (CheckTargetPos(targetPos)) { found = true; break; } } } if (found == false) { return(Vector3.zero); } return((targetPos - Agent.Position).normalized); }
/// <summary>Creates a new transformation, based upon yaw pitch and roll values</summary> /// <param name="Yaw"> /// <para>The yaw to apply</para> /// <para>NOTE: The angle in radians by which the object is rotated in the XZ-plane in clock-wise order when viewed from above.</para> /// </param> /// <param name="Pitch"> /// <para>The pitch to apply</para> /// <para>NOTE: The angle in radians by which the object is rotated in the YZ-plane in *counter* clock-wise order when viewed from the right.</para> /// </param> /// <param name="Roll"> /// <para>The roll to apply</para> /// <para>NOTE: The angle in radians by which the object is rotated in the XY-plane in *counter* clock-wise order when viewed from ahead.</para> /// </param> public Transformation(double Yaw, double Pitch, double Roll) { if (Yaw == 0.0 & Pitch == 0.0 & Roll == 0.0) { X = Vector3.Right; Y = Vector3.Down; Z = Vector3.Forward; } else if (Pitch == 0.0 & Roll == 0.0) { double cosYaw = System.Math.Cos(Yaw); double sinYaw = System.Math.Sin(Yaw); X = new Vector3(cosYaw, 0.0, -sinYaw); Y = Vector3.Down; Z = new Vector3(sinYaw, 0.0, cosYaw); } else { X = Vector3.Right; Y = Vector3.Down; Z = Vector3.Forward; X.Rotate(Y, Yaw); Z.Rotate(Y, Yaw); // In the left-handed coordinate system, the clock-wise rotation is positive when the origin is viewed from the positive direction of the axis. // Therefore, reverse the sign of rotation. Y.Rotate(X, -Pitch); Z.Rotate(X, -Pitch); X.Rotate(Z, -Roll); Y.Rotate(Z, -Roll); } }
public RaycastHit[] GetHits(Vector3 origin, Vector3 direction, bool debug = false) { List <RaycastHit> hits = new List <RaycastHit>(); float adjustedDistance = distance / Mathf.Cos(spread * Mathf.Deg2Rad); RaycastHit hit; if (Physics.Raycast(origin + offset, direction, out hit, distance, layerMask)) { hits.Add(hit); } if (Physics.Raycast(origin + offset, direction.Rotate(spread), out hit, adjustedDistance, layerMask)) { hits.Add(hit); } if (Physics.Raycast(origin + offset, direction.Rotate(-spread), out hit, adjustedDistance, layerMask)) { hits.Add(hit); } if (debug) { DrawRays(origin, direction); } return(hits.ToArray()); }
/// <summary>Creates a new transformation, based upon yaw pitch and roll values</summary> /// <param name="Yaw">The yaw to apply</param> /// <param name="Pitch">The pitch to apply</param> /// <param name="Roll">The roll to apply</param> public Transformation(double Yaw, double Pitch, double Roll) { if (Yaw == 0.0 & Pitch == 0.0 & Roll == 0.0) { this.X = Vector3.Right; this.Y = Vector3.Down; this.Z = Vector3.Forward; } else if (Pitch == 0.0 & Roll == 0.0) { double cosYaw = System.Math.Cos(Yaw); double sinYaw = System.Math.Sin(Yaw); this.X = new Vector3(cosYaw, 0.0, -sinYaw); this.Y = Vector3.Down; this.Z = new Vector3(sinYaw, 0.0, cosYaw); } else { X = Vector3.Right; Y = Vector3.Down; Z = Vector3.Forward; double cosYaw = System.Math.Cos(Yaw); double sinYaw = System.Math.Sin(Yaw); double cosPitch = System.Math.Cos(-Pitch); double sinPitch = System.Math.Sin(-Pitch); double cosRoll = System.Math.Cos(-Roll); double sinRoll = System.Math.Sin(-Roll); X.Rotate(Y, cosYaw, sinYaw); Z.Rotate(Y, cosYaw, sinYaw); Y.Rotate(X, cosPitch, sinPitch); Z.Rotate(X, cosPitch, sinPitch); X.Rotate(Z, cosRoll, sinRoll); Y.Rotate(Z, cosRoll, sinRoll); } }
internal void UpdateTopplingCantAndSpring() { if (CarSections.Length != 0) { //FRONT BOGIE // get direction, up and side vectors Vector3 d = new Vector3(FrontAxle.Follower.WorldPosition - RearAxle.Follower.WorldPosition); Vector3 s; { double t = 1.0 / d.Norm(); d *= t; t = 1.0 / Math.Sqrt(d.X * d.X + d.Z * d.Z); double ex = d.X * t; double ez = d.Z * t; s = new Vector3(ez, 0.0, -ex); Up = Vector3.Cross(d, s); } // cant and radius //TODO: This currently uses the figures from the base car // apply position due to cant/toppling { double a = baseCar.Specs.CurrentRollDueToTopplingAngle + baseCar.Specs.CurrentRollDueToCantAngle; double x = Math.Sign(a) * 0.5 * Game.RouteRailGauge * (1.0 - Math.Cos(a)); double y = Math.Abs(0.5 * Game.RouteRailGauge * Math.Sin(a)); Vector3 c = new Vector3(s.X * x + Up.X * y, s.Y * x + Up.Y * y, s.Z * x + Up.Z * y); FrontAxle.Follower.WorldPosition += c; RearAxle.Follower.WorldPosition += c; } // apply rolling { double a = -baseCar.Specs.CurrentRollDueToTopplingAngle - baseCar.Specs.CurrentRollDueToCantAngle; double cosa = Math.Cos(a); double sina = Math.Sin(a); s.Rotate(d, cosa, sina); Up.Rotate(d, cosa, sina); } // apply pitching if (CurrentCarSection >= 0 && CarSections[CurrentCarSection].Overlay) { double a = baseCar.Specs.CurrentPitchDueToAccelerationAngle; double cosa = Math.Cos(a); double sina = Math.Sin(a); d.Rotate(s, cosa, sina); Up.Rotate(s, cosa, sina); Vector3 cc = 0.5 * (FrontAxle.Follower.WorldPosition + RearAxle.Follower.WorldPosition); FrontAxle.Follower.WorldPosition -= cc; RearAxle.Follower.WorldPosition -= cc; FrontAxle.Follower.WorldPosition.Rotate(s, cosa, sina); RearAxle.Follower.WorldPosition.Rotate(s, cosa, sina); FrontAxle.Follower.WorldPosition += cc; RearAxle.Follower.WorldPosition += cc; } } }
public void DrawRays(Vector3 origin, Vector3 direction) { float adjustedDistance = distance / Mathf.Cos(spread * Mathf.Deg2Rad); Debug.DrawRay(origin + offset, direction * distance, Color.green); Debug.DrawRay(origin + offset, direction.Rotate(spread) * adjustedDistance, Color.green); Debug.DrawRay(origin + offset, direction.Rotate(-spread) * adjustedDistance, Color.green); }
private void setIllusionsToVector(Vector3 i_PerpendicularVector) { m_LastRecordedDirection = i_PerpendicularVector; m_Illusions[0].transform.position = transform.position + i_PerpendicularVector.Rotate(m_DegreeBetweenIllusions / 2).normalized * m_IllusionDistanceFromDemon; m_Illusions[1].transform.position = transform.position + i_PerpendicularVector.Rotate(-m_DegreeBetweenIllusions / 2).normalized * m_IllusionDistanceFromDemon; }
/// <summary>Creates a new transformation, based upon an initial transformation, plus secondary yaw pitch and roll values</summary> /// <param name="Transformation">The initial transformation</param> /// <param name="Yaw">The yaw to apply</param> /// <param name="Pitch">The pitch to apply</param> /// <param name="Roll">The roll to apply</param> public Transformation(Transformation Transformation, double Yaw, double Pitch, double Roll) { X = new Vector3(Transformation.X); Y = new Vector3(Transformation.Y); Z = new Vector3(Transformation.Z); X.Rotate(Y, Yaw); Z.Rotate(Y, Yaw); Y.Rotate(X, -Pitch); Z.Rotate(X, -Pitch); X.Rotate(Z, Roll); Y.Rotate(Z, Roll); }
/// <summary>Creates a new transformation, based upon an initial transformation, plus secondary yaw pitch and roll values</summary> /// <param name="Transformation">The initial transformation</param> /// <param name="Yaw"> /// <para>The yaw to apply</para> /// <para>NOTE: The angle in radians by which the object is rotated in the XZ-plane in clock-wise order when viewed from above.</para> /// </param> /// <param name="Pitch"> /// <para>The pitch to apply</para> /// <para>NOTE: The angle in radians by which the object is rotated in the YZ-plane in *counter* clock-wise order when viewed from the right.</para> /// </param> /// <param name="Roll"> /// <para>The roll to apply</para> /// <para>NOTE: The angle in radians by which the object is rotated in the XY-plane in *counter* clock-wise order when viewed from ahead.</para> /// </param> public Transformation(Transformation Transformation, double Yaw, double Pitch, double Roll) { X = new Vector3(Transformation.X); Y = new Vector3(Transformation.Y); Z = new Vector3(Transformation.Z); X.Rotate(Y, Yaw); Z.Rotate(Y, Yaw); // In the left-handed coordinate system, the clock-wise rotation is positive when the origin is viewed from the positive direction of the axis. // Therefore, reverse the sign of rotation. Y.Rotate(X, -Pitch); Z.Rotate(X, -Pitch); X.Rotate(Z, -Roll); Y.Rotate(Z, -Roll); }
/// <summary>Updates the position and rotation of an animated object which follows a track</summary> private void UpdateObjectPosition() { //Get vectors Direction = new Vector3(FrontAxleFollower.WorldPosition - RearAxleFollower.WorldPosition); { double t = 1.0 / Direction.Norm(); Direction *= t; t = 1.0 / System.Math.Sqrt(Direction.X * Direction.X + Direction.Z * Direction.Z); double ex = Direction.X * t; double ez = Direction.Z * t; Side = new Vector3(ez, 0.0, -ex); Up = Vector3.Cross(Direction, Side); } // apply position due to cant/toppling { double a = CurrentRollDueToTopplingAngle + CurrentRollDueToCantAngle; double x = System.Math.Sign(a) * 0.5 * FrontAxleFollower.RailGauge * (1.0 - System.Math.Cos(a)); double y = System.Math.Abs(0.5 * FrontAxleFollower.RailGauge * System.Math.Sin(a)); Vector3 c = Side * x + Up * y; FrontAxleFollower.WorldPosition += c; RearAxleFollower.WorldPosition += c; } // apply rolling { double a = CurrentRollDueToTopplingAngle - CurrentRollDueToCantAngle; double cosa = System.Math.Cos(a); double sina = System.Math.Sin(a); Side.Rotate(Direction, cosa, sina); Up.Rotate(Direction, cosa, sina); } }
public void Move(Vector3 target) { int troopCounter = 0; int segmentLength = 1; Vector3 lastPosition = target; Vector3 currentDirection = Vector3.forward; TroopBase[] troops = GetTroops(); while (troopCounter < troops.Length) { for (int i = 0; i < segmentLength / 2;) { TroopBase troop = troops[troopCounter]; if (troop.gameObject.activeInHierarchy) { troop.Target = lastPosition; lastPosition += currentDirection * troop.radius; i++; } troopCounter += 1; if (troopCounter >= troops.Length) { break; } } currentDirection = currentDirection.Rotate(90, Vector3.up); segmentLength += 1; } }
Chunk createAndPlaceNewChunk(GameObject prefab, int chunkId, float loadSpeed) { Chunk prefabChunk = prefab.GetComponent <Chunk>(); int yDifference = this.lastRoomRightExitY - prefabChunk.entreanceY; Vector3 movement = new Vector3(0, yDifference, 0); movement = movement.Rotate(rotation, Vector3.back); lastRoomEndPosition += movement; Chunk newChunk = createChunk(prefab, chunkId, loadSpeed); if (lastChunk != null) { lastChunk.nextChunk = newChunk; newChunk.lastChunk = lastChunk; } lastChunk = newChunk; proceduralGeneratorOfChunk.chunksToAdd.Add(newChunk); newChunk.chunkId = chunkId; newChunk.proceduralGenerator = proceduralGeneratorOfChunk; Vector3 movementX = new Vector3(prefabChunk.width, 0, 0); movementX = movementX.Rotate(rotation, Vector3.back); lastRoomEndPosition += movementX; lastRoomRightExitY = prefabChunk.rightExitY; return(newChunk); }
public virtual LineSegment3D Rotate(Vector3 pivotPoint, Quaternion rotation) { Vector3 outputStart = start.Rotate(pivotPoint, rotation); Vector3 outputEnd = end.Rotate(pivotPoint, rotation); return(new LineSegment3D(outputStart, outputEnd)); }
/// <summary> /// Returns the angle of attack of the part in degrees /// </summary> public float GetAoA(VehiclePart part, float angle, Vector3 worldVelocity) { float aoa; Vehicle vehicle = part.Vehicle; // Get the velocity in vehicle space Vector3 velocityVehicleSpace = vehicle.transform.InverseTransformDirection(worldVelocity); // Get the right direction of the part in vehicle space Vector3 partRightDirectionVehicleSpace = part.PartConfig.localRightDirection.RecontextualizeDirection(part.transform, vehicle.transform).normalized; // Flatten the velocity in vehicle space to a plane perpendicular to the part's right direction in vehicle space velocityVehicleSpace.Project(partRightDirectionVehicleSpace); // Get the default forward direction of the part in vehicle space Vector3 partDefaultForwardDirectionVehicleSpace = part.PartConfig.localForwardDirection.RecontextualizeDirection(part.transform, vehicle.transform).normalized; // Get the current forward direction the part in vehicle space Vector3 partForwardDirectionVehicleSpace = partDefaultForwardDirectionVehicleSpace.Rotate(angle, partRightDirectionVehicleSpace); // Get the angle between the current forward direction of the part in vehicle space and the flattened velocity in vehicle space. aoa = Vector3.SignedAngle(partForwardDirectionVehicleSpace, velocityVehicleSpace, partRightDirectionVehicleSpace); // This does the same thing. Is it faster? /*Vector3 partUpDirectionVehicleSpace = Vector3.Cross(partForwardDirectionVehicleSpace, partRightDirectionVehicleSpace); * float upAmount = Vector3.Dot(velocityVehicleSpace, partUpDirectionVehicleSpace); * float forwardAmount = Vector3.Dot(velocityVehicleSpace, partForwardDirectionVehicleSpace); * float aoa2 = Mathf.Atan2(-upAmount, forwardAmount) * Mathf.Rad2Deg; * Debug.Log(aoa/aoa2);*/ return(aoa); }
public void Rotate() { var point = new Vector3(5.0, 5.0); var rotated = point.Rotate(Vector3.Origin, 180.0); Assert.Equal(-5.0, rotated.X, 10); Assert.Equal(-5.0, rotated.Y, 10); }
public void TestFunctions() { // member Vector3 v = new Vector3(1, 2, 3); float l = v.magnitude; v.Normalize(); Assert.AreEqual(v, new Vector3(1 / l, 2 / l, 3 / l)); v.Set(1, 0, 2); Assert.AreEqual(v, new Vector3(1, 0, 2)); Assert.AreEqual(v.Rotate(Vector3.up, Mathf.PI), new Vector3(-1f, 0f, -2f)); Assert.IsTrue(v.Rotate(Vector3.up, Mathf.PI) == new Vector3(-1f, 0f, -2f)); Assert.AreEqual(v, new Vector3(1, 0, 2)); // staitc Vector3 v1 = new Vector3(1, 2, 3); Vector3 v2 = new Vector3(2, 3, 4); Assert.IsTrue(Mathf.Equals(v1, new Vector3(1.000009f, 2.000009f, 2.999991f))); Assert.IsFalse(Mathf.Equals(v1, new Vector3(1.00001f, 2.000009f, 2.999991f))); Assert.IsFalse(Mathf.Equals(v1, new Vector3(1.000009f, 2.00001f, 2.999991f))); Assert.IsFalse(Mathf.Equals(v1, new Vector3(1.000009f, 2.000009f, 2.99999f))); Assert.AreEqual(Vector3.Angle(v1, v2), 0.121868052f); Assert.IsTrue(Vector3.Cross(v1, v2) == new Vector3(-1, 2, -1)); Assert.AreEqual(Vector3.Distance(v1, v2), Mathf.Sqrt(3)); Assert.AreEqual(Vector3.Dot(v1, v2), 20); Assert.AreEqual(Vector3.Lerp(v1, v2, 0), v1); Assert.AreEqual(Vector3.Lerp(v1, v2, 0.5f), new Vector3(1.5f, 2.5f, 3.5f)); Assert.AreEqual(Vector3.Lerp(v1, v2, 1), v2); Assert.AreEqual(Vector3.SqrMagnitude(v1), 14); Assert.AreEqual(Vector3.Magnitude(v1), Mathf.Sqrt(14)); Assert.AreEqual(Vector3.Normalize(v1), new Vector3(1 / v1.magnitude, 2 / v1.magnitude, 3 / v1.magnitude)); Assert.AreEqual(Vector3.Max(v1, v2), v2); Assert.AreEqual(Vector3.Min(v1, v2), v1); }
static void Main(string[] args) { Console.WriteLine("Hello Core!"); var point = new Vector3(10, 10, 10); Console.WriteLine(point); Console.WriteLine(); Console.WriteLine(point.Rotate(new Vector3(0, 0, 0))); Console.WriteLine(); Console.WriteLine(point.Rotate(new Vector3(Math.PI, 0, 0))); Console.WriteLine(point.Rotate(new Vector3(Math.PI, 0, 0))); Console.WriteLine(); Console.WriteLine(point.Rotate(new Vector3(0, Math.PI, 0))); Console.WriteLine(point.Rotate(new Vector3(0, Math.PI, 0))); Console.WriteLine(); Console.WriteLine(point.Rotate(new Vector3(0, 0, Math.PI))); Console.WriteLine(point.Rotate(new Vector3(0, 0, Math.PI))); Console.WriteLine(); Console.WriteLine(point); Console.WriteLine("\nend"); Console.ReadKey(); }
/// <summary>Creates a new transformation, based upon a base transformation and an additional transformation</summary> /// <param name="firstTransformation">The transformation to apply first</param> /// <param name="secondTransformation">The transformation to apply second</param> public Transformation(Transformation firstTransformation, Transformation secondTransformation) { X = new Vector3(firstTransformation.X); Y = new Vector3(firstTransformation.Y); Z = new Vector3(firstTransformation.Z); X.Rotate(secondTransformation); Y.Rotate(secondTransformation); Z.Rotate(secondTransformation); }
/// <summary>Creates a new transformation, based upon a base transformation and an auxiliary transformation</summary> /// <param name="BaseTransformation">The base transformation</param> /// <param name="AuxTransformation">The auxiliary transformation</param> public Transformation(Transformation BaseTransformation, Transformation AuxTransformation) { X = new Vector3(BaseTransformation.X); Y = new Vector3(BaseTransformation.Y); Z = new Vector3(BaseTransformation.Z); X.Rotate(AuxTransformation.Z, AuxTransformation.Y, AuxTransformation.X); Y.Rotate(AuxTransformation.Z, AuxTransformation.Y, AuxTransformation.X); Z.Rotate(AuxTransformation.Z, AuxTransformation.Y, AuxTransformation.X); }
public void RotateAround(Vector3 point, Vector3 axis, float angle) { Vector3 tmp = point - Position; Translate(tmp); Rotate(axis, angle); tmp.Rotate(axis, angle); Translate(-tmp.X, -tmp.Y, -tmp.Z); }
public void Rotate_ReturnSucceed(float a, float b, float c, float radians, float xcenter, float ycenter, float zcenter, float x, float y, float z) { var input = new Vector3(a, b, c); var center = new Vector3(xcenter, ycenter, zcenter); var result = input.Rotate(radians, center); Assert.Equal(Math.Round(x, 3), Math.Round(result.X, 3)); Assert.Equal(Math.Round(y, 3), Math.Round(result.Y, 3)); Assert.Equal(Math.Round(z, 3), Math.Round(result.Z, 3)); }
/// <summary>Creates a new transformation, based upon an initial transformation, plus secondary yaw pitch and roll values</summary> /// <param name="Transformation">The initial transformation</param> /// <param name="Yaw">The yaw to apply</param> /// <param name="Pitch">The pitch to apply</param> /// <param name="Roll">The roll to apply</param> public Transformation(Transformation Transformation, double Yaw, double Pitch, double Roll) { X = new Vector3(Transformation.X); Y = new Vector3(Transformation.Y); Z = new Vector3(Transformation.Z); double cosYaw = System.Math.Cos(Yaw); double sinYaw = System.Math.Sin(Yaw); double cosPitch = System.Math.Cos(-Pitch); double sinPitch = System.Math.Sin(-Pitch); double cosRoll = System.Math.Cos(Roll); double sinRoll = System.Math.Sin(Roll); X.Rotate(Y, cosYaw, sinYaw); Z.Rotate(Y, cosYaw, sinYaw); Y.Rotate(X, cosPitch, sinPitch); Z.Rotate(X, cosPitch, sinPitch); X.Rotate(Z, cosRoll, sinRoll); Y.Rotate(Z, cosRoll, sinRoll); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { Vector3 moveControl = new Vector3(0, 0, 0); //Vector3.zero; if (e.KeyCode == Keys.W) { moveControl.z += 1; } if (e.KeyCode == Keys.S) { moveControl.z += -1; } if (e.KeyCode == Keys.D) { moveControl.x += 1; } if (e.KeyCode == Keys.A) { moveControl.x += -1; } if (e.KeyCode == Keys.Down) { rot_up -= 0.2f; } if (e.KeyCode == Keys.Up) { rot_up += 0.2f; } if (e.KeyCode == Keys.Space) { pointOfView.y += 1; } if (e.KeyCode == Keys.ShiftKey) { pointOfView.y -= 1; } if (e.KeyCode == Keys.Right) { rot_side -= 0.2f; } if (e.KeyCode == Keys.Left) { rot_side += 0.2f; } if (e.KeyCode == Keys.R) { drawnObject.Position = pointOfView * 1; drawnObject.Position.y -= 01f; } pointOfView += moveControl.Rotate(rot_side, rot_up); UpdateScreen(); }
public void UpdateVisualWheels() { WheelCollider.GetWorldPose(out Vector3 pos, out Quaternion quat); float offset = (Vehicle.transform.InverseTransformPoint(pos) - transform.localPosition).magnitude; VisualWheel.position = Vehicle.transform.TransformPoint(_visualWheelDefaultVehiclePosition + upDirection * offset); Vector3 worldUpDirection = Vehicle.transform.TransformDirection(upDirection); Vector3 worldDefaultDirection = Vehicle.transform.TransformDirection(defaultDirection); Quaternion desiredRotation = Quaternion.LookRotation(worldDefaultDirection.Rotate(steerAngle, worldUpDirection), worldUpDirection); transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, 5f * Time.deltaTime); }
public void Rotate() { var v0 = new Vector3(0, 0, -1); var angle = 45.0.ToRad(); v0.Rotate(angle, new Vector3(1, 0, 0)); var targ_y = 1.0 * Math.Sin(angle); var targ_z = -1.0 * Math.Cos(angle); Assert.AreEqual(v0.Y, targ_y, 1e-8); Assert.AreEqual(v0.Z, targ_z, 1e-8); }
private void MoveSelectionByArrows(Vector3 vector3) { Vector3 angles = PlayerController.gameObject.transform.eulerAngles; var rotation90 = Mathf.RoundToInt(angles.y / 90f) * 90; vector3 = vector3.Rotate(0, rotation90, 0); Vector3Int offset = Vector3Int.RoundToInt(vector3); MoveObjects(offset); moveGizmo.SetPosition(selectionGizmo.selectionFilter.GetCenter()); }
public override void Update() { var delta = Engine.Get().Delta; _factorDay = _driverDay.Update(delta); _skyboxRotation = new Vector3(360.0f * _factorDay, 0.0f, 0.0f); var lightDirection = _skyboxRotation.Rotate(new Vector3(0.2f, 0.0f, 0.5f)); lightDirection.Normalize(); var fogColour = FogColourSunrise.Interpolate(FogColourNight, SunriseFactor); fogColour = fogColour.Interpolate(FogColourDay, ShadowFactor); _sunPosition = lightDirection * new Vector3(-6048.0f, -6048.0f, -6048.0f); _moonPosition = lightDirection * new Vector3(6048.0f, 6048.0f, 6048.0f); /*if (Scenes.Get().GetCamera() != null) * { * _sunPosition += Scenes.Get().Camera.Position; * _moonPosition += Scenes.Get().Camera.Position; * }*/ _sunColour = SunColourSunrise.Interpolate(SunColourNight, SunriseFactor); _sunColour = _sunColour.Interpolate(SunColourDay, ShadowFactor); _moonColour = MoonColourNight.Interpolate(MoonColourDay, ShadowFactor); _fog.Colour = fogColour; _fog.Density = 0.002f + ((1.0f - ShadowFactor * 0.002f)); _fog.Gradient = 2.0f - ((1.0f - ShadowFactor) * 0.380f); _fog.LowerLimit = 0.0f; _fog.UpperLimit = 0.15f - ((1.0f - ShadowFactor) * 0.03f); _skyColour = SkyboxColourDay; if (Shadows.Get() != null) { Shadows.Get().LightDirection = lightDirection; Shadows.Get().ShadowBoxOffset = (4.0f * (1.0f - ShadowFactor)) + 10.0f; Shadows.Get().ShadowBoxDistance = 40.0f; Shadows.Get().ShadowTransition = 5.0f; Shadows.Get().ShadowDarkness = 0.6f * ShadowFactor; } _factorSunrise = Math.Clamp(-((float)Math.Sin(2.0f * Math.PI * DayFactor) - 1.0f) / 2.0f, 0.0f, 1.0f); _factorShadow = Math.Clamp(1.7f * (float)Math.Sin(2.0f * Math.PI * DayFactor), 0.0f, 1.0f);; _sunHeight = _sunPosition.Y; _starIntensity = Math.Clamp(1.0f - ShadowFactor, 0.0f, 1.0f); }
public void Vector3RotationTest() { Vector3 a = new Vector3(1, 0, 0); a.Rotate(180); Assert.AreEqual(-1f, a.X); a = new Vector3(1, 0, 0); a.RotateRadians(MathF.PI); Assert.AreEqual(-1f, a.X); }
protected override Vector3 GetRollDir() { Vector3 targetPos = Vector3.zero; bool found = false; if (Agent.BlackBoard.desiredTarget != null) { targetPos = Agent.Position - Agent.BlackBoard.desiredTarget.Position; targetPos = Agent.Position + (targetPos.normalized * Agent.BlackBoard.rollDistance); // 尝试N次 for (int i = 0; i < 10; ++i) { // 随机角度 int degree = Random.Range(0, 2) == 0 ? 1 : -1; degree *= Random.Range(0, 60); targetPos = targetPos.Rotate(Vector3.up, degree); if (CheckTargetPos(targetPos)) { found = true; break; } targetPos = targetPos.Rotate(Vector3.up, -degree); if (CheckTargetPos(targetPos)) { found = true; break; } } } if (found == false) { return(Vector3.zero); } return((targetPos - Agent.Position).normalized); }
public CompassDirection? VectorToDirection( Vector3 vec ) { vec.Normalize(); vec = vec.Rounded(); if ( UpVec == vec ) return CompassDirection.North; vec = vec.Rotate( Normal, MathHelper.PiOver2 ).Rounded(); if ( UpVec == vec ) return CompassDirection.East; vec = vec.Rotate( Normal, MathHelper.PiOver2 ).Rounded(); if ( UpVec == vec ) return CompassDirection.South; vec = vec.Rotate( Normal, MathHelper.PiOver2 ).Rounded(); if ( UpVec == vec ) return CompassDirection.West; return null; }
private Vector2 Transform3dTo2d( Vector3 vec3d, Face cubeFace ) { vec3d = vec3d.Rotate( cubeFace.Normal, -cubeFace.Rotation ) .Transform( VectorUtils.RotateOnto_Q( cubeFace.Normal, Vector3.UnitZ ) ); return new Vector2( vec3d.X, -vec3d.Y ); }
public Vector2 Transform3dTo2d( Vector3 vec3d ) { vec3d = vec3d.Rotate( Normal, -Rotation ) .Transform( VectorUtils.RotateOnto_Q( Normal, Vector3.UnitZ ) ); return new Vector2( vec3d.X, -vec3d.Y ); }