本文整理汇总了C#中Vector3.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.DistanceTo方法的具体用法?C# Vector3.DistanceTo怎么用?C# Vector3.DistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.DistanceTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPeds
public static Ped[] GetPeds(Vector3 Position,float length)
{
lock (lockObject)
{
try
{
if (pedList.Length == 0) { return new Ped[0]; }
//リストから一定距離のものだけを返す
return pedList.Where(p => p != null).Where(p => p.Exists()).Where(p => Position.DistanceTo(p.Position) <= length).ToArray<Ped>();
}
catch
{
return new Ped[0];
}
}
}
示例2: GetLineDose
/// <summary>
/// Scrapes a dose matrix along the line from startXYZ in mm to endXYZ in mm
/// </summary>
/// <param name="startXYZmm">the starting position of the line</param>
/// <param name="endXYZmm">the end position of the line</param>
/// <param name="resolution_mm">the resolution to interoplate the line dose (default 2 mm)</param>
/// <returns>a list of dose values at the specified resolution along the line</returns>
public List<DoseValue> GetLineDose(Vector3 startXYZmm, Vector3 endXYZmm, double resolution_mm = 2)
{
List<DoseValue> values = new List<DoseValue>();
var pointer = endXYZmm - startXYZmm;
var length = startXYZmm.DistanceTo(endXYZmm);
var numPts = (int)Math.Ceiling(length / resolution_mm);
for (int i = 0; i <= numPts; i++)
{
var pt = startXYZmm + ((1 - ((double)i / numPts)) * pointer);
if (IsInBounds(pt))
{
values.Add(GetPointDose(pt));
}
}
values.Reverse();
return values;
}
示例3: CreateRamp
public void CreateRamp(Vector3 top, Vector3 bottom)
{
float distance = top.DistanceTo(bottom);
int blocks = (int)Math.Ceiling(distance / 30);
Vector3 A = new Vector3((top.X - bottom.X) / blocks, (top.Y - bottom.Y) / blocks, (top.Z - bottom.Z) / blocks);
Vector3 temp = Call<Vector3>("vectortoangles", new Parameter(top - bottom));
Vector3 BA = new Vector3(temp.Z, temp.Y + 90, temp.X);
for (int b = 0; b <= blocks; b++)
{
spawnCrate(bottom + (A * b), BA);
}
}
示例4: DistanceSquareToSegment
public float DistanceSquareToSegment(Vector3 v0,Vector3 v1, ref Vector3 optionalPointOnRay, ref Vector3 optionalPointOnSegment)
{
// from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
// It returns the min distance between the ray and the segment
// defined by v0 and v1
// It can also set two optional targets :
// - The closest point on the ray
// - The closest point on the segment
var segCenter = v0;
segCenter.Add( v1 );
segCenter.Multiply( 0.5f );
var segDir = v1;
segDir.Subtract(v0);
segDir.Normalize();
var segExtent = v0.DistanceTo( v1 ) / 2;
var diff = origin;
diff.Subtract(segCenter );
var a01 = - direction.Dot( segDir );
var b0 = diff.Dot( direction );
var b1 = - diff.Dot( segDir );
var c = diff.LengthSquared();
var det = Mathf.Abs( 1 - a01 * a01 );
var sqrDist = 0f;
var s0 = 0f;
var s1 = 0f;
if ( det >= 0 ) {
// The ray and segment are not parallel.
s0 = a01 * b1 - b0;
s1 = a01 * b0 - b1;
var extDet = segExtent * det;
if ( s0 >= 0 ) {
if ( s1 >= - extDet ) {
if ( s1 <= extDet ) {
// region 0
// Minimum at interior points of ray and segment.
var invDet = 1 / det;
s0 *= invDet;
s1 *= invDet;
sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
} else {
// region 1
s1 = segExtent;
s0 = Mathf.Max( 0, - ( a01 * s1 + b0 ) );
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
}
} else {
// region 5
s1 = - segExtent;
s0 = Mathf.Max( 0, - ( a01 * s1 + b0 ) );
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
}
} else {
if ( s1 <= - extDet ) {
// region 4
s0 = Mathf.Max( 0, - ( - a01 * segExtent + b0 ) );
s1 = ( s0 > 0 ) ? - segExtent : Mathf.Min(Mathf.Max( - segExtent, - b1 ), segExtent );
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
} else if ( s1 <= extDet ) {
// region 3
s0 = 0;
s1 = Mathf.Min(Mathf.Max( - segExtent, - b1 ), segExtent );
sqrDist = s1 * ( s1 + 2 * b1 ) + c;
} else {
// region 2
s0 = Mathf.Max( 0, - ( a01 * segExtent + b0 ) );
s1 = ( s0 > 0 ) ? segExtent : Mathf.Min( Mathf.Max( - segExtent, - b1 ), segExtent );
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
}
}
//.........这里部分代码省略.........
示例5: CreateRamp2
public void CreateRamp2(Vector3 top, Vector3 bottom)
{
int num2 = (int)Math.Ceiling((double)(top.DistanceTo(bottom) / 30f));
Vector3 vector = new Vector3((top.X - bottom.X) / ((float)num2), (top.Y - bottom.Y) / ((float)num2), (top.Z - bottom.Z) / ((float)num2));
Vector3 vector2 = base.Call<Vector3>("vectortoangles", new Parameter[] { new Parameter(top - bottom) });
Vector3 angles = new Vector3(vector2.Z, vector2.Y + 90f, vector2.X);
for (int i = 0; i <= num2; i++)
{
spawnCrateRed(bottom + (vector * i), angles);
}
}
示例6: updatePed
public void updatePed(uint id, UpdateDataStruct data, StreamedPed ped)
{
var posnew = new Vector3(data.pos_x, data.pos_y, data.pos_z - 1.0f);
ped.position = posnew;
ped.heading = data.heading;
ped.direction = new Vector3(data.rot_x, data.rot_y, data.rot_z);
ped.cameraDirection = new Vector3(data.camdir_x, data.camdir_y, data.camdir_z);
if (ped.IsStreamedIn() && data.vehicle_id == 0)
{
if (ped.gameReference.isInVehicle())
{
ped.gameReference.CurrentVehicle.PassengersLeaveVehicle(true);
//ped.gameReference.CurrentVehicle.Delete();
}
float delta = posnew.DistanceTo(ped.gameReference.Position);
Vector3 vdelta = posnew - ped.gameReference.Position;
//ped.gameReference.Weapons.MP5.Ammo = 999;
int healthDelta = data.ped_health - ped.gameReference.Health;
ped.gameReference.Health = data.ped_health;
ped.last_game_health = data.ped_health;
if (data.weapon > 0)
{
if (ped.gameReference.Weapons.Current != (Weapon)data.weapon)
{
ped.gameReference.Weapons.FromType((Weapon)data.weapon).Ammo = 999;
ped.gameReference.Weapons.FromType((Weapon)data.weapon).AmmoInClip = 999;
ped.gameReference.Weapons.Select((Weapon)data.weapon);
}
}
else
{
ped.gameReference.Weapons.RemoveAll();
}
if (healthDelta > 20 && healthDelta < 100)
{
var bpf = new BinaryPacketFormatter(Commands.Player_damage);
bpf.Add(id);
//Client.instance.chatController.writeChat("damaged " + healthDelta) ;
Client.instance.serverConnection.write(bpf.getBytes());
}
bool cancelPositionUpdate = false;
if ((data.state & PlayerState.IsShooting) != 0)
{
ped.animator.playAnimation(PedAnimations.Shoot);
cancelPositionUpdate = true;
}
else
if ((data.state & PlayerState.IsAiming) != 0)
{
ped.animator.playAnimation(PedAnimations.Aim);
cancelPositionUpdate = true;
}
else
if ((data.state & PlayerState.IsRagdoll) != 0 || data.ped_health <= 0)
{
ped.animator.playAnimation(PedAnimations.Ragdoll);
ped.gameReference.Velocity = new Vector3(data.vel_x, data.vel_y, data.vel_z);
cancelPositionUpdate = true;
}
else
if ((data.vstate & VehicleState.IsEnteringVehicle) != 0)
{
ped.animator.playAnimation(PedAnimations.EnterClosestVehicle);
cancelPositionUpdate = true;
}
else
if ((data.state & PlayerState.IsCrouching) != 0)
{
ped.animator.playAnimation(PedAnimations.Couch);
}
else
{
if ((data.vstate & VehicleState.IsAccelerating) != 0)
{
if ((data.vstate & VehicleState.IsSprinting) != 0)
{
ped.animator.playAnimation(PedAnimations.Run);
}
else
{
ped.animator.playAnimation(PedAnimations.Walk);
}
}
else
{
ped.animator.playAnimation(PedAnimations.StandStill);
}
}
if (!cancelPositionUpdate)
{
ped.gameReference.Position = posnew;
}
ped.gameReference.Heading = data.heading;
//.........这里部分代码省略.........
示例7: CreateRamp
public Entity[] CreateRamp(Vector3 top, Vector3 bottom)
{
List<Entity> _ents = new List<Entity>();
int num2 = (int)Math.Ceiling((double)(top.DistanceTo(bottom) / 30f));
Vector3 vector = new Vector3((top.X - bottom.X) / ((float)num2), (top.Y - bottom.Y) / ((float)num2), (top.Z - bottom.Z) / ((float)num2));
Vector3 vector2 = base.Call<Vector3>("vectortoangles", new Parameter[] { new Parameter(top - bottom) });
Vector3 angles = new Vector3(vector2.Z, vector2.Y + 90f, vector2.X);
for (int i = 0; i <= num2; i++)
{
Entity ent = spawnCrateTrap(bottom + (vector * i), angles);
_ents.Add(ent);
}
return _ents.ToArray();
}
示例8: GetVehicles
public static Vehicle[] GetVehicles(Vector3 Position, float length)
{
lock (lockObject)
{
try
{
if (vehicleList.Length == 0) { return new Vehicle[0]; }
//リストから一定距離のものだけを返す
return vehicleList.Where(v => v != null).Where(v => v.Exists()).Where(v => Position.DistanceTo(v.Position) <= length).ToArray<Vehicle>();
}
catch
{
return new Vehicle[0];
}
}
}
示例9: Analysis
//対象物が画面のどこらへんにあるかを割り出す処理
//返り値はVector3(x,y,z)
// x:0.0~1.0
// y:0.0~1.0
// z:距離を線形変換。フォントサイズの算出等に使える。
public Vector3 Analysis(Camera cam, Vector3 TargetPos)
{
float x, y, z;
x = -cam.Rotation.X * (float)Math.PI / 180.0f;
y = -cam.Rotation.Y * (float)Math.PI / 180.0f;
z = -cam.Rotation.Z * (float)Math.PI / 180.0f;
Vector3 Output = TargetPos - cam.Position; //平行移動
Vector3 temp;
//z軸回りに回転
temp.X = (float)Math.Cos(z) * Output.X - (float)Math.Sin(z) * Output.Y;
temp.Y = (float)Math.Sin(z) * Output.X + (float)Math.Cos(z) * Output.Y;
temp.Z = Output.Z;
Output = temp;
//y軸回りに回転
temp.X = (float)Math.Cos(y) * Output.X - (float)Math.Sin(y) * Output.Z;
temp.Y = Output.Y;
temp.Z = (float)Math.Sin(y) * Output.X + (float)Math.Cos(y) * Output.Z;
Output = temp;
//x軸回りに回転
temp.X = Output.X;
temp.Y = (float)Math.Cos(x) * Output.Y - (float)Math.Sin(x)*Output.Z;
temp.Z = (float)Math.Sin(x) * Output.Y + (float)Math.Cos(x)*Output.Z;
Output = temp;
//ベクトルの角度を取得
Vector2 theta;
theta.X = (float)Math.Atan2(Output.X*10.0f,10*Output.Y);
theta.Y = (float)Math.Atan2(10 * Output.Z, 10 * Output.Y);
//角度より位置を割り出す
if (Output.Y >= 0.0)
{
temp.X = (float)Math.Sin(-theta.X) + 0.5f;
temp.Y = (float)Math.Sin(-theta.Y) + 0.5f;
}
else
{
temp.X = -1.0f;
temp.Y = -1.0f;
}
//線形変換
temp.Z = a * TargetPos.DistanceTo(cam.Position) + b;
Output = temp;
return Output;
}