예제 #1
0
 public Point(Vector2S v, QuaternionS rotation)
 {
     this.position   = new Vector2S();
     this.position.x = (float)Math.Round(v.x, Decimals);
     this.position.y = (float)Math.Round(v.y, Decimals);
     this.rotation   = rotation;
 }
예제 #2
0
        public Snippet GetLocalSnippet(
            int presentFrame)
        {
            // Validate input
            if (presentFrame < SalamanderController.FeaturePastPoints - 1 || presentFrame > points.Count - SalamanderController.FeaturePoints)
            {
                Debug.LogError("Attempt to create a Snippet the exceedes the past or the future limit");
                throw new Exception("Attempt to create a Snippet the exceedes the past or the future limit");
            }

            // Find present position and rotation
            Vector2S    presentPosition = points[presentFrame].position;
            QuaternionS presentRotation = this.points[presentFrame].rotation;

            // Build the new Snippet
            Snippet snippet = new Snippet();

            for (int i = 0; i < SalamanderController.SnippetSize; i++)
            {
                // Compute the position of the points relative to the present position and rotation
                // Create a Point at the current position
                int     addingFrame     = presentFrame - SalamanderController.FeaturePastPoints + 1 + i;
                Vector3 localPosition3D = new Vector3(this.points[addingFrame].position.x, 0, this.points[addingFrame].position.y);

                // Move it to the root
                localPosition3D.x -= presentPosition.x;
                localPosition3D.z -= presentPosition.y;

                // Rotate it to face upwards
                localPosition3D = Quaternion.Inverse((Quaternion)presentRotation) * localPosition3D;

                // Compute the new rotation
                QuaternionS localRotation = this.points[addingFrame].rotation * presentRotation;

                // Store the relative point to the snippet
                snippet.points[i] = new Point(localPosition3D.GetXZVector2(), localRotation);
            }

            return(snippet);
        }
예제 #3
0
            public static Point getMedianPoint(List <Vector2S> positions)
            {
                Vector2S    position = new Vector2S(0f, 0f);
                QuaternionS rotation;

                // Position
                foreach (Vector2S currentPosition in positions)
                {
                    position += currentPosition;
                }

                position /= positions.Count;

                // Rotation
                Vector2S displacement2D = (positions[positions.Count - 1] - positions[0]);

                rotation = Quaternion.LookRotation(
                    new Vector3(displacement2D.x, 0, displacement2D.y),
                    Vector3.up);

                return(new Point(position, rotation));
            }
 /// <summary>
 /// Sets the position of the spawn point.
 /// </summary>
 /// <param name="manualPosition">The position.</param>
 /// <param name="angleRot">The angle rotation.</param>
 public void SetPosition(Vector3S manualPosition, Vector2S angleRot)
 {
     Level.CWMap.SpawnPos      = manualPosition;
     Level.CWMap.SpawnRotation = angleRot;
 }
 /// <summary>
 /// Sets the position of the spawn point.
 /// </summary>
 /// <param name="manualPosition">The position.</param>
 /// <param name="angleRot">The angle rotation.</param>
 public void SetPosition(Vector3S manualPosition, Vector2S angleRot)
 {
     Level.SpawnPos = manualPosition;
     Level.SpawnRot = new[] { (byte)angleRot.x, (byte)angleRot.z };
 }
