本文整理汇总了C#中Vector3.Multiply方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Multiply方法的具体用法?C# Vector3.Multiply怎么用?C# Vector3.Multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.Multiply方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rotation
/// <summary>
/// Returns a Quaternion representing a rotation.
/// </summary>
/// <param name="axis">The axis to rotate around.</param>
/// <param name="angle">The angle to rotate by.</param>
/// <returns>A Quaternion representing the rotation.</returns>
public static Quaternion Rotation(Vector3 axis, double angle)
{
double real = Math.Cos(angle / 2.0);
Vector3 imaginary;
//normalize first
imaginary = axis.Multiply(1.0 / axis.Length());
imaginary = imaginary.Multiply(Math.Sin(angle / 2.0));
return new Quaternion(real, imaginary);
}
示例2: 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;
}
示例3: When_Multiplying_A_Vector_With_A_Scalar_Vector_With_Result_Is_Returned
public void When_Multiplying_A_Vector_With_A_Scalar_Vector_With_Result_Is_Returned()
{
// Arrange
Vector3 vectorOne = new Vector3(1.0, 2.0, 3.0);
double scalarOne = 2;
// Act
Vector3 result = vectorOne.Multiply(scalarOne);
// Assert
Assert.AreEqual(2, result.X);
Assert.AreEqual(4, result.Y);
Assert.AreEqual(6, result.Z);
}
示例4: Transform
public void Transform(ref Vector3 pos, ref Vector3 scale, ref Vector3 euler)
{
pos += translation;
scale.Multiply(this.scale);
euler += this.euler;
}
示例5: doCollideWithWorld
/// <summary>
/// Detección de colisiones recursiva
/// </summary>
public void doCollideWithWorld(TgcBoundingSphere characterSphere, Vector3 movementVector, List<IColisionable> obstaculos, int recursionDepth, ColisionInfo colisionInfo)
{
//Limitar recursividad
if (recursionDepth > 5)
{
return;
}
//Ver si la distancia a recorrer es para tener en cuenta
float distanceToTravelSq = movementVector.LengthSq();
if (distanceToTravelSq < EPSILON)
{
return;
}
//Posicion deseada
Vector3 originalSphereCenter = characterSphere.Center;
Vector3 nextSphereCenter = originalSphereCenter + movementVector;
//Buscar el punto de colision mas cercano de todos los objetos candidatos
float minCollisionDistSq = float.MaxValue;
Vector3 realMovementVector = movementVector;
TgcBoundingAxisAlignBox.Face collisionFace = null;
IColisionable collisionObstacle = null;
Vector3 nearestPolygonIntersectionPoint = Vector3.Empty;
foreach (IColisionable obstaculoBB in obstaculos)
{
//Obtener los polígonos que conforman las 6 caras del BoundingBox
TgcBoundingAxisAlignBox.Face[] bbFaces = obstaculoBB.GetTgcBoundingBox().computeFaces();
foreach (TgcBoundingAxisAlignBox.Face bbFace in bbFaces)
{
Vector3 pNormal = TgcCollisionUtils.getPlaneNormal(bbFace.Plane);
TgcRay movementRay = new TgcRay(originalSphereCenter, movementVector);
float brutePlaneDist;
Vector3 brutePlaneIntersectionPoint;
if (!TgcCollisionUtils.intersectRayPlane(movementRay, bbFace.Plane, out brutePlaneDist, out brutePlaneIntersectionPoint))
{
continue;
}
float movementRadiusLengthSq = Vector3.Multiply(movementVector, characterSphere.Radius).LengthSq();
if (brutePlaneDist * brutePlaneDist > movementRadiusLengthSq)
{
continue;
}
//Obtener punto de colisión en el plano, según la normal del plano
float pDist;
Vector3 planeIntersectionPoint;
Vector3 sphereIntersectionPoint;
TgcRay planeNormalRay = new TgcRay(originalSphereCenter, -pNormal);
bool embebbed = false;
bool collisionFound = false;
if (TgcCollisionUtils.intersectRayPlane(planeNormalRay, bbFace.Plane, out pDist, out planeIntersectionPoint))
{
//Ver si el plano está embebido en la esfera
if (pDist <= characterSphere.Radius)
{
embebbed = true;
//TODO: REVISAR ESTO, caso embebido a analizar con más detalle
sphereIntersectionPoint = originalSphereCenter - pNormal * characterSphere.Radius;
}
//Esta fuera de la esfera
else
{
//Obtener punto de colisión del contorno de la esfera según la normal del plano
sphereIntersectionPoint = originalSphereCenter - Vector3.Multiply(pNormal, characterSphere.Radius);
//Disparar un rayo desde el contorno de la esfera hacia el plano, con el vector de movimiento
TgcRay sphereMovementRay = new TgcRay(sphereIntersectionPoint, movementVector);
if (!TgcCollisionUtils.intersectRayPlane(sphereMovementRay, bbFace.Plane, out pDist, out planeIntersectionPoint))
{
//no hay colisión
continue;
}
}
//Ver si planeIntersectionPoint pertenece al polígono
Vector3 newMovementVector;
float newMoveDistSq;
Vector3 polygonIntersectionPoint;
if (pointInBounbingBoxFace(planeIntersectionPoint, bbFace))
{
if (embebbed)
{
//TODO: REVISAR ESTO, nunca debería pasar
//throw new Exception("El polígono está dentro de la esfera");
}
polygonIntersectionPoint = planeIntersectionPoint;
collisionFound = true;
}
else
//.........这里部分代码省略.........
示例6: 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;
}
}
//.........这里部分代码省略.........
示例7: When_Vector_Multiplied_With_A_Matrix_Vector_With_Result_Is_Returned
public void When_Vector_Multiplied_With_A_Matrix_Vector_With_Result_Is_Returned()
{
//Arrange
Vector3 vectorOne = new Vector3(3.0, 2.0, 1.0);
Matrix4 matrixOne = new Matrix4(1.0, 2.0, 3.0, 4.0, 2.0, 3.0, 4.0, 1.0, 3.0, 4.0, 1.0, 2.0, 4.0, 1.0, 2.0, 3.0);
//Act
Vector3 result = vectorOne.Multiply(matrixOne);
//Assert
Assert.AreEqual(result.X, 14.0);
Assert.AreEqual(result.Y, 17.0);
Assert.AreEqual(result.Z, 20.0);
}