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


C# Vector3.Multiply方法代码示例

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


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

示例1: CircleGeometry

        public CircleGeometry(float radius=1,int segments=8,float thetaStart = 0, float thetaLength = Mathf.Tau)
        {
            segments = Mathf.Max(3, segments);
            var uvs = new List<Vector2>();
            
            vertices.Add(Vector3.Zero);
            uvs.Add(Vector2.Half);

            for(var i = 0f; i <= segments; i ++ ) 
            {
                
		        var segment = thetaStart + i / segments * thetaLength;

                var v = new Vector3(Mathf.Cos( segment ),radius * Mathf.Sin( segment ),0);
                v.Multiply(radius);
                vertices.Add(v);
                uvs.Add(new Vector2(( v.x / radius + 1 ) / 2, ( v.y / radius + 1 ) / 2 ));
            }

            var n = Vector3.UnitZ;

            for (var i = 1; i <= segments; i++)
            {
                faces.Add(new Face3(i, i + 1, 0, n));
                var faceSet = new UVFaceSet(uvs[i], uvs[i + 1], Vector2.Half);
                faceVertexUvs[0].Add(faceSet);
            }

            ComputeNormals();
            BoundingSphere = new Sphere(Vector3.Zero,radius );
        }
开发者ID:prepare,项目名称:three.net,代码行数:31,代码来源:CircleGeometry.cs

示例2: doCollideWithWorld

        /// <summary>
        /// Detección de colisiones recursiva
        /// </summary>
        public void doCollideWithWorld(TgcBoundingSphere characterSphere, Vector3 movementVector, List<TgcBoundingBox> obstaculos, int recursionDepth)
        {
            //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;
            TgcBoundingBox.Face collisionFace = null;
            TgcBoundingBox collisionObstacle = null;
            Vector3 nearestPolygonIntersectionPoint = Vector3.Empty;
            foreach (TgcBoundingBox obstaculoBB in obstaculos)
            {
                //Obtener los polígonos que conforman las 6 caras del BoundingBox
                TgcBoundingBox.Face[] bbFaces = obstaculoBB.computeFaces();

                foreach (TgcBoundingBox.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
                        {
//.........这里部分代码省略.........
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:101,代码来源:SphereCollisionManager.cs

示例3: SetupMatrices

        // Setup the world, view, and projection matrices.
        private void SetupMatrices()
        {
            // World Matrix:
            const int TICKS_PER_REV = 10000;
            double angle = Environment.TickCount * (2 * Math.PI) / TICKS_PER_REV;
            m_Device.Transform.World = Matrix.RotationY((float)angle);

            // View Matrix:
            Vector3 camera_position  = new Vector3(0, 10, -20);
            camera_position.Normalize();
            camera_position.Multiply(m_Range);

            m_Device.Transform.View = Matrix.LookAtLH(
                camera_position,
                new Vector3(0, 0, 0),
                new Vector3(0, 1, 0));

            // Projection Matrix:
            // Perspective transformation defined by:
            //       Field of view           Pi / 4
            //       Aspect ratio            1
            //       Near clipping plane     Z = 1
            //       Far clipping plane      Z = 100
            m_Device.Transform.Projection =
                Matrix.PerspectiveFovLH((float)(Math.PI / 4), 1, 1, 100);
        }
开发者ID:walidBelfadel,项目名称:MARS_project,代码行数:27,代码来源:RenderForm.cs


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