本文整理汇总了C#中Vector3F.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3F.Normalize方法的具体用法?C# Vector3F.Normalize怎么用?C# Vector3F.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3F
的用法示例。
在下文中一共展示了Vector3F.Normalize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Normalize
public void Normalize()
{
Vector3F v, n1, n2;
float magnitude;
v = new Vector3F(3.0f, 4.0f, 0.0f);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0f, n1.Magnitude, 1e-7);
Assert.AreEqual(1.0f, n2.Magnitude, 1e-7);
Assert.AreEqual(5.0f, magnitude, 1e-7);
v = new Vector3F(3.0f, 0.0f, 4.0f);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0f, n1.Magnitude, 1e-7);
Assert.AreEqual(1.0f, n2.Magnitude, 1e-7);
Assert.AreEqual(5.0f, magnitude, 1e-7);
v = new Vector3F(0.0f, 3.0f, 4.0f);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0f, n1.Magnitude, 1e-7);
Assert.AreEqual(1.0f, n2.Magnitude, 1e-7);
Assert.AreEqual(5.0f, magnitude, 1e-7);
}
示例2: NormalizeZeroVector
public void NormalizeZeroVector()
{
Vector3F v = new Vector3F(0.0f, 0.0f, 0.0f);
Vector3F n1 = v.Normalize();
Assert.IsNaN(n1.X);
Assert.IsNaN(n1.Y);
Assert.IsNaN(n1.Z);
Assert.IsTrue(n1.IsUndefined);
float magnitude;
Vector3F n2 = v.Normalize(out magnitude);
Assert.IsNaN(n2.X);
Assert.IsNaN(n2.Y);
Assert.IsNaN(n2.Z);
Assert.IsTrue(n2.IsUndefined);
Assert.AreEqual(0.0f, magnitude);
}
示例3: AnisotropicGaussianTest
public void AnisotropicGaussianTest(float x, float y, float z)
{
// Validate code in Blur.fx.
// Reference: "Screen Space Anisotropic Blurred Soft Shadows"
Vector3F normalView = new Vector3F(x, y, z);
normalView.Normalize();
Vector3F axisMajor0, axisMinor0;
float radiusMajor0, radiusMinor0;
GetEllipseCoefficients(normalView, out axisMajor0, out axisMinor0, out radiusMajor0, out radiusMinor0);
Assert.AreEqual(0.0f, axisMajor0.Z);
Assert.AreEqual(0.0f, axisMinor0.Z);
Assert.IsTrue(axisMajor0.IsNumericallyNormalized);
Assert.IsTrue(axisMinor0.IsNumericallyNormalized);
Vector3F axisMajor1, axisMinor1;
float radiusMajor1, radiusMinor1;
GetEllipseCoefficients_Optimized(normalView, out axisMajor1, out axisMinor1, out radiusMajor1, out radiusMinor1);
Assert.IsTrue(Vector3F.AreNumericallyEqual(axisMajor0, axisMajor1));
Assert.IsTrue(Vector3F.AreNumericallyEqual(axisMinor0, axisMinor1));
Assert.AreEqual(radiusMajor0, radiusMajor1);
Assert.AreEqual(radiusMinor0, radiusMinor1);
}
示例4: Particle
/// <summary>
/// Initializes a new instance of the <see cref="Particle"/> class.
/// </summary>
/// <param name="world">The world.</param>
/// <param name="pos">The initial position.</param>
/// <param name="direction">The direction in which the particle is flying.</param>
/// <param name="owner">The owner of the particle.</param>
/// <param name="block">The block type of the particle.</param>
/// <param name="behavior">The partcle behavior. Includes how fare and fast it moves, what happens if it hits a player an obstacle etc.</param>
public Particle(World world, Vector3I pos, Vector3F direction, Player owner,
Block block, IParticleBehavior behavior)
: base(world)
{
_direction = direction.Normalize();
if (_direction == Vector3F.Zero)
throw new ArgumentException("direction vector cannot be zero");
_stepDelay = behavior.ProcessingStepsPerSecond <= 0 || behavior.ProcessingStepsPerSecond > 20
? 50
: 1000 / behavior.ProcessingStepsPerSecond;
_pos = pos;
_startingPos = pos;
_currentStep = 0;
_owner = owner;
_block = block;
_restDistance = behavior.MaxDistance;
_behavior = behavior;
lock (_world.SyncRoot)
{
//draw it once right now
if (null != _map && ReferenceEquals(_map, _world.Map))
{
_prevBlock = _map.GetBlock(pos);
if (Block.Undefined != _prevBlock) //out of bounds!
UpdateMap(new BlockUpdate(null, pos, block));
}
}
}
示例5: CreatingTerrain
//FIXME [HS:6411] [Test]
public void CreatingTerrain()
{
//Check whether terrain shape is in scene
Assert.IsTrue(IsTerrainInScene());
//Remove Terrain
EditorManager.Actions.Add(RemoveShapeAction.CreateRemoveShapeAction(TerrainEditor.CurrentTerrain));
//Check that terrain shape is NOT in scene
Assert.IsTrue(!IsTerrainInScene());
//Add again
EditorManager.GetShapeCreatorPluginByNameAndCategory("Geometry", "Terrain").ExecutePlugin();
TestManager.Helpers.ProcessEvents();
//Undo of Add Terrain is unsupported!
EditorManager.Actions.Reset();
//Check whether terrain shape is in scene
Assert.IsTrue(IsTerrainInScene());
// Test the various painting methods
PaintTerrain(TerrainManaged.HeightmapEditMode_e.Elevate, 300, 128, 4);
PaintTerrain(TerrainManaged.HeightmapEditMode_e.Flatten, 300, 128, 4);
PaintTerrain(TerrainManaged.HeightmapEditMode_e.Elevate, 300, 128, 3);
PaintTerrain(TerrainManaged.HeightmapEditMode_e.Flatten, 300, 128, 3);
PaintTerrain(TerrainManaged.HeightmapEditMode_e.Elevate, 300, 128, 3);
SmoothTerrain(300, 128);
//Toggle lighting
bool lighting = TerrainEditor.DirectionalLighting;
TerrainEditor.DirectionalLighting = !TerrainEditor.DirectionalLighting;
Assert.AreEqual(TerrainEditor.DirectionalLighting, !lighting);
EditorManager.ActiveView.UpdateView(true);
TerrainEditor.DirectionalLighting = !TerrainEditor.DirectionalLighting;
Assert.AreEqual(TerrainEditor.DirectionalLighting, lighting);
EditorManager.ActiveView.UpdateView(true);
//Change lighting dir & color
Vector3F dir = new Vector3F(0.0f, 0.2f, -0.8f);
dir.Normalize();
TerrainEditor.CurrentTerrain.EngineTerrain.SetDirectionalLightProperties(dir, System.Drawing.Color.FromArgb(96, 64, 32), System.Drawing.Color.FromArgb(196, 128, 96));
//Undo/redo test (everything)
while (EditorManager.Actions.Undo()) {}
while (EditorManager.Actions.Redo()) {}
//Verify redone state (e.g. at least that the terrain exists)
Assert.IsTrue(IsTerrainInScene());
}
示例6: Normalize
public void Normalize()
{
Vector3F v = new Vector3F(3.0f, -1.0f, 23.0f);
v.Normalize();
Assert.IsTrue(v.IsNumericallyNormalized);
}
示例7: Power2
public void Power2()
{
const float θ = 0.4f;
const float t = -1.2f;
Vector3F v = new Vector3F(2.3f, 1.0f, -2.0f);
v.Normalize();
QuaternionF q = new QuaternionF((float)Math.Cos(θ), (float)Math.Sin(θ) * v);
q.Power(t);
QuaternionF expected = new QuaternionF((float)Math.Cos(t * θ), (float)Math.Sin(t * θ) * v);
Assert.IsTrue(QuaternionF.AreNumericallyEqual(expected, q));
}
示例8: Power3
public void Power3()
{
const float θ = 0.4f;
Vector3F v = new Vector3F(2.3f, 1.0f, -2.0f);
v.Normalize();
QuaternionF q = new QuaternionF((float)Math.Cos(θ), (float)Math.Sin(θ) * v);
QuaternionF q2 = q;
q2.Power(2);
Assert.IsTrue(QuaternionF.AreNumericallyEqual(q * q, q2));
QuaternionF q3 = q;
q3.Power(3);
Assert.IsTrue(QuaternionF.AreNumericallyEqual(q * q * q, q3));
q2 = q;
q2.Power(-2);
Assert.IsTrue(QuaternionF.AreNumericallyEqual(q.Inverse * q.Inverse, q2));
q3 = q;
q3.Power(-3);
Assert.IsTrue(QuaternionF.AreNumericallyEqual(q.Inverse * q.Inverse * q.Inverse, q3));
}
示例9: Ln4
public void Ln4()
{
float θ = 0.0f;
Vector3F v = new Vector3F(1.0f, 2.0f, 3.0f);
v.Normalize();
QuaternionF q = new QuaternionF((float)Math.Cos(θ), (float)Math.Sin(θ) * v);
q.Ln();
Assert.IsTrue(Numeric.AreEqual(0.0f, q.W));
Assert.IsTrue(Vector3F.AreNumericallyEqual(θ * v, q.V));
}
示例10: Invert
public void Invert()
{
QuaternionF inverseIdentity = QuaternionF.Identity;
inverseIdentity.Invert();
Assert.AreEqual(QuaternionF.Identity, inverseIdentity);
float angle = 0.4f;
Vector3F axis = new Vector3F(1.0f, 1.0f, 1.0f);
axis.Normalize();
QuaternionF q = QuaternionF.CreateRotation(axis, angle);
q.Invert();
Assert.IsTrue(Vector3F.AreNumericallyEqual(-axis, q.Axis));
q = new QuaternionF(1, 2, 3, 4);
QuaternionF inverse = q;
inverse.Invert();
Assert.IsTrue(QuaternionF.AreNumericallyEqual(QuaternionF.Identity, inverse * q));
}
示例11: Exp4
public void Exp4()
{
float θ = 0.0f;
Vector3F v = new Vector3F(1.0f, 2.0f, 3.0f);
v.Normalize();
QuaternionF q = new QuaternionF(0.0f, θ * v);
q.Exp();
Assert.IsTrue(Numeric.AreEqual(1, q.W));
Assert.IsTrue(Vector3F.AreNumericallyEqual(Vector3F.Zero, q.V));
}
示例12: Exp2
public void Exp2()
{
float θ = -0.3f;
Vector3F v = new Vector3F(1.0f, 2.0f, 3.0f);
v.Normalize();
QuaternionF q = new QuaternionF(0.0f, θ * v);
q.Exp();
Assert.IsTrue(Numeric.AreEqual((float)Math.Cos(θ), q.W));
Assert.IsTrue(Vector3F.AreNumericallyEqual((float)Math.Sin(θ) * v, q.V));
}