本文整理汇总了C#中System.Vector3.Dot方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Dot方法的具体用法?C# Vector3.Dot怎么用?C# Vector3.Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Vector3
的用法示例。
在下文中一共展示了Vector3.Dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
/// public メソッド
///---------------------------------------------------------------------------
/// カプセルと三角形との衝突
public bool Check( DemoGame.GeometryCapsule moveCap, ShapeTriangles trgShape )
{
Vector3 collPos = StaticDataList.getVectorZero();
calMovePos = moveCap.EndPos;
calBestDis = -1.0f;
calBestId = -1;
float checDis = moveCap.Line.Length + moveCap.R + collCheckDis;
if( AppDebug.CollLightFlg == false ){
for( int i=0; i<trgShape.EntryNum; i++ ){
float a = (calMovePos.Dot( trgShape.Triangle[i].Plane.Nor ) + trgShape.Triangle[i].Plane.D);
if( a >= checDis || a <= -checDis ){
continue;
}
if( DemoGame.CommonCollision.CheckSphereAndTriangle( moveCap, trgShape.Triangle[i], ref collPos ) == true ){
float dis = Common.VectorUtil.Distance( collPos, moveCap.StartPos );
if( dis < calBestDis || calBestId < 0 ){
calMovePos = collPos;
calBestDis = dis;
calBestId = i;
}
}
AppDebug.CollCnt ++;
}
}
else{
for( int i=0; i<trgShape.EntryNum; i++ ){
float a = (calMovePos.Dot( trgShape.Triangle[i].Plane.Nor ) + trgShape.Triangle[i].Plane.D);
if( a >= checDis || a <= -checDis ){
continue;
}
if( DemoGame.CommonCollision.CheckLineAndTriangle( moveCap.Line, trgShape.Triangle[i], ref collPos ) == true ){
float dis = Common.VectorUtil.Distance( collPos, moveCap.StartPos );
if( dis < calBestDis || calBestId < 0 ){
calMovePos = collPos;
calBestDis = dis;
calBestId = i;
}
}
AppDebug.CollCnt ++;
}
}
if( calBestId >= 0 ){
return true;
}
return false;
}
示例2: AnyOrthogonalShouldWork
public void AnyOrthogonalShouldWork()
{
var r = new Random();
for (int i = 0; i < 1000; i++)
{
var v = new Vector3((double) r.NextDouble(), (double) r.NextDouble(), (double) r.NextDouble());
var o = v.Orthogonal();
v.Dot(o).Should().BeApproximately(0, 1e-9);
}
}
示例3: CheckNearDis
/// 最近接距離を求める
public float CheckNearDis( Vector3 pos )
{
float isDis = 0.0f;
float bestDis = 0.0f;
/// 面単位で確認すればいいので1つ飛ばしで判定
for( int i=0; i<EntryNum; i+=2 ){
isDis = pos.Dot( Triangle[i].Plane.Nor ) + Triangle[i].Plane.D;
if( i == 0 || isDis > bestDis ){
bestDis = isDis;
}
}
return bestDis;
}
示例4: CheckNearDis
/// 最近接距離を求める
public float CheckNearDis( Vector3 pos )
{
float isDis = 0.0f;
float bestDis = 0.0f;
/// 上面
bestDis = pos.Dot( Triangle[0].Plane.Nor ) + Triangle[0].Plane.D;
/// 下面
bestDis = pos.Dot( Triangle[1].Plane.Nor ) + Triangle[1].Plane.D;
if( isDis > bestDis ){
bestDis = isDis;
}
/// 右側面
bestDis = pos.Dot( Triangle[EntryNum-4].Plane.Nor ) + Triangle[EntryNum-4].Plane.D;
if( isDis > bestDis ){
bestDis = isDis;
}
/// 左側面
bestDis = pos.Dot( Triangle[EntryNum-2].Plane.Nor ) + Triangle[EntryNum-2].Plane.D;
if( isDis > bestDis ){
bestDis = isDis;
}
/// 遠面
for( int i=0; i<objDivisionNum; i++ ){
isDis = pos.Dot( Triangle[i*4+2].Plane.Nor ) + Triangle[i*4+2].Plane.D;
if( i == 0 || isDis > bestDis ){
bestDis = isDis;
}
}
return bestDis;
}
示例5: GetRotationAngle
public static double GetRotationAngle(
Vector3 rotationStatus,
double rotationValue,
Vector3 rotationAxis)
{
double angle = 0.0;
if (rotationStatus.Dot (rotationAxis) >= 0.0)
{
angle = 2.0 * Math.Atan2 (rotationStatus.Length (), rotationValue);
}
else
{
angle = 2.0 * Math.Atan2 (rotationStatus.Length (), -rotationValue);
}
return (angle > Math.PI) ? angle - 2.0 * Math.PI : angle;
}
示例6: Reflect
/// <summary>
/// <para>Reflects a vector off the plane defined by a normal.</para>
/// </summary>
/// <param name="inDirection"></param>
/// <param name="inNormal"></param>
public static Vector3<byte> Reflect(this Vector3<byte> inDirection, Vector3<byte> inNormal)
{
//In case of bytes it is -2 * some byte (which is byte). Dot product is closed under bytes so this is valid for bytes.
byte twoTimesDotNDir = (byte)(-2 * (int)inNormal.Dot(inDirection));
//this operation is also closed for bytes. We do not need to make an extension method.
return (twoTimesDotNDir * inNormal) + inDirection;
}
示例7: Project
/// <summary>
/// <para>Projects a vector onto another vector.</para>
/// </summary>
/// <param name="vector"></param>
/// <param name="onNormal"></param>
public static Vector3<float> Project(this Vector3<float> vector, Vector3<float> onNormal)
{
//return ProjectInternalGeneric(vector, onNormal);
float single = onNormal.Dot(onNormal);
if (single < Vector3<float>.kEpsilon)
{
return Vector3<float>.zero;
}
return (onNormal * vector.Dot(onNormal)) * (1.0f / single);
}
示例8: ProcessTriangle
public override void ProcessTriangle(ref Vector3 point0, ref Vector3 point1, ref Vector3 point2, int partId, int triangleIndex)
{
Vector3 v10 = point1 - point0;
Vector3 v20 = point2 - point0;
Vector3 triangleNormal = v10.Cross(v20);
float dist;
point0.Dot(ref triangleNormal, out dist);
float distA = triangleNormal.Dot(From) - dist;
float distB = triangleNormal.Dot(To) - dist;
if (distA * distB >= 0.0f)
{
return; // same sign
}
if (((Flags & EFlags.FilterBackfaces) != 0) && (distA <= 0.0f))
{
// Backface, skip check
return;
}
float proj_length = distA - distB;
float distance = (distA) / (proj_length);
// Now we have the intersection point on the plane, we'll see if it's inside the triangle
// Add an epsilon as a tolerance for the raycast,
// in case the ray hits exacly on the edge of the triangle.
// It must be scaled for the triangle size.
if (distance < HitFraction)
{
float edgeTolerance = triangleNormal.LengthSquared;
edgeTolerance *= -0.0001f;
Vector3 point = Vector3.Lerp(From, To, distance);
{
Vector3 v0p; v0p = point0 - point;
Vector3 v1p; v1p = point1 - point;
Vector3 cp0; cp0 = v0p.Cross(v1p);
float dot;
cp0.Dot(ref triangleNormal, out dot);
if (dot >= edgeTolerance)
{
Vector3 v2p; v2p = point2 - point;
Vector3 cp1;
cp1 = v1p.Cross(v2p);
cp1.Dot(ref triangleNormal, out dot);
if (dot >= edgeTolerance)
{
Vector3 cp2;
cp2 = v2p.Cross(v0p);
cp2.Dot(ref triangleNormal, out dot);
if (dot >= edgeTolerance)
{
//@BP Mod
// Triangle normal isn't normalized
triangleNormal.Normalize();
//@BP Mod - Allow for unflipped normal when raycasting against backfaces
if (((Flags & EFlags.KeepUnflippedNormal) == 0) && (distA <= 0.0f))
{
triangleNormal = -triangleNormal;
}
HitFraction = ReportHit(ref triangleNormal, distance, partId, triangleIndex);
}
}
}
}
}
}
示例9: return
public static IBody2 CreateSemiCirclularSheet
( this IModeler modeler
, Vector3 center
, Vector3 vNormal
, Vector3 vRef // Horizontal
, double radius)
{
// Should be orthogonal
Debug.Assert(vRef.Dot(vNormal)<1e-9);
var math = SwAddinBase.Active.Math;
var centerSw = center.ToSwMathPoint();
var vNormalSw = vNormal.ToSwMathPoint();
var vNormalOrthSw = vRef.ToSWVector(math).Normalise();
var centerDbls = centerSw.ArrayData;
var vNormalDbls = vNormalSw.ArrayData;
var vNormalOrthDbls = vNormalOrthSw.ArrayData;
var surf = (Surface) modeler.CreatePlanarSurface2(centerDbls, vNormalDbls, vNormalOrthDbls);
var startPoint = center + radius*vRef.Unit();
var endPoint = center - radius*vRef.Unit();
var startPointDbls = startPoint.ToDoubles();
var endPointDbls = endPoint.ToDoubles();
var arco = modeler.CreateArc
(centerDbls, vNormalDbls, radius, startPointDbls, endPointDbls);
var arc = (Curve) arco;
var arcStartPoint = startPoint;
var arcEndPoint = endPoint;
var trimmedArc = arc.CreateTrimmedCurve2(arcStartPoint.X,arcStartPoint.Y,arcStartPoint.Z,arcEndPoint.X,arcEndPoint.Y,arcEndPoint.Z);
var line = modeler.CreateTrimmedLine(arcEndPoint, arcStartPoint);
return (IBody2) surf.CreateTrimmedSheet(new[] {trimmedArc, line});
}
示例10: FromAxisAngle
public static Vector4 FromAxisAngle(Vector3 axis, float angle)
{
if (axis.Dot() == 0.0f)
return Identity;
Vector4 result = Identity;
angle *= 0.5f;
axis.Normalize();
result._x = axis._x * (float)System.Math.Sin(angle);
result._y = axis._y * (float)System.Math.Sin(angle);
result._z = axis._z * (float)System.Math.Sin(angle);
result._w = (float)System.Math.Cos(angle);
return result.Normalize();
}
示例11: LinePlaneIntersect
public static bool LinePlaneIntersect(Vector3 lineStart, Vector3 lineEnd, Vector3 planePoint, Vector3 planeNormal, out Vector3 result)
{
Vector3 diff = lineEnd - lineStart;
float scale = -planeNormal.Dot(lineStart - planePoint) / planeNormal.Dot(diff);
if (float.IsNaN(scale) || scale < 0.0f || scale > 1.0f)
{
result = new Vector3();
return false;
}
result = lineStart + (diff * scale);
return true;
}
示例12: dot
public void dot() {
var a = new Vector3(5, 2, -1);
var b = new Vector3(3, -3, 0);
Assert.Equal(9, a.Dot(b));
Assert.Equal(9, b.Dot(a));
}
示例13: CheckTriangle
/// ラインと三角形との衝突
public bool CheckTriangle( DemoGame.GeometryLine moveLine, ShapeTriangles trgShape )
{
Vector3 collPos = new Vector3(0,0,0);
calMovePos = moveLine.EndPos;
calBestDis = -1.0f;
calBestId = -1;
float checDis = moveLine.Length + collCheckDis;
for( int i=0; i<trgShape.EntryNum; i++ ){
float a = (calMovePos.Dot( trgShape.Triangle[i].Plane.Nor ) + trgShape.Triangle[i].Plane.D);
if( a >= checDis || a <= -checDis ){
continue;
}
if( DemoGame.CommonCollision.CheckLineAndTriangle( moveLine, trgShape.Triangle[i], ref collPos ) == true ){
float dis = Common.VectorUtil.Distance( collPos, moveLine.StartPos );
if( dis < calBestDis || calBestId < 0 ){
calMovePos = collPos;
calBestDis = dis;
calBestId = i;
}
}
}
if( calBestId >= 0 ){
return true;
}
return false;
}
示例14: GetClosestPtPosRay
/// 点と線分の最近接点を算出
public static float GetClosestPtPosRay( Vector3 trgPos, Vector3 trgRay, Vector3 trgRayPos, ref Vector3 cPos )
{
Vector3 ab, ca;
float a_t;
float a_dotCA;
float a_dotAA;
ab = trgRay;
ca = trgPos - trgRayPos;
a_dotCA = ca.Dot( ab );
a_dotAA = ab.Dot( ab );
if( a_dotAA <= epsilon ){
a_t = 0.0f;
}
else{
a_t = (a_dotCA / a_dotAA);
}
// if( a_t < epsilon ){
// a_t = 0.0f;
// }
// else if( a_t > 1.0f ){
// a_t = 1.0f;
// }
/// 最近接点の算出
cPos.X = trgRayPos.X + ( a_t * ab.X );
cPos.Y = trgRayPos.Y + ( a_t * ab.Y );
cPos.Z = trgRayPos.Z + ( a_t * ab.Z );
/// 最近接点と点との距離を返す
Vector3 calVec = trgPos - cPos;
float dis = FMath.Sqrt( calVec.Dot(calVec) );
return dis;
}
示例15: LineSphereIntersect
public static bool LineSphereIntersect(Vector3 start, Vector3 end, Vector3 center, float radius, out Vector3 result)
{
Vector3 diff = end - start;
float a = diff.Dot();
if (a > 0.0f)
{
float b = 2 * diff.Dot(start - center);
float c = (center.Dot() + start.Dot()) - (2 * center.Dot(start)) - (radius * radius);
float magnitude = (b * b) - (4 * a * c);
if (magnitude >= 0.0f)
{
magnitude = (float)Math.Sqrt(magnitude);
a *= 2;
float scale = (-b + magnitude) / a;
float dist2 = (-b - magnitude) / a;
if (dist2 < scale)
scale = dist2;
result = start + (diff * scale);
return true;
}
}
result = new Vector3();
return false;
}