当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.Cross方法代码示例

本文整理汇总了C#中Vector3.Cross方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Cross方法的具体用法?C# Vector3.Cross怎么用?C# Vector3.Cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector3的用法示例。


在下文中一共展示了Vector3.Cross方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Vector3

        public static Vector3 operator *(Quaternion xform, Vector3 vec)
        {
            /* From nVidia SDK */
            Vector3 uv, uuv;
            Vector3 qvec = new Vector3(xform.X, xform.Y, xform.Z);

            uv = qvec.Cross(vec);
            uuv = qvec.Cross(uv);
            uv *= (2.0f * xform.W);
            uuv *= 2.0f;

            return vec + uv + uuv;
        }
开发者ID:BackupTheBerlios,项目名称:flatfour-svn,代码行数:13,代码来源:Quaternion.cs

示例2: Quaternion

        /// <summary>
        /// Initializes a new instance of the <see cref="Quaternion"/> class.
        /// </summary>
        /// <param name="sourcePosition">The source position.</param>
        /// <param name="destinationPosition">The destination position.</param>
        public Quaternion(Vector3 sourcePosition, Vector3 destinationPosition)
        {
            var r = sourcePosition.Cross(destinationPosition);
            var s = Functions.Sqrt(2 * (1 + sourcePosition.Dot(destinationPosition)));

            mValues = new Vector4(r / s, s / 2);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:12,代码来源:Quaternion.cs

示例3: Cross

        public void Cross()
        {
            var vector1 = new Vector3(2.0f, 3.0f, 4.0f);
            var vector2 = new Vector3(5.0f, 6.0f, 7.0f);

            var cross = vector1.Cross(vector2);
            Assert.AreEqual(-3.0f, cross.X);
            Assert.AreEqual(6.0f, cross.Y);
            Assert.AreEqual(-3.0f, cross.Z);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:10,代码来源:Test_Vector3.cs

示例4: VecToRad

        /// <summary>
        /// 2つのベクトルがなす角をかえす
        /// </summary>
        /// <param name="vecA"></param>
        /// <param name="vecB"></param>
        /// <returns></returns>
        public static double VecToRad( Vector3 vecA, Vector3 vecB )
        {
            vecA.Normalize();
            vecB.Normalize();

            double dir = (double)(Axiom.Math.Utility.ASin(vecA.Dot(vecB)) - Axiom.Math.Utility.HALF_PI);
            Vector3 resVec = vecA.Cross(vecB);
            if (resVec.z < 0) dir = -dir;

            return dir;
        }
开发者ID:terakenxx,项目名称:TukubaChallenge,代码行数:17,代码来源:Rooting.cs

示例5: MeshTriangle

        public MeshTriangle(byte id, Vector3 p0, Vector3 p1, Vector3 p2)
        {
            Id = id;
            P0 = p0;
            P1 = p1;
            P2 = p2;

            Points = new List<Vector3>{P0, P1, P2};
            U = P1 - P0;
            V = P2 - P0;
            Normal = U.Cross(V).NormalizeRet();

            Direction = CalculateDirection();
            UU = U.Dot(U);
            VV = V.Dot(V);
            UV = U.Dot(V);

            D = UV * UV - UU * VV;
        }
开发者ID:HaKDMoDz,项目名称:Psy,代码行数:19,代码来源:MeshTriangle.cs

示例6: Vector3

        /// Multiply a Vector3.
        public static Vector3 operator *(Quaternion lhs, Vector3 rhs)
        {
            Vector3 qVec = new Vector3(lhs.x_, lhs.y_, lhs.z_);
            Vector3 cross1 = qVec.Cross(rhs);
            Vector3 cross2 = qVec.Cross(cross1);

            return rhs + (cross1 * lhs.w_ + cross2) * 2.0f;
        }
开发者ID:CodeMason,项目名称:ImageBasedMocap,代码行数:9,代码来源:Quaternion.cs

示例7: CreatePlane

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">Name of the plane mesh.</param>
        /// <param name="plane">Plane to use for distance and orientation of the mesh.</param>
        /// <param name="width">Width in world coordinates.</param>
        /// <param name="height">Height in world coordinates.</param>
        /// <param name="xSegments">Number of x segments for tesselation.</param>
        /// <param name="ySegments">Number of y segments for tesselation.</param>
        /// <param name="normals">If true, plane normals are created.</param>
        /// <param name="numTexCoordSets">Number of 2d texture coord sets to use.</param>
        /// <param name="uTile">Number of times the texture should be repeated in the u direction.</param>
        /// <param name="vTile">Number of times the texture should be repeated in the v direction.</param>
        /// <param name="upVec">The up direction of the plane.</param>
        /// <returns></returns>
        public Mesh CreatePlane(string name, Plane plane, float width, float height, int xSegments, int ySegments, bool normals, int numTexCoordSets, float uTile, float vTile, Vector3 upVec,
            BufferUsage vertexBufferUsage, BufferUsage indexBufferUsage, bool vertexShadowBuffer, bool indexShadowBuffer )
        {
            Mesh mesh = CreateManual(name);
            SubMesh subMesh = mesh.CreateSubMesh(name + "SubMesh");

            mesh.SharedVertexData = new VertexData();
            VertexData vertexData = mesh.SharedVertexData;

            VertexDeclaration decl = vertexData.vertexDeclaration;
            int currOffset = 0;

            // add position data
            decl.AddElement(0, currOffset, VertexElementType.Float3, VertexElementSemantic.Position);
            currOffset += VertexElement.GetTypeSize(VertexElementType.Float3);

            // normals are optional
            if(normals) {
                decl.AddElement(0, currOffset, VertexElementType.Float3, VertexElementSemantic.Normal);
                currOffset += VertexElement.GetTypeSize(VertexElementType.Float3);
            }

            // add texture coords
            for(ushort i = 0; i < numTexCoordSets; i++) {
                decl.AddElement(0, currOffset, VertexElementType.Float2, VertexElementSemantic.TexCoords, i);
                currOffset += VertexElement.GetTypeSize(VertexElementType.Float2);
            }

            vertexData.vertexCount = (xSegments + 1) * (ySegments + 1);

            // create a new vertex buffer (based on current API)
            HardwareVertexBuffer vbuf =
                HardwareBufferManager.Instance.CreateVertexBuffer(decl.GetVertexSize(0), vertexData.vertexCount, vertexBufferUsage, vertexShadowBuffer);

            // get a reference to the vertex buffer binding
            VertexBufferBinding binding = vertexData.vertexBufferBinding;

            // bind the first vertex buffer
            binding.SetBinding(0, vbuf);

            // transform the plane based on its plane def
            Matrix4 translate = Matrix4.Identity;
            Matrix4 transform = Matrix4.Zero;
            Matrix4 rotation = Matrix4.Identity;
            Matrix3 rot3x3 = Matrix3.Zero;

            Vector3 xAxis, yAxis, zAxis;
            zAxis = plane.Normal;
            zAxis.Normalize();
            yAxis = upVec;
            yAxis.Normalize();
            xAxis = yAxis.Cross(zAxis);

            if (xAxis.Length == 0) {
                throw new AxiomException("The up vector for a plane cannot be parallel to the planes normal.");
            }

            rot3x3.FromAxes(xAxis, yAxis, zAxis);
            rotation = rot3x3;

            // set up transform from origin
            translate.Translation = plane.Normal * -plane.D;

            transform = translate * rotation;

            float xSpace = width / xSegments;
            float ySpace = height / ySegments;
            float halfWidth = width / 2;
            float halfHeight = height / 2;
            float xTexCoord = (1.0f * uTile) / xSegments;
            float yTexCoord = (1.0f * vTile) / ySegments;
            Vector3 vec = Vector3.Zero;
            Vector3 min = Vector3.Zero;
            Vector3 max = Vector3.Zero;
            float maxSquaredLength = 0;
            bool firstTime = true;

            // generate vertex data
            GeneratePlaneVertexData(vbuf, ySegments, xSegments, xSpace, halfWidth, ySpace, halfHeight, transform, firstTime, normals, rotation, numTexCoordSets, xTexCoord, yTexCoord, subMesh, ref min, ref max, ref maxSquaredLength);

            // generate face list
            Tesselate2DMesh(subMesh, xSegments + 1, ySegments + 1, false, indexBufferUsage, indexShadowBuffer);

            // generate bounds for the mesh
            mesh.BoundingBox = new AxisAlignedBox(min, max);
//.........这里部分代码省略.........
开发者ID:ufosky-server,项目名称:MultiversePlatform,代码行数:101,代码来源:MeshManager.cs

示例8: CreateCurvedIllusionPlane

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="plane"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="curvature"></param>
        /// <param name="xSegments"></param>
        /// <param name="ySegments"></param>
        /// <param name="normals"></param>
        /// <param name="numberOfTexCoordSets"></param>
        /// <param name="uTiles"></param>
        /// <param name="vTiles"></param>
        /// <param name="upVector"></param>
        /// <param name="orientation"></param>
        /// <param name="vertexBufferUsage"></param>
        /// <param name="indexBufferUsage"></param>
        /// <param name="vertexShadowBuffer"></param>
        /// <param name="indexShadowBuffer"></param>
        /// <returns></returns>
        public Mesh CreateCurvedIllusionPlane(string name, Plane plane, float width, float height, float curvature, int xSegments, int ySegments, bool normals, int numberOfTexCoordSets, float uTiles, float vTiles, Vector3 upVector, Quaternion orientation, BufferUsage vertexBufferUsage, BufferUsage indexBufferUsage, bool vertexShadowBuffer, bool indexShadowBuffer)
        {
            Mesh mesh = CreateManual(name);
            SubMesh subMesh = mesh.CreateSubMesh(name + "SubMesh");

            // set up vertex data, use a single shared buffer
            mesh.SharedVertexData = new VertexData();
            VertexData vertexData = mesh.SharedVertexData;

            // set up vertex declaration
            VertexDeclaration vertexDeclaration = vertexData.vertexDeclaration;
            int currentOffset = 0;

            // always need positions
            vertexDeclaration.AddElement(0, currentOffset, VertexElementType.Float3, VertexElementSemantic.Position);
            currentOffset += VertexElement.GetTypeSize(VertexElementType.Float3);

            // optional normals
            if(normals) {
                vertexDeclaration.AddElement(0, currentOffset, VertexElementType.Float3, VertexElementSemantic.Normal);
                currentOffset += VertexElement.GetTypeSize(VertexElementType.Float3);
            }

            for(ushort i = 0; i < numberOfTexCoordSets; i++) {
                // assumes 2d texture coordinates
                vertexDeclaration.AddElement(0, currentOffset, VertexElementType.Float2, VertexElementSemantic.TexCoords, i);
                currentOffset += VertexElement.GetTypeSize(VertexElementType.Float2);
            }

            vertexData.vertexCount = (xSegments + 1) * (ySegments + 1);

            // allocate vertex buffer
            HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer(vertexDeclaration.GetVertexSize(0), vertexData.vertexCount, vertexBufferUsage, vertexShadowBuffer);

            // set up the binding, one source only
            VertexBufferBinding binding = vertexData.vertexBufferBinding;
            binding.SetBinding(0, vertexBuffer);

            // work out the transform required, default orientation of plane is normal along +z, distance 0
            Matrix4 xlate, xform, rot;
            Matrix3 rot3 = Matrix3.Identity;
            xlate = rot = Matrix4.Identity;

            // determine axes
            Vector3 zAxis, yAxis, xAxis;
            zAxis = plane.Normal;
            zAxis.Normalize();
            yAxis = upVector;
            yAxis.Normalize();
            xAxis = yAxis.Cross(zAxis);
            if(xAxis.Length == 0) {
                throw new AxiomException("The up vector for a plane cannot be parallel to the planes normal.");
            }

            rot3.FromAxes(xAxis, yAxis, zAxis);
            rot = rot3;

            // set up standard xform from origin
            xlate.Translation = plane.Normal * -plane.D;

            // concatenate
            xform = xlate * rot;

            // generate vertex data, imagine a large sphere with the camera located near the top,
            // the lower the curvature, the larger the sphere.  use the angle from the viewer to the
            // points on the plane
            float cameraPosition;      // camera position relative to the sphere center

            // derive sphere radius (unused)
            //float sphereDistance;      // distance from the camera to the sphere along box vertex vector
            float sphereRadius;

            // actual values irrelevant, it's the relation between the sphere's radius and the camera's position which is important
            float SPHERE_RADIUS = 100;
            float CAMERA_DISTANCE = 5;
            sphereRadius = SPHERE_RADIUS - curvature;
            cameraPosition = sphereRadius - CAMERA_DISTANCE;

            // lock the whole buffer
//.........这里部分代码省略.........
开发者ID:ufosky-server,项目名称:MultiversePlatform,代码行数:101,代码来源:MeshManager.cs

示例9: VecToRad

        /// <summary>
        /// 2つのベクトルがなす角をかえす
        /// </summary>
        /// <param name="vecA"></param>
        /// <param name="vecB"></param>
        /// <returns></returns>
        public double VecToRad(Vector3 vecA, Vector3 vecB)
        {
            vecA.Normalize();
            vecB.Normalize();

            double rad = vecA.Dot(vecB);
            if (rad > 1.0) rad = 1.0;

            double dir = (double)(Math.Asin(rad) - (Math.PI / 2.0));

            if (double.IsNaN(dir))
            {
                Debug.Write("NAn");
            }

            Vector3 resVec = vecA.Cross(vecB);
            if (resVec.z > 0) dir = -dir;

            return dir;
        }
开发者ID:terakenxx,项目名称:TukubaChallenge,代码行数:26,代码来源:CarSim.cs

示例10: LookAt

        public static Matrix3 LookAt(Vector3 forward, Vector3 up)
        {
            var Z = forward.Normalize();
            var X = up.Cross(Z).Normalize();
            var Y = Z.Cross(X);

            return new Matrix3(X, Y, Z);
        }
开发者ID:reignstudios,项目名称:ReignSDK,代码行数:8,代码来源:Matrix3.cs

示例11: Vector3

        /// <summary>
        /// Concatenates two quaternions. The right argument is applied first.
        /// </summary>
        /// <param name="left">The left operand which is applied after the right one.</param>
        /// <param name="right">The right operand which is applied first.</param>
        /// <returns>A quaternion containing the rotations of both given quaternions.</returns>
        public static Quaternion operator *(Quaternion left, Quaternion right)
        {
            var v1 = new Vector3(right.X, right.Y, right.Z);
            var v2 = new Vector3(left.X, left.Y, left.Z);

            var w = left.W * right.W - v1.Dot(v2);
            var v = right.W * v2 + left.W * v1 + v2.Cross(v1);

            return new Quaternion(v, w);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:16,代码来源:Quaternion.cs

示例12: LookAtRH

        public static Matrix LookAtRH(Vector3 eye, Vector3 at, Vector3 up)
        {
            var result = new Matrix();

            Vector3 vectorNormal = (at - eye).Normal;
            Vector3 right = up.Cross(vectorNormal);
            Vector3 rightNormal = right.Normal;
            Vector3 upNormal = vectorNormal.Cross(right).Normal;

            result[0, 0] = -rightNormal.X;
            result[1, 0] = -rightNormal.Y;
            result[2, 0] = -rightNormal.Z;
            result[3, 0] = rightNormal.Dot(eye);
            result[0, 1] = upNormal.X;
            result[1, 1] = upNormal.Y;
            result[2, 1] = upNormal.Z;
            result[3, 1] = -upNormal.Dot(eye);
            result[0, 2] = -vectorNormal.X;
            result[1, 2] = -vectorNormal.Y;
            result[2, 2] = -vectorNormal.Z;
            result[3, 2] = vectorNormal.Dot(eye);
            result[0, 3] = 0.0f;
            result[1, 3] = 0.0f;
            result[2, 3] = 0.0f;
            result[3, 3] = 1.0f;

            return result;
        }
开发者ID:alex-v-odesk,项目名称:IceFlake,代码行数:28,代码来源:Matrix.cs

示例13: Vector3

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quat"></param>
		/// <param name="vector"></param>
		/// <returns></returns>
		public static Vector3 operator *( Quaternion quat, Vector3 vector )
		{
			// nVidia SDK implementation
			Vector3 uv, uuv;
			var qvec = new Vector3( quat.x, quat.y, quat.z );

			uv = qvec.Cross( vector );
			uuv = qvec.Cross( uv );
			uv *= ( 2.0f*quat.w );
			uuv *= 2.0f;

			return vector + uv + uuv;

			// get the rotation matrix of the Quaternion and multiply it times the vector
			//return quat.ToRotationMatrix() * vector;
		}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:22,代码来源:Quaternion.cs

示例14: GetRotationTo

        /// <summary>
        /// Gets the shortest arc quaternion to rotate this vector to the destination vector. 
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="fallbackAxis"></param>
        /// <returns></returns>
        /// <remarks>
        ///		Don't call this if you think the dest vector can be close to the inverse
        ///		of this vector, since then ANY axis of rotation is ok.
        ///	</remarks>
        public Quaternion GetRotationTo( Vector3 destination, Vector3 fallbackAxis )
        {
            // Based on Stan Melax's article in Game Programming Gems
            Quaternion q;

            // Copy, since cannot modify local
            Vector3 v0 = new Vector3( this.x, this.y, this.z );
            Vector3 v1 = destination;

            // normalize both vectors
            v0.Normalize();
            v1.Normalize();

            // get the cross product of the vectors
            Vector3 c = v0.Cross( v1 );

            Real d = v0.Dot( v1 );

            // If dot == 1, vectors are the same
            if( d >= 1.0f )
            {
                return Quaternion.Identity;
            }

            if( d < ( 1e-6f - 1.0f ) )
            {
                if( fallbackAxis != Vector3.Zero )
                {
                    // rotate 180 degrees about the fallback axis
                    q = Quaternion.FromAngleAxis( Utility.PI, fallbackAxis );
                }
                else
                {
                    // Generate an axis
                    Vector3 axis = Vector3.UnitX.Cross( this );
                    if( axis.IsZeroLength ) // pick another if colinear
                    {
                        axis = Vector3.UnitY.Cross( this );
                    }
                    axis.Normalize();
                    q = Quaternion.FromAngleAxis( Utility.PI, axis );
                }
            }
            else
            {
                Real s = Utility.Sqrt( ( 1 + d ) * 2 );
                Real inverse = 1 / s;

                q.x = c.x * inverse;
                q.y = c.y * inverse;
                q.z = c.z * inverse;
                q.w = s * 0.5f;
            }
            return q;
        }
开发者ID:RainsSoft,项目名称:UAxiom3D-Lib,代码行数:65,代码来源:Vector3.cs

示例15: timer_Tick

        void timer_Tick(object sender, EventArgs e)
        {
            Vector3 to = _Camera._Target - _Camera._Position;
            to.Normalise();
            Vector3 up = new Vector3(0, 1, 0);
            Vector3 right = up.Cross(to);
            right.Normalise();

            Vector3 newup = to.Cross(right);
            newup.Normalise();

            right.Mul(_Velocity.x);
            to.Mul(_Velocity.z);
            newup.Mul(_Velocity.y);

//            if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
            {
                _Camera._Position.Add(right);
                _Camera._Position.Add(to);
                _Camera._Position.Add(newup);
                _Camera._Target.Add(right);
                _Camera._Target.Add(to);
                _Camera._Target.Add(newup);
            }
  /*          else
            {
                _Camera._Position.Add(right);
                _Camera._Position.Add(newup);
            }
            */
            _WootracerOptions.UpdateGUI();
            _WootracerOptions._FocusDistance = (_Camera._Target - _Camera._Position).Magnitude();
            _Camera._FOV = _WootracerOptions._FieldOfView;
            _Camera._Spherical = _WootracerOptions._Spherical;
            _Camera._Stereographic = _WootracerOptions._Stereographic;

            _Velocity *= 0.6;

            _ImageRenderer._RampValue = 1;// _ImageRenderer._MaxValue;
            _ImageRenderer.TransferLatest(false);

            if (_Dirty || _CameraDirty || _Velocity.MagnitudeSquared() > 0.0001 && _ImageRenderer != null)
            {
                _ImageRenderer.Stop();
                if (_Dirty)
                {
                    Compile();
                }
                else
                {
                    Compile();
//                    _ImageRenderer.UpdateCamera(_Camera.CreateElement().ToString());
                }
                _ImageRenderer.Render();
            }

//            if (_Velocity.MagnitudeSquared() < 0.0001)
  //              _Timer.Stop();
        }
开发者ID:dom767,项目名称:woofractal,代码行数:59,代码来源:MainWindow.xaml.cs


注:本文中的Vector3.Cross方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。