Пример #1
0
        public void TransformCameraTarget(Transform targetTransform, out Vector3 outPosition, out Quaternion outRotation, ECameraTargetType view)
        {
            if (view == ECameraTargetType.MAP)
            {
                Vector3 lpos = targetTransform.position;
                outPosition = lpos + (lpos.normalized * MapViewDistance);

                Vector3 upVector      = lpos.normalized;
                Vector3 rightVector   = Vector3.Cross(upVector, Vector3.up).normalized;
                Vector3 forwardVector = MathCustom.GetFaceNormalVector(Vector3.zero, rightVector, upVector);
                outRotation = Quaternion.LookRotation(-upVector, forwardVector);
            }
            else if (view == ECameraTargetType.ZOOM)
            {
                Vector3 lpos = targetTransform.position;

                Vector3 newPosition;
                MathCustom.SphericalToCartesian(DistanceToplayer, -Mathf.PI / 2, Elevation, out newPosition);
                outPosition = targetTransform.TransformPoint(newPosition + Vector3.up * StepHeight);

                Vector3 newPos = targetTransform.TransformPoint(newPosition);
                Vector3 cross  = Vector3.Cross(newPos, targetTransform.forward);
                outRotation = Quaternion.LookRotation(lpos - newPos, Vector3.Cross(cross, -(lpos - newPos)));
            }
            else
            {
                outPosition = Vector3.zero;
                outRotation = Quaternion.identity;
            }
        }
Пример #2
0
        protected void Reoriente()
        {
            Vector3 forwardVector = -transform.position.normalized;
            Vector3 rightVector   = Vector3.Cross(forwardVector, Vector3.up).normalized;
            Vector3 upVector      = MathCustom.GetFaceNormalVector(transform.position, transform.position + rightVector, transform.position + forwardVector);

            transform.rotation = Quaternion.LookRotation(forwardVector, -upVector);
        }
Пример #3
0
        protected void AddRoadPart(RoadEdge startEdge, RoadEdge targetEdge)
        {
            SortPoints(startEdge, targetEdge);

            List <Vector3[]> preTris = new List <Vector3[]>();

            preTris.Add(new Vector3[3] {
                startEdge.meshPoints[1], startEdge.meshPoints[0], targetEdge.meshPoints[0]
            });
            preTris.Add(new Vector3[3] {
                targetEdge.meshPoints[0], targetEdge.meshPoints[1], startEdge.meshPoints[1]
            });

            for (int i = 0; i < 2; i++)
            {
                if (Vector3.Angle(MathCustom.GetFaceNormalVector(preTris[i][0], preTris[i][1], preTris[i][2]).normalized, MathCustom.GetBarycenter(preTris[i]).normalized) < 90f)
                {
                    roadVertice.AddTriangle(new Vector3[3] {
                        preTris[i][2], preTris[i][1], preTris[i][0]
                    });
                }
                else
                {
                    roadVertice.AddTriangle(preTris[i]);
                }
            }
            preTris.Clear();

            int[] lTriangles = new int[roadVertice.triangles.Count * 3];
            for (int i = 0; i < lTriangles.Length / 3; i++)
            {
                lTriangles[i * 3]       = roadVertice.triangles[i].verticesindex[0];
                lTriangles[(i * 3) + 1] = roadVertice.triangles[i].verticesindex[1];
                lTriangles[(i * 3) + 2] = roadVertice.triangles[i].verticesindex[2];
            }

            roadMeshObject.mesh.vertices  = roadVertice.vertex.ToArray();
            roadMeshObject.mesh.triangles = lTriangles;
            roadMeshObject.mesh.normals   = roadVertice.normals.ToArray();

            SetUV();
            roadMeshObject.mesh.uv      = roadVertice.UV.ToArray();
            roadMeshCollider.sharedMesh = roadMeshObject.mesh;
        }