本文整理汇总了C#中Ray.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.Scale方法的具体用法?C# Ray.Scale怎么用?C# Ray.Scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ray
的用法示例。
在下文中一共展示了Ray.Scale方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NegativeUniformScaling
public void NegativeUniformScaling()
{
Vector3F origin = new Vector3F(1, 2, 3);
Vector3F direction = new Vector3F(-2, 3, -5).Normalized;
float length = 100;
Ray ray = new Ray(origin, direction, length);
Vector3F endPoint = ray.Origin + ray.Direction * ray.Length;
Vector3F scale = new Vector3F(-3.5f);
origin *= scale;
direction = (direction * scale).Normalized;
length *= Math.Abs(scale.X);
endPoint *= scale;
ray.Scale(ref scale);
Assert.AreEqual(origin, ray.Origin);
Assert.AreEqual(direction, ray.Direction);
Assert.AreEqual(length, ray.Length);
Assert.IsTrue(Vector3F.AreNumericallyEqual(endPoint, ray.Origin + ray.Direction * ray.Length));
}
示例2: ComputeCollision
public override void ComputeCollision(ContactSet contactSet, CollisionQueryType type)
{
if (type == CollisionQueryType.ClosestPoints)
{
// Just use normal composite shape algorithm.
_triangleMeshAlgorithm.ComputeCollision(contactSet, type);
return;
}
Debug.Assert(type != CollisionQueryType.ClosestPoints, "Closest point queries should have already been handled!");
// Mesh = A, Ray = B
IGeometricObject meshObject = contactSet.ObjectA.GeometricObject;
IGeometricObject rayObject = contactSet.ObjectB.GeometricObject;
// Object A should be the mesh, swap objects if necessary.
bool swapped = (meshObject.Shape is RayShape);
if (swapped)
MathHelper.Swap(ref rayObject, ref meshObject);
RayShape rayShape = rayObject.Shape as RayShape;
TriangleMeshShape meshShape = meshObject.Shape as TriangleMeshShape;
// Check if shapes are correct.
if (rayShape == null || meshShape == null)
throw new ArgumentException("The contact set must contain a ray and a triangle mesh shape.", "contactSet");
// Assume no contact.
contactSet.HaveContact = false;
// Get transformations.
Vector3F rayScale = rayObject.Scale;
Pose rayPose = rayObject.Pose;
Vector3F meshScale = meshObject.Scale;
Pose meshPose = meshObject.Pose;
// Ray in world space.
Ray rayWorld = new Ray(rayShape);
rayWorld.Scale(ref rayScale); // Scale ray.
rayWorld.ToWorld(ref rayPose); // Transform ray to world space.
// Ray in local scaled space of the mesh.
Ray ray = rayWorld;
ray.ToLocal(ref meshPose); // Transform ray to local space of composite.
// Ray in local unscaled space of the mesh.
Ray rayUnscaled = ray;
var inverseCompositeScale = Vector3F.One / meshScale;
rayUnscaled.Scale(ref inverseCompositeScale);
ITriangleMesh triangleMesh = meshShape.Mesh;
bool isTwoSided = meshShape.IsTwoSided;
if (meshShape.Partition != null)
{
// ----- Mesh with BVH vs. Ray -----
foreach (var childIndex in meshShape.Partition.GetOverlaps(rayUnscaled))
{
Triangle triangle = triangleMesh.GetTriangle(childIndex);
AddContact(contactSet, swapped, type, ref rayWorld, ref ray, ref triangle, childIndex, ref meshPose, ref meshScale, isTwoSided);
if (type == CollisionQueryType.Boolean && contactSet.HaveContact)
break; // We can abort early.
}
}
else
{
// ----- Mesh vs. Ray -----
var rayUnscaledDirectionInverse = new Vector3F(
1 / rayUnscaled.Direction.X,
1 / rayUnscaled.Direction.Y,
1 / rayUnscaled.Direction.Z);
float epsilon = Numeric.EpsilonF * (1 + meshObject.Aabb.Extent.Length);
int numberOfTriangles = triangleMesh.NumberOfTriangles;
for (int i = 0; i < numberOfTriangles; i++)
{
Triangle triangle = triangleMesh.GetTriangle(i);
// Make ray vs AABB check first. We could skip this because the ray vs. triangle test
// is also fast. But experiments (ray vs sphere mesh) have shown that making an
// additional ray vs. AABB test first makes the worst case more than 20% faster.
if (GeometryHelper.HaveContact(triangle.Aabb, rayUnscaled.Origin, rayUnscaledDirectionInverse, rayUnscaled.Length, epsilon))
{
AddContact(contactSet, swapped, type, ref rayWorld, ref ray, ref triangle, i, ref meshPose, ref meshScale, isTwoSided);
// We have contact and stop for boolean queries.
if (contactSet.HaveContact && type == CollisionQueryType.Boolean)
break;
}
}
}
}
示例3: NonuniformScaling
public void NonuniformScaling()
{
Vector3F scale = new Vector3F(1, 2, 3);
Vector3F origin = new Vector3F(1, 2, 3);
Vector3F direction = new Vector3F(-2, 3, -5).Normalized;
float length = 100;
Ray ray = new Ray(origin, direction, length);
Vector3F endPoint = ray.Origin + ray.Direction * ray.Length;
ray.Scale(ref scale);
origin = origin * scale;
endPoint = endPoint * scale;
Assert.AreEqual(origin, ray.Origin);
Assert.AreEqual((endPoint - origin).Normalized, ray.Direction);
Assert.AreEqual((endPoint - origin).Length, ray.Length);
Assert.IsTrue(Vector3F.AreNumericallyEqual(endPoint, ray.Origin + ray.Direction * ray.Length));
}
示例4: PositiveUniformScaling
public void PositiveUniformScaling()
{
Vector3F origin = new Vector3F(1, 2, 3);
Vector3F direction = new Vector3F(-2, 3, -5).Normalized;
float length = 100;
Ray ray = new Ray(origin, direction, length);
Vector3F pointOnRay = ray.Origin + ray.Direction * 10;
Vector3F scale = new Vector3F(3.5f);
origin *= scale;
direction = (direction * scale).Normalized;
length *= scale.X;
pointOnRay *= scale;
ray.Scale(ref scale);
Assert.AreEqual(origin, ray.Origin);
Assert.AreEqual(direction, ray.Direction);
Assert.AreEqual(length, ray.Length);
Assert.IsTrue(Vector3F.AreNumericallyEqual(pointOnRay, ray.Origin + ray.Direction * 10 * 3.5f));
}