本文整理汇总了C#中UnityEngine.Vector3.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Scale方法的具体用法?C# Vector3.Scale怎么用?C# Vector3.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Vector3
的用法示例。
在下文中一共展示了Vector3.Scale方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSceneGUI
public bool OnSceneGUI(Transform transform, Color color, bool handlesOnly, ref Vector3 center, ref Vector3 size)
{
if (!this.m_UseLossyScale)
return this.OnSceneGUI(transform.localToWorldMatrix, color, handlesOnly, ref center, ref size);
Matrix4x4 transform1 = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
size.Scale(transform.lossyScale);
center = transform.TransformPoint(center);
center = transform1.inverse.MultiplyPoint(center);
bool flag = this.OnSceneGUI(transform1, color, handlesOnly, ref center, ref size);
center = transform1.MultiplyPoint(center);
center = transform.InverseTransformPoint(center);
size.Scale(new Vector3(1f / transform.lossyScale.x, 1f / transform.lossyScale.y, 1f / transform.lossyScale.z));
return flag;
}
示例2: GetVectorField
public override Vector3 GetVectorField( Vector3 position )
{
position = position * noiseScale + offset;
float angle = Mathf.Lerp( 0, 2 * Mathf.PI, Mathf.PerlinNoise(position.x, position.y) );
Vector3 noiseVector = new Vector3( Mathf.Cos(angle), Mathf.Sin(angle), 0 );
//noiseVector = Random.onUnitSphere;
noiseVector.Scale( new Vector3(affectX ? 1 : 0, affectY ? 1 : 0, affectZ ? 1: 0) );
noiseVector *= force;
return noiseVector;
}
示例3: GetVectorField
public override Vector3 GetVectorField( Vector3 position )
{
BoxCollider boxCollider = GetComponent<BoxCollider>();
Vector3 affect = new Vector3(affectX ? 1 : 0, affectY ? 1 : 0, affectZ ? 1: 0);
Vector3 vector = transform.position - position;
vector.Scale( affect );
vector.Normalize();
Vector3 dist = transform.position - position;
Vector3 halfSize = 0.5f * boxCollider.size;
Vector3 attenuate = new Vector3( Mathf.Abs(dist.x) / halfSize.x, Mathf.Abs(dist.y)/halfSize.y, Mathf.Abs(dist.z)/halfSize.z );
//attenuate = new Vector3( 1/ attenuate.x, 1/attenuate.y, 1/attenuate.z );
attenuate.Scale( affect );
vector *= force;
vector.Scale( attenuate );
return vector;
}
示例4: getTranslationWithScalar
public Vector3 getTranslationWithScalar(float scalar =1) {
Vector3 v = new Vector3 (this.Tx, this.Ty, this.Tz);
v.Scale (new Vector3 (scalar, scalar, scalar));
return v;
}
示例5: getScopeWithScalar
public Vector3 getScopeWithScalar(float scalar =1) {
Vector3 v = new Vector3 (this.Sx, this.Sy, this.Sz);
v.Scale (new Vector3 (scalar, scalar, scalar));
return v;
}
示例6: Drive
public void Drive(FlightCtrlState s)
{
if (useSAS)
{
_requestedAttitude = attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Quaternion.Euler(90, 0, 0);
if (!vessel.ActionGroups[KSPActionGroup.SAS])
{
vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
vessel.Autopilot.SAS.LockHeading(_requestedAttitude);
lastSAS = _requestedAttitude;
}
else if (Quaternion.Angle(lastSAS, _requestedAttitude) > 10)
{
vessel.Autopilot.SAS.LockHeading(_requestedAttitude);
lastSAS = _requestedAttitude;
}
else
{
vessel.Autopilot.SAS.LockHeading(_requestedAttitude, true);
}
}
else
{
// Direction we want to be facing
_requestedAttitude = attitudeGetReferenceRotation(attitudeReference) * attitudeTarget;
Transform vesselTransform = vessel.ReferenceTransform;
Quaternion delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselTransform.rotation) * _requestedAttitude);
Vector3d deltaEuler = delta.DeltaEuler();
// ( MoI / available torque ) factor:
Vector3d NormFactor = Vector3d.Scale(vesselState.MoI, torque.Invert()).Reorder(132);
// Find out the real shorter way to turn were we wan to.
// Thanks to HoneyFox
Vector3d tgtLocalUp = vesselTransform.transform.rotation.Inverse() * _requestedAttitude * Vector3d.forward;
Vector3d curLocalUp = Vector3d.up;
double turnAngle = Math.Abs(Vector3d.Angle(curLocalUp, tgtLocalUp));
Vector2d rotDirection = new Vector2d(tgtLocalUp.x, tgtLocalUp.z);
rotDirection = rotDirection.normalized * turnAngle / 180.0;
// And the lowest roll
// Thanks to Crzyrndm
Vector3 normVec = Vector3.Cross(_requestedAttitude * Vector3.forward, vesselTransform.up);
Quaternion targetDeRotated = Quaternion.AngleAxis((float)turnAngle, normVec) * _requestedAttitude;
float rollError = Vector3.Angle(vesselTransform.right, targetDeRotated * Vector3.right) * Math.Sign(Vector3.Dot(targetDeRotated * Vector3.right, vesselTransform.forward));
error = new Vector3d(
-rotDirection.y * Math.PI,
rotDirection.x * Math.PI,
rollError * Mathf.Deg2Rad
);
error.Scale(_axisControl);
Vector3d err = error + inertia.Reorder(132) / 2d;
err = new Vector3d(
Math.Max(-Math.PI, Math.Min(Math.PI, err.x)),
Math.Max(-Math.PI, Math.Min(Math.PI, err.y)),
Math.Max(-Math.PI, Math.Min(Math.PI, err.z)));
err.Scale(NormFactor);
// angular velocity:
Vector3d omega;
omega.x = vessel.angularVelocity.x;
omega.y = vessel.angularVelocity.z; // y <=> z
omega.z = vessel.angularVelocity.y; // z <=> y
omega.Scale(NormFactor);
if (Tf_autoTune)
tuneTf(torque);
setPIDParameters();
// angular velocity limit:
var Wlimit = new Vector3d(Math.Sqrt(NormFactor.x * Math.PI * kWlimit),
Math.Sqrt(NormFactor.y * Math.PI * kWlimit),
Math.Sqrt(NormFactor.z * Math.PI * kWlimit));
pidAction = pid.Compute(err, omega, Wlimit);
// deadband
pidAction.x = Math.Abs(pidAction.x) >= deadband ? pidAction.x : 0.0f;
pidAction.y = Math.Abs(pidAction.y) >= deadband ? pidAction.y : 0.0f;
pidAction.z = Math.Abs(pidAction.z) >= deadband ? pidAction.z : 0.0f;
// low pass filter, wf = 1/Tf:
Vector3d act = lastAct;
act.x += (pidAction.x - lastAct.x) * (1.0 / ((TfV.x / TimeWarp.fixedDeltaTime) + 1.0));
act.y += (pidAction.y - lastAct.y) * (1.0 / ((TfV.y / TimeWarp.fixedDeltaTime) + 1.0));
act.z += (pidAction.z - lastAct.z) * (1.0 / ((TfV.z / TimeWarp.fixedDeltaTime) + 1.0));
lastAct = act;
SetFlightCtrlState(act, deltaEuler, s, 1);
act = new Vector3d(s.pitch, s.yaw, s.roll);
// Feed the control torque to the differential throttle
//.........这里部分代码省略.........
示例7: rescaleModel
public virtual void rescaleModel()
{
//transform.GetChild(0).GetChild(0).GetChild(0).localScale = new Vector3(radialFactor, radialFactor, stretchFactor);
/*if (origScale.x < 0)
origScale = transform.GetChild(0).GetChild(0).localScale;*/
Vector3 scale = new Vector3(radialFactor, stretchFactor, radialFactor);
scale.Scale(origScale);
transform.GetChild(0).GetChild(0).localScale = scale;
}
示例8: SetPosition
// set position for bone
static void SetPosition( Transform[] transforms, NeuronBones bone, Vector3 position, float lerp_ratio )
{
Transform t = transforms[(int)bone];
if( t != null )
{
// calculate position when we have scale
position.Scale( new Vector3( 1.0f / t.parent.lossyScale.x, 1.0f / t.parent.lossyScale.y, 1.0f / t.parent.lossyScale.z ) );
Vector3 pos = Vector3.Lerp( t.localPosition, position, lerp_ratio );
if( !float.IsNaN( pos.x ) && !float.IsNaN( pos.y ) && !float.IsNaN( pos.z ) )
{
t.localPosition = pos;
}
}
}
示例9: GetPartialCoverBetween
/// <summary>
/// Checks for cover along the flight path of the bullet, doesn't check for walls or plants, only intended for cover with partial fillPercent
/// </summary>
private bool GetPartialCoverBetween(Vector3 sourceLoc, Vector3 targetLoc, out Thing cover)
{
//Sanity check
if (this.verbProps.projectileDef.projectile.flyOverhead)
{
cover = null;
return false;
}
sourceLoc.Scale(new Vector3(1, 0, 1));
targetLoc.Scale(new Vector3(1, 0, 1));
//Calculate segment vector and segment amount
Vector3 shotVec = sourceLoc - targetLoc; //Vector from target to source
Vector3 segmentVec = shotVec.normalized * segmentLength;
float distToCheck = Mathf.Min(distToCheckForCover, shotVec.magnitude); //The distance to raycast
float numSegments = distToCheck / segmentLength;
//Raycast accross all segments to check for cover
List<IntVec3> checkedCells = new List<IntVec3>();
Thing targetThing = GridsUtility.GetEdifice(targetLoc.ToIntVec3());
Thing newCover = null;
for (int i = 0; i <= numSegments; i++)
{
IntVec3 cell = (targetLoc + segmentVec * i).ToIntVec3();
if (!checkedCells.Contains(cell))
{
//Cover check, if cell has cover compare fillPercent and get the highest piece of cover, ignore if cover is the target (e.g. solar panels, crashed ship, etc)
Thing coverAtCell = GridsUtility.GetCover(cell);
if (coverAtCell != null
&& (targetThing == null || !coverAtCell.Equals(targetThing))
&& (newCover == null || newCover.def.fillPercent < coverAtCell.def.fillPercent))
{
newCover = coverAtCell;
}
}
}
cover = newCover;
//Report success if found cover that is not a wall or plant
return (cover != null
&& cover.def.Fillage != FillCategory.Full
&& cover.def.category != ThingCategory.Plant); //Don't care about trees
}
示例10: onPartFixedUpdate
protected override void onPartFixedUpdate()
{
if (mode == CargoMode.Idle)
{
teleCount = 0;
jumpCount = 0;
approachCount = 0;
waitCount = 0;
}
if (mode == CargoMode.ReasonableWaitBeforeJump)
{
waitCount++;
if (waitCount > 300)
{
mode = CargoMode.JumpRequested;
}
}
if (mode == CargoMode.HoldingPosition)
{
vessel.SetWorldVelocity(destination.GetVelocityOfDestination(vessel));
}
if (mode == CargoMode.AcceleratingTowardsDock)
{
int safeDistance = 50;
if (destination.IsDestinationLanded())
{
safeDistance = 50;
}
if (approachCount == 50)
{
approachCount++;
originalVesselVelocity = vessel.obt_velocity;
}
else if (approachCount > 2000)
{
print("Approach is taking too long. Giving up.");
vessel.SetWorldVelocity(destination.GetVelocityOfDestination(vessel));
mode = CargoMode.Idle;
}
else if (destination.GetPreciseDistanceToDestination(vessel).magnitude < safeDistance)
{
print("Approach successful");
vessel.SetWorldVelocity(destination.GetVelocityOfDestination(vessel));
mode = CargoMode.HoldingPosition;
}
else if (approachCount < 100)
{
approachCount++;
}
else
{
approachCount++;
Vector3 finalVelocity;
//print("OriginalVelocity: " + originalVesselVelocity);
//print("Current Velocity: " + vessel.obt_velocity);
Vector3 reducedVector = new Vector3();
Vector3 scalar = new Vector3(1, 1, 1);
scalar = scalar / 1;
reducedVector = destination.GetPreciseDistanceToDestination(vessel);
//print("Reduced Vector - starts at: " + reducedVector);
reducedVector.Scale(scalar);
//print("Reduced Vector - scales to: " + reducedVector);
finalVelocity = originalVesselVelocity + (reducedVector);
//print("FinalVelocity: " + finalVelocity);
vessel.SetWorldVelocity(finalVelocity);
}
}
if (mode == CargoMode.DriftingTowardsDock)
{
}
if (mode == CargoMode.TeleportRequested)
{
mode = CargoMode.TeleportingToSpaceDock;
teleCount = 0;
approachCount = 0;
jumpCount = 0;
}
if (mode == CargoMode.TeleportingToSpaceDock)
{
if (teleCount < 1)
{
print("Zork: Going onto Rails");
Teleport(new Vector3(0, 0, -3000000));
print("Zork: Teleporting: count at " + teleCount);
//vessel.transform.position = whereToGoFifth;
teleCount++;
}
//.........这里部分代码省略.........
示例11: TestScaleBy
public static void TestScaleBy()
{
const float floatScale = 4.8f;
const float floatStart = 1.2f;
float floatVal = floatStart;
Ref<float> floatRef = new Ref<float>(
() => floatVal,
t => floatVal = t
);
const double doubleScale = 3.2;
const double doubleStart = 9.2;
double doubleVal = doubleStart;
Ref<double> doubleRef = new Ref<double>(
() => doubleVal,
t => doubleVal = t
);
Vector2 vec2Scale = new Vector2(9.5f, 2.0f);
Vector2 vec2Start = new Vector2(4.0f, 5.0f);
Vector2 vec2Val = vec2Start;
Ref<Vector2> vec2Ref = new Ref<Vector2>(
() => vec2Val,
t => vec2Val = t
);
Vector3 vec3Scale = new Vector3(4.0f, 19.0f, 2.0f);
Vector3 vec3Start = new Vector3(92.0f, 0.5f, 34.0f);
Vector3 vec3Val = vec3Start;
Ref<Vector3> vec3Ref = new Ref<Vector3>(
() => vec3Val,
t => vec3Val = t
);
Vector4 vec4Scale = new Vector4(92.0f, 0.5f, 14.0f, 7.0f);
Vector4 vec4Start = new Vector4(0.4f, 10.0f, 3.0f, 82.0f);
Vector4 vec4Val = vec4Start;
Ref<Vector4> vec4Ref = new Ref<Vector4>(
() => vec4Val,
t => vec4Val = t
);
CommandQueue queue = new CommandQueue();
queue.Enqueue(
Commands.Repeat(2,
Commands.Sequence(
Commands.Parallel(
Commands.ScaleBy(floatRef, floatScale, 1.0),
Commands.ScaleBy(doubleRef, doubleScale, 1.0),
Commands.ScaleBy(vec2Ref, vec2Scale, 1.0),
Commands.ScaleBy(vec3Ref, vec3Scale, 1.0),
Commands.ScaleBy(vec4Ref, vec4Scale, 1.0)
),
Commands.WaitForFrames(1)
)
)
);
queue.Update(0.2f);
Vector2 vec2ExpectedScale = vec2Scale;
Vector3 vec3ExpectedScale = vec3Scale;
Vector4 vec4ExpectedScale = vec4Scale;
vec2ExpectedScale.Scale(new Vector2(0.2f, 0.2f));
vec3ExpectedScale.Scale(new Vector3(0.2f, 0.2f, 0.2f));
vec4ExpectedScale.Scale(new Vector4(0.2f, 0.2f, 0.2f, 0.2f));
vec2ExpectedScale += new Vector2(0.8f, 0.8f);
vec3ExpectedScale += new Vector3(0.8f, 0.8f, 0.8f);
vec4ExpectedScale += new Vector4(0.8f, 0.8f, 0.8f, 0.8f);
vec2ExpectedScale.Scale(vec2Start);
vec3ExpectedScale.Scale(vec3Start);
vec4ExpectedScale.Scale(vec4Start);
AreEqual(floatVal, floatStart * (0.8f + floatScale * 0.2f), 0.001f);
AreEqual(doubleVal, doubleStart * (0.8 + doubleScale * 0.2), 0.001f);
AreEqual(vec2Val, vec2ExpectedScale, 0.001f);
AreEqual(vec3Val, vec3ExpectedScale, 0.001f);
AreEqual(vec4Val, vec4ExpectedScale, 0.001f);
queue.Update(0.8);
vec2ExpectedScale = vec2Scale;
vec3ExpectedScale = vec3Scale;
vec4ExpectedScale = vec4Scale;
vec2ExpectedScale.Scale(vec2Start);
vec3ExpectedScale.Scale(vec3Start);
vec4ExpectedScale.Scale(vec4Start);
AreEqual(floatVal, floatStart * floatScale, 0.001f);
AreEqual(doubleVal, doubleStart * doubleScale, 0.001f);
AreEqual(vec2Val, vec2ExpectedScale, 0.001f);
AreEqual(vec3Val, vec3ExpectedScale, 0.001f);
AreEqual(vec4Val, vec4ExpectedScale, 0.001f);
floatVal = floatStart;
doubleVal = doubleStart;
vec2Val = vec2Start;
vec3Val = vec3Start;
vec4Val = vec4Start;
queue.Update(0.0);
queue.Update(0.5);
vec2ExpectedScale = vec2Scale;
vec3ExpectedScale = vec3Scale;
//.........这里部分代码省略.........