本文整理汇总了C#中Vector2d.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2d.Normalize方法的具体用法?C# Vector2d.Normalize怎么用?C# Vector2d.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2d
的用法示例。
在下文中一共展示了Vector2d.Normalize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simulate
public override void Simulate()
{
if (IsMoving) {
MovementDirection = Destination - Body.Position;
long distance;
MovementDirection.Normalize (out distance);
if (distance > closingDistance) {
Body.Velocity += (MovementDirection * timescaledSpeed - Body.Velocity) * SteeringWeight;
} else {
Body.Velocity += (MovementDirection * ((timescaledSpeed * distance) / (closingDistance)) - Body.Velocity) * SteeringWeight;
if (distance < ((closingDistance * closingDistanceMultiplier) >> FixedMath.SHIFT_AMOUNT)) {
StopMove ();
}
}
Body.VelocityChanged = true;
}
else {
if (TouchingObjects.Count > 0) Body.Velocity /= TouchingObjects.Count;
Body.Velocity -= Body.Velocity * SteeringWeight;
StopTime++;
}
TouchingObjects.FastClear ();
}
示例2: Simulate
public override void Simulate()
{
if (IsMoving) {
if (RepathCount <= 0) {
if (ViableDestination) {
if (Pathfinder.GetPathNode (Body.Position.x, Body.Position.y, out CurrentNode)) {
if (StraightPath) {
if (Pathfinder.NeedsPath (CurrentNode, DestinationNode)) {
if (Pathfinder.FindPath (Destination, CurrentNode, DestinationNode, MyPath)) {
HasPath = true;
PathIndex = 0;
} else {
if (IsFormationMoving) {
StartMove (MyMovementGroup.Destination);
IsFormationMoving = false;
}
}
StraightPath = false;
RepathCount = RepathRate;
} else {
RepathCount = StraightRepathRate;
}
} else {
if (Pathfinder.NeedsPath (CurrentNode, DestinationNode)) {
if (Pathfinder.FindPath (Destination, CurrentNode, DestinationNode, MyPath)) {
HasPath = true;
PathIndex = 0;
} else {
if (IsFormationMoving) {
StartMove (MyMovementGroup.Destination);
IsFormationMoving = false;
}
}
RepathCount = RepathRate;
} else {
StraightPath = true;
RepathCount = StraightRepathRate;
}
}
}
else {
}
} else {
HasPath = false;
if (IsFormationMoving) {
StartMove (MyMovementGroup.Destination);
IsFormationMoving = false;
}
}
} else {
if (HasPath) {
RepathCount--;
} else {
RepathCount--;
}
}
if (StraightPath) {
TargetPos = Destination;
} else if (HasPath) {
if (PathIndex >= MyPath.Count)
PathIndex = MyPath.Count - 1;
TargetPos = MyPath [PathIndex];
} else {
TargetPos = Destination;
}
MovementDirection = TargetPos - Body.Position;
MovementDirection.Normalize (out distance);
if (TargetPos.x != LastTargetPos.x || TargetPos.y != LastTargetPos.y) {
LastTargetPos = TargetPos;
TargetDirection = MovementDirection;
}
if (PathIndex + 1 >= MyPath.Count) {
if (distance > closingDistance) {
Body.Velocity += (MovementDirection * timescaledSpeed - Body.Velocity) * SteeringWeight;
} else {
Body.Velocity += (MovementDirection * ((timescaledSpeed * distance) / (closingDistance)) - Body.Velocity) * SteeringWeight;
if (distance < ((closingDistance * closingDistanceMultiplier) >> FixedMath.SHIFT_AMOUNT)) {
StopMove ();
}
}
} else {
Body.Velocity += (MovementDirection * timescaledSpeed - Body.Velocity) * SteeringWeight;
if (distance <= closingDistance) {
PathIndex++;
}
}
Body.VelocityChanged = true;
} else {
if (Body.VelocityMagnitude > 0) {
Body.Velocity -= Body.Velocity * SteeringWeight;
Body.VelocityChanged = true;
}
StopTime++;
}
//.........这里部分代码省略.........
示例3: StartTurn
public void StartTurn(Vector2d targetRotation)
{
TargetRotation = targetRotation;
TargetRotation.Normalize();
TargetReached = false;
}
示例4: OnSimulate
protected override void OnSimulate()
{
if (!CanMove) {
return;
}
if (IsMoving) {
if (canPathfind) {
if (repathCount <= 0) {
if (viableDestination) {
if (Pathfinder.GetPathNode(cachedBody.Position.x, cachedBody.Position.y, out currentNode)) {
if (straightPath) {
if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode)) {
if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath)) {
hasPath = true;
pathIndex = 0;
} else {
if (IsFormationMoving) {
StartMove(MyMovementGroup.Destination);
IsFormationMoving = false;
}
}
straightPath = false;
repathCount = RepathRate;
} else {
repathCount = StraightRepathRate;
}
} else {
if (forcePathfind || Pathfinder.NeedsPath(currentNode, destinationNode)) {
if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath)) {
hasPath = true;
pathIndex = 0;
} else {
if (IsFormationMoving) {
StartMove(MyMovementGroup.Destination);
IsFormationMoving = false;
}
}
repathCount = RepathRate;
} else {
straightPath = true;
repathCount = StraightRepathRate;
}
}
} else {}
} else {
hasPath = false;
if (IsFormationMoving) {
StartMove(MyMovementGroup.Destination);
IsFormationMoving = false;
}
}
} else {
if (hasPath) {
repathCount--;
} else {
repathCount--;
}
}
if (straightPath) {
targetPos = Destination;
} else if (hasPath) {
if (pathIndex >= myPath.Count) {
pathIndex = myPath.Count - 1;
}
targetPos = myPath[pathIndex];
} else {
targetPos = Destination;
}
} else {
targetPos = Destination;
}
movementDirection = targetPos - cachedBody.Position;
movementDirection.Normalize(out distance);
if (targetPos.x != lastTargetPos.x || targetPos.y != lastTargetPos.y) {
lastTargetPos = targetPos;
targetDirection = movementDirection;
}
if (distance > closingDistance) {
desiredVelocity = (movementDirection);
if (movementDirection.Cross (lastMovementDirection.x, lastMovementDirection.y) != 0)
{
lastMovementDirection = movementDirection;
cachedTurn.StartTurnRaw (movementDirection);
}
} else {
if (distance < FixedMath.Mul (closingDistance, CollisionStopMultiplier)) {
Arrive();
return;
}
desiredVelocity = (movementDirection * (distance) / (closingDistance));
}
desiredVelocity *= timescaledSpeed;
cachedBody._velocity += (desiredVelocity - cachedBody._velocity) * timescaledAcceleration;
if (distance <= closingDistance) {
pathIndex++;
//.........这里部分代码省略.........
示例5: Advect
private void Advect(double dt)
{
for (int i = 0; i < max_x; i++)
{
for (int j = 0; j < max_y; j++)
{
double vel_x = (u_x[i, j] + u_x[i + 1, j]) / 2;
double vel_y = (u_y[i, j] + u_y[i, j + 1]) / 2;
double old_x = i - dt * vel_x;
double old_y = j - dt * vel_y;
int old_i = (int)old_x;
int old_j = (int)old_y;
double offset_i = old_x - old_i;
double offset_j = old_y - old_j;
// this skips for now but really old_i and old_j should be clamped
if (old_i < 0 || old_j < 0 || old_i + 1 >= max_x || old_j + 1 >= max_y) continue;
//Advects temperature, density
cells[i, j].SetInterpolatedValues(cells[old_i, old_j], cells[old_i, old_j + 1], cells[old_i + 1, old_j], cells[old_i + 1, old_j + 1], offset_i, offset_j);
// deal with implicit surfaces
if (i <= 0 || j <= 0 || i + 2 >= max_x || j + 2 >= max_y) continue;
Vector2d normal = new Vector2d(cells[i + 1, j].ImplicitSurface - cells[i - 1, j].ImplicitSurface, cells[i, j + 1].ImplicitSurface - cells[i, j - 1].ImplicitSurface);
normal.Normalize();
double w_x = vel_x + FluidConstants.BLUE_CORE_EMISSION_RATE * normal.X;
double w_y = vel_y + FluidConstants.BLUE_CORE_EMISSION_RATE * normal.Y;
cells[i, j].ImplicitSurface -= timestep * (w_x * (cells[i - 1, j].ImplicitSurface - cells[i, j].ImplicitSurface) + w_y * (cells[i, j - 1].ImplicitSurface - cells[i, j].ImplicitSurface));
if (cells[i, j].ImplicitSurface > 0)
cells[i, j].Density = 100;
else
cells[i, j].Density = 10;
}
}
}
示例6: TurnDirection
public void TurnDirection(Vector2d targetDirection)
{
targetDirection.Normalize ();
StartTurn (targetDirection);
}