本文整理汇总了C#中Vector3.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Add方法的具体用法?C# Vector3.Add怎么用?C# Vector3.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAnchorGuess
private static Vector3 GetAnchorGuess(Entity connectionA, Entity connectionB)
{
var anchor = new Vector3();
if (connectionA != null)
anchor.Add( ref connectionA.position, out anchor );
if (connectionB != null)
anchor.Add( ref connectionB.position, out anchor );
if (connectionA != null && connectionB != null)
anchor.Mult( 0.5f, out anchor );
return anchor;
}
示例2: When_Adding_Two_Vectors_Vector_With_Result_Is_Returned
public void When_Adding_Two_Vectors_Vector_With_Result_Is_Returned()
{
// Arrange
Vector3 vectorOne = new Vector3(1.0, 1.0, 1.0);
Vector3 vectorTwo = new Vector3(2.0, 3.0, 4.0);
// Act
Vector3 result = vectorOne.Add(vectorTwo);
// Assert
Assert.AreEqual(3, result.X);
Assert.AreEqual(4, result.Y);
Assert.AreEqual(5, result.Z);
}
示例3: HitTest
private bool HitTest(Vector3 origin, Vector3 direction, float maxDistance, float stepSize, out Vector3 hitPos, out float iterations)
{
Vector3 step = direction.Mul(stepSize);
hitPos = origin.Add(step);
iterations = 0;
while (hitPos.Sub(ref origin).Len() < maxDistance)
{
iterations = fractal.HitTest(hitPos);
if (iterations >= threshold)
{
return true;
}
hitPos.AddAssign(ref step);
}
return false;
}
示例4: AdjustContrast
/// <summary>
/// Adjusts the contrast of a pixel.
/// </summary>
/// <param name="argb">The ARGB pixel to adjust.</param>
/// <param name="scale">The value to scale the contrast by.</param>
/// <returns>The adjusted ARGB pixel.</returns>
public static int AdjustContrast(int argb, float scale)
{
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF;
int g = (argb >> 8) & 0xFF;
int b = (argb) & 0xFF;
Vector3 res = new Vector3(r, g, b);
res.Multiply(1 / 255.0f);
res.Subtract(0.5f);
res.Multiply(scale);
res.Add(0.5f);
res.Multiply(255.0f);
res.Clamp(0, 255);
r = (int)res.X;
g = (int)res.Y;
b = (int)res.Z;
return (a << 24) | (r << 16) | (g << 8) | b;
}
示例5: 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;
}
}
//.........这里部分代码省略.........
示例6: Main
public static void Main (String[] args) {
spheres[0] = (new Sphere(
new Vector3(0, -10002, 0),
9999,
new Vector3(1, 1, 1),
false));
spheres[1] = (new Sphere(
new Vector3(-10012, 0, 0),
9999,
new Vector3(1, 0, 0),
false));
spheres[2] = (new Sphere(
new Vector3(10012, 0, 0),
9999,
new Vector3(0, 1, 0),
false));
spheres[3] = (new Sphere(
new Vector3(0, 0, -10012),
9999,
new Vector3(1, 1, 1),
false));
spheres[4] = (new Sphere(
new Vector3(0, 10012, 0),
9999,
new Vector3(1, 1, 1),
true));
spheres[5] = (new Sphere(
new Vector3(-5, 0, 2),
2,
new Vector3(1, 1, 0),
false));
spheres[6] = (new Sphere(
new Vector3(0, 5, -1),
4,
new Vector3(1, 0, 0),
false));
spheres[7] = (new Sphere(
new Vector3(8, 5, -1),
2,
new Vector3(0, 0, 1),
false));
var data = new Vector3[RayBench.HEIGHT][];
var cam = new Camera();
var vdu = cam.rt.Sub(cam.lt).Div(RayBench.WIDTH);
var vdv = cam.lb.Sub(cam.lt).Div(RayBench.HEIGHT);
var options = new ParallelOptions();
options.MaxDegreeOfParallelism = 4;
//for(int y = 0; y < RayBench.HEIGHT; ++y) {
Parallel.For(0, RayBench.HEIGHT, options, y => {
data[y] = new Vector3[RayBench.WIDTH];
for(int x = 0; x < RayBench.WIDTH; ++x) {
var color = new Vector3();
var ray = new Ray();
ray.origin = cam.eye;
for(int i = 0; i < RayBench.SAMPLES; ++i) {
ray.direction = cam.lt.Add(
vdu.Mul((float)(x + rnd.NextDouble())).Add(
vdv.Mul((float)(y + rnd.NextDouble()))));
ray.direction = ray.direction.Sub(ray.origin);
ray.direction = ray.direction.Unit();
color = color.Add(RayBench.trace(ray, 0));
}
color = color.Div(RayBench.SAMPLES);
data[y][x] = color;
}
});
RayBench.WritePPM(data);
}
示例7: Align
public void Align(Vector3 v1, Vector3 v2)
{
// If V1 and V2 are not parallel, the axis of rotation is the unit-length
// vector U = Cross(V1,V2)/Length(Cross(V1,V2)). The angle of rotation,
// A, is the angle between V1 and V2. The quaternion for the rotation is
// q = cos(A/2) + sin(A/2)*(ux*i+uy*j+uz*k) where U = (ux,uy,uz).
//
// (1) Rather than extract A = acos(Dot(V1,V2)), multiply by 1/2, then
// compute sin(A/2) and cos(A/2), we reduce the computational costs by
// computing the bisector B = (V1+V2)/Length(V1+V2), so cos(A/2) =
// Dot(V1,B).
//
// (2) The rotation axis is U = Cross(V1,B)/Length(Cross(V1,B)), but
// Length(Cross(V1,B)) = Length(V1)*Length(B)*sin(A/2) = sin(A/2), in
// which case sin(A/2)*(ux*i+uy*j+uz*k) = (cx*i+cy*j+cz*k) where
// C = Cross(V1,B).
//
// If V1 = V2, then B = V1, cos(A/2) = 1, and U = (0,0,0). If V1 = -V2,
// then B = 0. This can happen even if V1 is approximately -V2 using
// floating point arithmetic, since Vector3::Normalize checks for
// closeness to zero and returns the zero vector accordingly. The test
// for exactly zero is usually not recommend for floating point
// arithmetic, but the implementation of Vector3::Normalize guarantees
// the comparison is robust. In this case, the A = pi and any axis
// perpendicular to V1 may be used as the rotation axis.
var bisector = v1.Add(v2);
bisector.Normalise();
var cosHalfAngle = v1.Dot(bisector);
Vector3 cross;
tuple[0] = cosHalfAngle;
if (cosHalfAngle != 0)
{
cross = v1.Cross(bisector);
tuple[1] = cross.tuple[0];
tuple[2] = cross.tuple[1];
tuple[3] = cross.tuple[2];
}
else
{
double invLength;
if (System.Math.Abs(v1.tuple[0]) >= System.Math.Abs(v1.tuple[1]))
{
// V1.x or V1.z is the largest magnitude component
invLength = 1 / System.Math.Sqrt(v1.tuple[0] * v1.tuple[0]
+ v1.tuple[2] * v1.tuple[2]);
tuple[1] = - v1.tuple[2] * invLength;
tuple[2] = 0;
tuple[3] = + v1.tuple[0] * invLength;
}
else
{
// V1.y or V1.z is the largest magnitude component
invLength = 1 / System.Math.Sqrt(v1.tuple[1] * v1.tuple[1]
+ v1.tuple[2] * v1.tuple[2]);
tuple[1] = 0;
tuple[2] = + v1.tuple[2] * invLength;
tuple[3] = - v1.tuple[1] * invLength;
}
}
}
示例8: terrenoMuyEmpinado
private bool terrenoMuyEmpinado(Vector3 origin, Vector3 direction)
{
Vector3 deltaXZ = direction * 5;
Vector3 target = new Vector3(origin.X, 0, origin.Z);
target.Add(deltaXZ);
float targetDeltaY = this.level.Terrain.getPosition(target.X, target.Z).Y - origin.Y;
//if(targetDeltaY > MAX_DELTA_Y)GuiController.Instance.Logger.log("Pendiente: " + origin.Y + " -> " + (origin.Y + targetDeltaY) + " = " + targetDeltaY );
return targetDeltaY > MAX_DELTA_Y;
}