本文整理汇总了C#中Vector3.IsZero方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.IsZero方法的具体用法?C# Vector3.IsZero怎么用?C# Vector3.IsZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.IsZero方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Optimize
public bool Optimize(IList<RCSWrapper> engines, Vector3 needed_torque)
{
var num_engines = engines.Count;
var zero_torque = needed_torque.IsZero();
TorqueAngle = TorqueError = -1f;
float error, angle;
var last_error = -1f;
Vector3 cur_imbalance, target;
for(int i = 0; i < RCS.MaxIterations; i++)
{
//calculate current errors and target
cur_imbalance = Vector3.zero;
for(int j = 0; j < num_engines; j++)
{ var e = engines[j]; cur_imbalance += e.Torque(e.limit); }
angle = zero_torque? 0f : Vector3.Angle(cur_imbalance, needed_torque);
target = needed_torque-cur_imbalance;
error = VSL.Torque.AngularAcceleration(target).magnitude;
//remember the best state
if(angle <= 0f && error < TorqueError || angle < TorqueAngle || TorqueAngle < 0)
{
for(int j = 0; j < num_engines; j++)
{ var e = engines[j]; e.best_limit = e.limit; }
TorqueAngle = angle;
TorqueError = error;
}
//check convergence conditions
if(error < RCS.OptimizationTorqueCutoff*RCS.OptimizationPrecision ||
last_error > 0 && Mathf.Abs(error-last_error) < RCS.OptimizationPrecision*last_error)
break;
last_error = error;
//normalize limits before optimization
var limit_norm = 0f;
for(int j = 0; j < num_engines; j++)
{
var e = engines[j];
if(limit_norm < e.limit) limit_norm = e.limit;
}
if(limit_norm > 0)
{
for(int j = 0; j < num_engines; j++)
{ var e = engines[j]; e.limit = Mathf.Clamp01(e.limit / limit_norm); }
}
if(!optimization_pass(engines, num_engines, target, error, RCS.OptimizationPrecision))
break;
}
var optimized = TorqueError < RCS.OptimizationTorqueCutoff ||
(!zero_torque && TorqueAngle < RCS.OptimizationAngleCutoff);
//treat single-engine crafts specially
if(num_engines == 1)
engines[0].limit = optimized? 1f : 0f;
else //restore the best state
for(int j = 0; j < num_engines; j++)
{ var e = engines[j]; e.limit = e.best_limit; }
return optimized;
}
示例2: FindCollisionAndNormal
/// <summary>
/// 指定の方向ベクトルについての衝突情報とその衝突法線ベクトルを探します。
/// </summary>
/// <param name="direction">判定する方向ベクトル。</param>
/// <param name="resultCollision">衝突情報 (JigLibX)。</param>
/// <param name="resultNormal">衝突法線ベクトル。</param>
void FindCollisionAndNormal(ref Vector3 direction, out CollisionInfo resultCollision, out Vector3? resultNormal)
{
resultCollision = null;
resultNormal = null;
if (direction.IsZero()) return;
// 衝突リストから指定された検査方向ベクトルの逆ベクトルを
// 衝突法線ベクトルとする CollisionSkin を探します。
// 逆ベクトルと法線ベクトルの一致性は、
// その内積結果が一定の範囲内である場合に一致とみなします。
var dir = -direction;
dir.Normalize();
foreach (var collision in Collisions)
{
var normal = collision.DirToBody0;
if (collision.SkinInfo.Skin1 == this)
{
Vector3.Negate(ref normal, out normal);
}
float nDotDir;
Vector3.Dot(ref normal, ref dir, out nDotDir);
if (0.7f < nDotDir)
{
resultCollision = collision;
resultNormal = normal;
break;
}
}
}
示例3: UpdatePosition
protected override Vector3 UpdatePosition()
{
vectorSum = Vector3.zero;
totalMass = 0f;
EditorUtils.RunOnAllParts (calculateCoM);
if (vectorSum.IsZero ()) {
return vectorSum;
}
return vectorSum / totalMass;
}
示例4: Update
public override void Update()
{
Steering = new Vector3(vessel.ctrlState.pitch, vessel.ctrlState.roll, vessel.ctrlState.yaw);
Translation = new Vector3(vessel.ctrlState.X, vessel.ctrlState.Z, vessel.ctrlState.Y);
if(!Steering.IsZero()) Steering = Steering/Steering.CubeNorm().magnitude;
if(!Translation.IsZero()) Translation = Translation/Translation.CubeNorm().magnitude;
TranslationAvailable = VSL.Engines.Maneuver.Count > 0 || VSL.Engines.NumActiveRCS > 0;
}
示例5: Update
public override void Update(GameTime gameTime)
{
if (!camera.Active) return;
var dt = gameTime.GetDeltaTime();
var newPosition = camera.Position;
var newOrientation = camera.Orientation;
var deltaRotation = new Vector2();
var mouse = InputDevice.GetMouse();
if (mouse.IsMouseMoved)
{
deltaRotation.X += mouse.DeltaX;
deltaRotation.Y += mouse.DeltaY;
mouse.ResetPosition();
}
var pad = InputDevice.GetGamePad(PlayerIndex);
{
const float padRotationAmount = 10.0f;
var stickPosition = pad.CurrentState.ThumbSticks.Right;
deltaRotation.X += stickPosition.X * padRotationAmount;
deltaRotation.Y += -stickPosition.Y * padRotationAmount;
}
{
float yaw;
float pitch;
float roll;
camera.Orientation.ToYawPitchRoll(out yaw, out pitch, out roll);
yaw -= RotationVelocity * deltaRotation.X * dt % (2 * MathHelper.Pi);
pitch -= RotationVelocity * deltaRotation.Y * dt;
if (MathHelper.PiOver2 < pitch)
{
pitch = MathHelper.PiOver2;
}
else if (pitch < -MathHelper.PiOver2)
{
pitch = -MathHelper.PiOver2;
}
newOrientation = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);
}
var moveDirection = new Vector3(0, 0, 0);
var keyboard = InputDevice.GetKeybord(PlayerIndex);
if (keyboard.IsKeyDown(Keys.W))
{
moveDirection.Z = -1;
}
if (keyboard.IsKeyDown(Keys.S))
{
moveDirection.Z = 1;
}
if (keyboard.IsKeyDown(Keys.D))
{
moveDirection.X = 1;
}
if (keyboard.IsKeyDown(Keys.A))
{
moveDirection.X = -1;
}
if (keyboard.IsKeyDown(Keys.Q))
{
moveDirection.Y = 1;
}
if (keyboard.IsKeyDown(Keys.Z))
{
moveDirection.Y = -1;
}
{
var delta = pad.CurrentState.ThumbSticks.Left;
moveDirection.X += delta.X;
moveDirection.Z += -delta.Y;
if (pad.IsButtonDown(Buttons.LeftShoulder))
{
moveDirection.Y += 1;
}
if (pad.IsButtonDown(Buttons.RightShoulder))
{
moveDirection.Y += -1;
}
}
if (!moveDirection.IsZero())
{
moveDirection.Normalize();
newPosition += MoveVelocity * dt * Vector3.Transform(moveDirection, newOrientation);
}
camera.Position = newPosition;
camera.Orientation = newOrientation;
//.........这里部分代码省略.........
示例6: OptimizeLimitsForTorque
public bool OptimizeLimitsForTorque(IList<EngineWrapper> engines, Vector3 needed_torque, out float max_limit)
{
var num_engines = engines.Count;
var zero_torque = needed_torque.IsZero();
TorqueAngle = TorqueError = -1f;
float error, angle;
var last_error = -1f;
Vector3 cur_imbalance = VSL.Torque.Engines.Torque, target;
// Log("=============================== Optimization ===============================\n" +
// "needed_torque {}\n" +
// "OnPlanet.VSF {}, GeeVSF {}, MaxTWR {}\n" +
// "Physics.M {}, G {}\n" +
// "Engines.MaxThrust {}\n" +
// "Control.AttitudeError {}, InvFactor {}\n",
// needed_torque,
// VSL.OnPlanetParams.VSF, VSL.OnPlanetParams.GeeVSF, VSL.OnPlanetParams.MaxTWR,
// VSL.Physics.M, VSL.Physics.G,
// VSL.Engines.MaxThrust,
// VSL.Controls.AttitudeError, VSL.Controls.InvAlignmentFactor);//debug
for(int i = 0; i < ENG.MaxIterations; i++)
{
//calculate current errors and target
cur_imbalance = VSL.Torque.Engines.Torque;
for(int j = 0; j < num_engines; j++)
{ var e = engines[j]; cur_imbalance += e.Torque(e.throttle * e.limit); }
angle = zero_torque? 0f : Vector3.Angle(cur_imbalance, needed_torque);
target = needed_torque-cur_imbalance;
error = VSL.Torque.AngularAcceleration(target).magnitude;
//remember the best state
if(angle <= 0f && error < TorqueError || angle+error < TorqueAngle+TorqueError || TorqueAngle < 0)
{
for(int j = 0; j < num_engines; j++)
{ var e = engines[j]; e.best_limit = e.limit; }
TorqueAngle = angle;
TorqueError = error;
}
//check convergence conditions
if(error < ENG.OptimizationTorqueCutoff*ENG.OptimizationPrecision ||
last_error > 0 && Mathf.Abs(error-last_error) < ENG.OptimizationPrecision*last_error)
break;
last_error = error;
//normalize limits of main and balanced engines before optimization
var limit_norm = 0f;
for(int j = 0; j < num_engines; j++)
{
var e = engines[j];
if(e.Role == TCARole.MANEUVER) continue;
if(limit_norm < e.limit) limit_norm = e.limit;
}
if(limit_norm > 0)
{
for(int j = 0; j < num_engines; j++)
{
var e = engines[j];
if(e.Role == TCARole.MANEUVER) continue;
e.limit = Mathf.Clamp01(e.limit / limit_norm);
}
}
//optimize limits
if(!optimization_for_torque_pass(engines, num_engines, target, error, ENG.OptimizationPrecision))
break;
}
var optimized = TorqueError < ENG.OptimizationTorqueCutoff ||
(!zero_torque && TorqueAngle < ENG.OptimizationAngleCutoff);
// Log("num engines {}, optimized {}, TorqueError {}, TorqueAngle {}\nneeded torque {}\ncurrent turque {}\nlimits:\n{}\n" +
// "-------------------------------------------------------------------------------------------------",
// num_engines, optimized, TorqueError, TorqueAngle, needed_torque, cur_imbalance,
// engines.Aggregate("", (s, e) => s+string.Format("{0}: VSF {1:P1}, throttle {2:P1}, best limit {3:P1}\n",
// e.name, e.VSF, e.throttle, e.best_limit)));//debug
//treat single-engine crafts specially
if(num_engines == 1)
{
engines[0].limit = optimized? engines[0].best_limit : 0f;
max_limit = engines[0].limit;
}
else //restore the best state
{
max_limit = 0;
for(int j = 0; j < num_engines; j++)
{
var e = engines[j];
e.limit = e.best_limit;
if(e.limit > max_limit)
max_limit = e.limit;
}
}
return optimized;
}
示例7: compute_steering
protected void compute_steering(Vector3 current, Vector3 needed)
{
#if DEBUG
if(current.IsZero() || needed.IsZero())
LogFST("compute steering:\ncurrent {}\nneeded {}\ncurrent thrust {}", current, needed, VSL.Engines.CurrentThrustDir);
#endif
VSL.Controls.SetAttitudeError(Vector3.Angle(needed, current));
if(VSL.Controls.AttitudeError > ATCB.AngleThreshold)
{
//rotational axis
var current_maxI = current.MaxI();
var axis = Vector3.Cross(needed, current).Exclude(current_maxI);
if(axis.sqrMagnitude < 0.01f)
axis = VSL.Torque.MaxCurrent.AA.Exclude(current_maxI).MaxComponentV();
//main rotation component
var axis1 = axis.MaxComponentV();
var current_cmp1 = Vector3.ProjectOnPlane(current, axis1);
var needed_cmp1 = Vector3.ProjectOnPlane(needed, axis1);
var angle1 = Vector3.Angle(needed_cmp1, current_cmp1);
//second rotation component
var axis2 = (axis - axis1).MaxComponentV();
var angle2 = Vector3.Angle(needed, needed_cmp1);
//steering
steering = (axis1.normalized * angle1 +
axis2.normalized * angle2) * Mathf.Deg2Rad;
// LogF("\ncurrent_maxI: {}\n" +
// "axis: {}\n" +
// "axis1: {}\n" +
// "axis2: {}\n" +
// "current_cmp1: {}\n" +
// "needed_cmp1: {}\n" +
// "angle1: {}\n" +
// "angle2: {}\n",
// current_maxI, axis, axis1, axis2, current_cmp1, needed_cmp1, angle1, angle2);//debug
}
else steering = rotation2steering(Quaternion.FromToRotation(needed, current));
// LogF("\nneeded {}\ncurrent {}\nangle {}\nsteering {}",
// needed, current, Vector3.Angle(needed, current), DebugUtils.FormatSteering(steering));//debug
//FIXME: sometimes generates NaN
// needed (2.309423E+09, -5.479368E+11, -2.858228E+11); |v| = 6.180087E+11
// current (-0.0680542, -28.58647, -718.0868); |v| = 718.6556
// angle 60.17245 > threshold
// steering [pitch NaN, roll NaN, yaw NaN]
}