本文整理汇总了C#中Vec2.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Vec2.Length方法的具体用法?C# Vec2.Length怎么用?C# Vec2.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec2
的用法示例。
在下文中一共展示了Vec2.Length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Move
public Vec2 Move(Human LeMe, IEnumerable<Human> NearestNeighbours)
{
if ((LeMe.Node - LeMe.Position).Length() > 100.0f)
{
LeMe.Node = this.GetNewTarget(LeMe);
if (LeMe.HumanType == HumanType.Agent)
{
LeMe.MovementBehaviour = new AgentMovementBehaviour();
}
else
{
LeMe.MovementBehaviour = new UsualMovementBehaviour();
}
}
this.velocity = LeMe.Node - LeMe.Position;
this.velocity.Mul(-1.0f);
this.velocity.Mul(1.0f / this.velocity.Length());
this.velocity.Mul(this.speed);
foreach (var human in NearestNeighbours.Where(Human => Human.Position != LeMe.Position && !(Human.HumanType != HumanType.Agent && LeMe.HumanType == HumanType.Victim)))
{
this.distance = human.Position - LeMe.Position;
var num = this.distance.Length();
distance.Mul(1.0f / distance.Length());
distance.Mul(1.7f);
if (!(num <= 15.0f))
{
continue;
}
num = 15.0f - num;
num /= 15.0f;
this.distance.Mul(num * -1f);
this.distance.Mul(3.5f);
this.velocity += this.distance;
this.distance = human.Position - LeMe.Position;
}
this.velocity.Mul(1.0f / this.velocity.Length());
this.velocity.Mul(this.speed);
LeMe.Position = LeMe.Position + this.velocity;
return LeMe.Position;
}
示例2: Move
public Vec2 Move(Human LeMe, IEnumerable<Human> NearestNeighbours)
{
LeMe.Node = LeMe.Victim.Position;
if ((LeMe.Node - LeMe.Position).Length() < 14f)
{
LeMe.Victim.Kill();
}
this.velocity = LeMe.Node - LeMe.Position;
this.velocity.Mul(1.0f / this.velocity.Length());
this.velocity.Mul(this.speed);
foreach (var human in NearestNeighbours.Where(Human => Human.Position != LeMe.Position && !(Human.HumanType != HumanType.Agent && LeMe.HumanType == HumanType.Victim)))
{
this.distance = human.Position - LeMe.Position;
var num = this.distance.Length();
distance.Mul(1.0f / distance.Length());
distance.Mul(1.7f);
if (!(num <= 15.0f))
{
continue;
}
num = 15.0f - num;
num /= 15.0f;
this.distance.Mul(num * -1f);
this.distance.Mul(3.5f);
this.velocity += this.distance;
this.distance = human.Position - LeMe.Position;
}
this.velocity.Mul(1.0f / this.velocity.Length());
this.velocity.Mul(this.speed);
LeMe.Position = LeMe.Position + this.velocity;
return LeMe.Position;
}
示例3: UpdateGeometry
private unsafe void UpdateGeometry(float time)
{
//generate geometry
Vertex[] vertices = new Vertex[tesselation * tesselation];
ushort[] indices = new ushort[(tesselation - 1) * (tesselation - 1) * 6];
{
//vertices
int vertexPosition = 0;
for (int y = 0; y < tesselation; y++)
{
for (int x = 0; x < tesselation; x++)
{
Vertex vertex = new Vertex();
Vec2 pos2 = new Vec2(
(float)x / (float)(tesselation - 1) - .5f,
(float)y / (float)(tesselation - 1) - .5f);
float posZ = MathFunctions.Sin(pos2.Length() * 30 - time * 2) / 2;
MathFunctions.Clamp(ref posZ, -5f, .5f);
vertex.position = new Vec3(pos2.X, pos2.Y, posZ) * Scale;
vertex.normal = Vec3.Zero;
vertex.texCoord = new Vec2(pos2.X + .5f, pos2.Y + .5f);
//vertex.tangents = Vec4.Zero;
vertices[vertexPosition] = vertex;
vertexPosition++;
}
}
//indices
int indexPosition = 0;
for (int y = 0; y < tesselation - 1; y++)
{
for (int x = 0; x < tesselation - 1; x++)
{
indices[indexPosition] = (ushort)(tesselation * y + x);
indexPosition++;
indices[indexPosition] = (ushort)(tesselation * y + x + 1);
indexPosition++;
indices[indexPosition] = (ushort)(tesselation * (y + 1) + x + 1);
indexPosition++;
indices[indexPosition] = (ushort)(tesselation * (y + 1) + x + 1);
indexPosition++;
indices[indexPosition] = (ushort)(tesselation * (y + 1) + x);
indexPosition++;
indices[indexPosition] = (ushort)(tesselation * y + x);
indexPosition++;
}
}
//calculate vertex normals
fixed (Vertex* pVertices = vertices)
{
int triangleCount = indices.Length / 3;
for (int n = 0; n < triangleCount; n++)
{
int index0 = indices[n * 3 + 0];
int index1 = indices[n * 3 + 1];
int index2 = indices[n * 3 + 2];
Vec3 pos0 = pVertices[index0].position;
Vec3 pos1 = pVertices[index1].position;
Vec3 pos2 = pVertices[index2].position;
Vec3 normal = Vec3.Cross(pos1 - pos0, pos2 - pos0);
normal.Normalize();
pVertices[index0].normal += normal;
pVertices[index1].normal += normal;
pVertices[index2].normal += normal;
}
//normalize
for (int n = 0; n < vertices.Length; n++)
pVertices[n].normal = pVertices[n].normal.GetNormalize();
}
}
SubMesh subMesh = mesh.SubMeshes[0];
//copy data to vertex buffer
{
HardwareVertexBuffer vertexBuffer = subMesh.VertexData.VertexBufferBinding.GetBuffer(0);
IntPtr buffer = vertexBuffer.Lock(HardwareBuffer.LockOptions.Discard);
fixed (Vertex* pVertices = vertices)
{
NativeUtils.CopyMemory(buffer, (IntPtr)pVertices, vertices.Length * sizeof(Vertex));
}
vertexBuffer.Unlock();
}
//copy data to index buffer
{
HardwareIndexBuffer indexBuffer = subMesh.IndexData.IndexBuffer;
IntPtr buffer = indexBuffer.Lock(HardwareBuffer.LockOptions.Discard);
fixed (ushort* pIndices = indices)
{
//.........这里部分代码省略.........