예제 #6
0
    public void DrawHexTile(int index)
    {
        if( Tiles.Count <= index){
            return;
        }

        SL_Tile tile = Tiles[index];

        var vNorm_CONV = new Vector3(TileNormals[index].x,TileNormals[index].y,TileNormals[index].z);

        var ext = vNorm_CONV * 0.04f;
        var ext2 = vNorm_CONV * 1.041f;

        Mesh newMesh = new Mesh ();
        Vector3[] 	theMeshVerts;
        Vector2[] 	theMeshUVs;
        Vector3[]	theMeshNormals;

        Mesh SecondMesh = new Mesh();
        Vector3[]	SecondMeshVerts;

        if(NumNeighbors(tile) == 6)
        {
            theMeshVerts = new Vector3[7];
            theMeshUVs = new Vector2[7];
            theMeshNormals = new Vector3[7];
            SecondMeshVerts = new Vector3[7];

            for(int i = 0; i < 7; ++i)
            {
                Vector3 v2_conv = new Vector3(TileVertices[ tile.Vertices[i] ].x, TileVertices[ tile.Vertices[i] ].y, TileVertices[ tile.Vertices[i] ].z);
                theMeshVerts[i] = v2_conv + ext;
                theMeshNormals[i] = vNorm_CONV;

                Vector3 scaled = (v2_conv - vNorm_CONV);
                scaled.x = scaled.x * 0.5f;
                scaled.y = scaled.y * 0.5f;
                scaled.z = scaled.z * 0.5f;
                scaled = scaled + ext2;
                SecondMeshVerts[i] = scaled;

                //using boneweights to contain tile info
                //in TilePicker retrieve this to get submesh index
                boneWeights[boneCount].boneIndex0 = 6; //numNeighbors
                boneWeights[boneCount].weight0 = (float)index; //tile index
                boneWeights[boneCount].boneIndex1 = tile.Neighbors[0]; //neighbor indexes - not used
                boneWeights[boneCount].weight1 = (float)tile.Neighbors[1];
                boneWeights[boneCount].boneIndex2 = tile.Neighbors[2];
                boneWeights[boneCount].weight2 = (float)tile.Neighbors[3];
                boneWeights[boneCount].boneIndex3 = tile.Neighbors[4];
                boneWeights[boneCount].weight3 = (float)tile.Neighbors[5];
                boneCount++;

            }
            newMesh.vertices = theMeshVerts;
            newMesh.triangles = HexIndices;
            newMesh.normals = theMeshNormals;
            //newMesh.RecalculateNormals();
            //newMesh.RecalculateBounds();
            newMesh.Optimize();

            SecondMesh.vertices = SecondMeshVerts;
            SecondMesh.uv = theMeshUVs;
            SecondMesh.triangles = HexIndices;
            //SecondMesh.RecalculateNormals();
            SecondMesh.RecalculateBounds();
            SecondMesh.Optimize();

        } else {
            theMeshVerts = new Vector3[6];
            theMeshUVs 	= new Vector2[6];
            theMeshNormals = new Vector3[6];
            SecondMeshVerts = new Vector3[6];

            for(int i = 0; i < 6; ++i)
            {
                Vector3 v2_conv = new Vector3(TileVertices[ tile.Vertices[i] ].x, TileVertices[ tile.Vertices[i] ].y, TileVertices[ tile.Vertices[i] ].z);
                theMeshVerts[i] = v2_conv + ext;
                theMeshNormals[i] = vNorm_CONV;

                Vector3 scaled = (v2_conv - vNorm_CONV);
                scaled.x = scaled.x * 0.5f;
                scaled.y = scaled.y * 0.5f;
                scaled.z = scaled.z * 0.5f;
                scaled = scaled + ext2;
                SecondMeshVerts[i] = scaled;

                //using boneweights to contain tile info
                //in TilePicker retrieve this to get submesh index
                boneWeights[boneCount].boneIndex0 = 5;
                boneWeights[boneCount].weight0 = (float)index;
                boneWeights[boneCount].boneIndex1 = tile.Neighbors[0]; //neighbor indexes - not used
                boneWeights[boneCount].weight1 = (float)tile.Neighbors[1];
                boneWeights[boneCount].boneIndex2 = tile.Neighbors[2];
                boneWeights[boneCount].weight2 = (float)tile.Neighbors[3];
                boneWeights[boneCount].boneIndex3 = tile.Neighbors[4];
                boneWeights[boneCount].weight3 = -1.0f;
                boneCount++;
            }
            newMesh.vertices = theMeshVerts;
            newMesh.normals = theMeshNormals;
            newMesh.triangles = PentIndices;

            //newMesh.RecalculateNormals();
            //newMesh.RecalculateBounds();
            newMesh.Optimize();

            SecondMesh.vertices = SecondMeshVerts;
            SecondMesh.uv = theMeshUVs;
            SecondMesh.triangles = PentIndices;
            SecondMesh.RecalculateNormals();
            //SecondMesh.RecalculateBounds();
            SecondMesh.Optimize();
        }

        if(writeUvMap)
        {
            //color the hex tiles based on planet texture
            //cast ray to 0,0,0 and get the planet material color at the collision
            RaycastHit theHit;

            //Color[] meshColors = new Color[theMeshVerts.Length];
            //Color[] secondMeshColors = new Color[theMeshVerts.Length];

            int count=0;
            foreach(int tileVert in tile.Vertices)
            {
                Vector3S v3s = TileVertices[ tile.Vertices[count] ];
                Vector3 v3 = new Vector3(v3s.x,v3s.y,v3s.z);

                int layerMask = 1 << 11; //only cast rays against layer 11
                if(Physics.Linecast(v3 * 2, Vector3.zero, out theHit, layerMask))
                {
                    var td = theHit.collider.gameObject.name;
                    if(td == "Planet")
                    {
                        Renderer renderer = theHit.collider.renderer;
                        //Texture2D tex = renderer.material.GetTexture("_difColor") as Texture2D;
                        Texture2D tex = renderer.material.GetTexture("_MainTex") as Texture2D;
                        Vector2 pixelUV = theHit.textureCoord;
                        pixelUV.x *= tex.width;
                        pixelUV.y *= tex.height;

                        theMeshUVs[count] = pixelUV;

                        if(count == 0)
                        {
                            SL_UVs[index] = new Vector2S();
                            SL_UVs[index].x = pixelUV.x;
                            SL_UVs[index].y = pixelUV.y;

                            /*
                            GroundColors[index] = tex.GetPixel((int)pixelUV.x, (int)pixelUV.y);
                            GroundColors[index].a = Amplitude;
                            HexColors[index] = GroundColors[index];
                            NextHexColors[index] = GroundColors[index];

                            /*
                            for(int i=0; i < theMeshVerts.Length; i++)
                            {
                                meshColors[i] = GroundColors[index];
                                secondMeshColors[i] = GroundColors[index];
                            }*/
                        }
                    }
                }
                count++;
            }
            //newMesh.colors = meshColors;
        }
        combine[index].mesh = newMesh;
        combine2[index].mesh = SecondMesh;
    }