本文整理汇总了C#中UnityEngine.Vector2.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.Rotate方法的具体用法?C# Vector2.Rotate怎么用?C# Vector2.Rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Vector2
的用法示例。
在下文中一共展示了Vector2.Rotate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateVelocity
//.........这里部分代码省略.........
bestPos[j] = samplePos[i];
break;
}
}
}
if (score < bestEverScore)
{
bestEver = samplePos[i];
bestEverScore = score;
if (score == 0)
{
sub = 100;
break;
}
}
}
samplePosCount = 0;
for (int i = 0; i < KeepCount; i++)
{
Vector2 p = bestPos[i];
float s = bestSizes[i];
bestScores[i] = float.PositiveInfinity;
const float Half = 0.6f;
float offset = s * Half * 0.5f;
samplePos[samplePosCount + 0] = (p + new Vector2(+offset, +offset));
samplePos[samplePosCount + 1] = (p + new Vector2(-offset, +offset));
samplePos[samplePosCount + 2] = (p + new Vector2(-offset, -offset));
samplePos[samplePosCount + 3] = (p + new Vector2(+offset, -offset));
s *= s * Half;
sampleSize[samplePosCount + 0] = (s);
sampleSize[samplePosCount + 1] = (s);
sampleSize[samplePosCount + 2] = (s);
sampleSize[samplePosCount + 3] = (s);
samplePosCount += 4;
}
}
result = bestEver;
}
if (DebugDraw) DrawCross(result + position2D);
newVelocity = To3D(Vector2.ClampMagnitude(result, maxSpeed));
if (newVelocity != Vector3.zero)
{
float angle = Vector3.Angle(DesiredVelocity, newVelocity);
//:限制新速度方向
//如果计算出来的新速度是与设计速度的夹角大于angleMax
//则新速度旋转到最大夹角
float angleMax = 45;
if (angle > angleMax)
{
Vector2 firstObject = new Vector2(DesiredVelocity.x, DesiredVelocity.z);
Vector2 secondObject = new Vector2(newVelocity.x, newVelocity.z);
float det = firstObject.x * secondObject.y - firstObject.y * secondObject.x;
if (det > 0)//param2 is unclockwise
{
Vector2 verticalObject = secondObject.Rotate(-(angle - angleMax));
newVelocity.x = verticalObject.x;
newVelocity.z = verticalObject.y;
if (newVelocity.magnitude < minSpeed)
{
newVelocity = newVelocity.normalized * minSpeed;
}
}
else if (det < 0)
{
Vector2 verticalObject = secondObject.Rotate((angle - angleMax));
newVelocity.x = verticalObject.x;
newVelocity.z = verticalObject.y;
if (newVelocity.magnitude < minSpeed)
{
newVelocity = newVelocity.normalized * minSpeed;
}
}
else
{
newVelocity = Vector3.zero;
}
}
if (printVelocity)
{
Debug.Log("vel " + velocity + "newVelocity " + newVelocity);
}
}
}
示例2: RelativeToWorld
public Vector2 RelativeToWorld(Vector2 vector)
{
return vector.Rotate(Angle - 90);
}
示例3: WorldToRelative
public Vector2 WorldToRelative(Vector2 vector)
{
return vector.Rotate(-Angle + 90);
}
示例4: CreateRotated
int[][][] CreateRotated(int[][] pixels, ref int w, ref int h, int count)
{
var pw = w;
var ph = h;
var pcx = w / 2;
var pcy = h / 2;
w = Mathf.RoundToInt(w * 1.5f / 2) * 2;
h = Mathf.RoundToInt(h * 1.5f / 2) * 2;
var cx = w / 2;
var cy = h / 2;
var _w = w;
var _h = h;
var offset = new Vector2();
return count.Range().Select(ai =>
{
var angle = (float)ai * 360 / count;
return _h.Range().Select(y =>
{
return _w.Range().Select(x =>
{
offset.x = x - cx;
offset.y = y - cy;
offset = offset.Rotate(angle);
var px = Mathf.RoundToInt(offset.x + pcx);
var py = Mathf.RoundToInt(offset.y + pcy);
if (px < 0 || px >= pw || py < 0 || py >= ph)
{
return 0;
}
return pixels[py][px];
}).ToArray();
}).ToArray();
}).ToArray();
}