Esempio n. 1
0
        public Vector3 GetDirectionPoint()
        {
            float   rot       = TransformUtils.NormalizeAngle(Mathf.RoundToInt(transform.rotation.eulerAngles.y));
            Vector3 direction = new Vector3();

            if (rot == 0)
            {
                ////Debug.Log("Door: " + i + " is facing: +X");
                direction = new Vector3(1f, 0f, 0f);
            }
            else if (rot == 180)
            {
                ////Debug.Log("Door: " + i + " is facing: -X");
                direction = new Vector3(-1f, 0f, 0f);
            }
            else if (rot == 90)
            {
                ////Debug.Log("Door: " + i + " is facing: -Z");
                direction = new Vector3(0f, 0f, -1f);
            }
            else if (rot == 270)
            {
                ////Debug.Log("Door: " + i + " is facing: +Z");
                direction = new Vector3(0f, 0f, 1f);
            }
            else
            {
                Debug.LogWarning("Y rotation is not on a 90 degree scale");
            }

            return(voxelOwner.transform.position + (direction * Volume.VoxelScale));
        }
    private Vector3 GetDoorDirection(GeneratorDoor door)
    {
        float rot = TransformUtils.NormalizeAngle(Mathf.RoundToInt(door.transform.rotation.eulerAngles.y));

        Vector3 direction = new Vector3();

        if (rot == 0)
        {
            ////Debug.Log("Door: " + i + " is facing: +X");
            direction = new Vector3(1f, 0f, 0f);
        }
        else if (rot == 180)
        {
            ////Debug.Log("Door: " + i + " is facing: -X");
            direction = new Vector3(-1f, 0f, 0f);
        }
        else if (rot == 90)
        {
            ////Debug.Log("Door: " + i + " is facing: -Z");
            direction = new Vector3(0f, 0f, -1f);
        }
        else if (rot == 270)
        {
            ////Debug.Log("Door: " + i + " is facing: +Z");
            direction = new Vector3(0f, 0f, 1f);
        }

        return(direction);
    }
Esempio n. 3
0
    private bool CheckOverlap(GeneratorDoor door, Volume v)
    {
        bool overlap = false;

        for (int i = 0; i < v.voxels.Count; i++)
        {
            //Check if voxel is there already
            if (globalVoxels.ContainsKey(TransformUtils.RoundVec3ToInt(v.voxels[i].gameObject.transform.position)))
            {
                //overlap found! bad!
                //Debug.Log("THERE IS AN OVERLAP!!");
                overlap = true;
                continue;
            }

            for (int j = 0; j < openSet.Count; j++)
            {
                for (int k = 0; k < openSet[j].doors.Count; k++)
                {
                    //check if door is in the globalVoxelList
                    if (!openSet[j].doors[k].open)
                    {
                        continue;
                    }
                    //we also want to ignore the Door we're connecting with
                    if (openSet[j].doors[k] == door)
                    {
                        continue;
                    }
                    float   rot       = TransformUtils.NormalizeAngle(Mathf.RoundToInt(openSet[j].doors[k].transform.rotation.eulerAngles.y));
                    Vector3 direction = new Vector3();
                    if (rot == 0)
                    {
                        ////Debug.Log("Door: " + i + " is facing: +X");
                        direction = new Vector3(1f, 0f, 0f);
                    }
                    else if (rot == 180)
                    {
                        ////Debug.Log("Door: " + i + " is facing: -X");
                        direction = new Vector3(-1f, 0f, 0f);
                    }
                    else if (rot == 90)
                    {
                        ////Debug.Log("Door: " + i + " is facing: -Z");
                        direction = new Vector3(0f, 0f, -1f);
                    }
                    else if (rot == 270)
                    {
                        ////Debug.Log("Door: " + i + " is facing: +Z");
                        direction = new Vector3(0f, 0f, 1f);
                    }
                    GameObject g = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    g.transform.position = openSet[j].doors[k].voxelOwner.transform.position + (direction * Volume.VoxelScale);
                    g.GetComponent <Renderer>().material.color = Color.red;
                    doorVoxelsTest.Add(g);
                    if (TransformUtils.RoundVec3ToInt(v.voxels[i].gameObject.transform.position) == TransformUtils.RoundVec3ToInt(openSet[j].doors[k].voxelOwner.transform.position + (direction * Volume.VoxelScale)))
                    {
                        overlap = true;
                        //Debug.Log("Room is overlapping a door voxel neighbour!!!");
                    }
                    else
                    {
                        //Debug.Log("Room is NOT overlapping with a door voxel neighbour!");
                    }
                }
            }
        }

        return(overlap);
    }
Esempio n. 4
0
    private bool CheckSpace(GameObject newRoom, Volume v, Room ro)
    {
        bool hasSpace = true;

        for (int i = 0; i < ro.doors.Count; i++)
        {
            //we need to find the direction the door is pointing in world space..
            //Debug.Log(i + " : " + ro.doors[i].open);
            if (!ro.doors[i].open)
            {
                continue;                    //check all OPEN doors BUT the one we're connecting with..
            }
            if (ro.doors[i] == newRoom.GetComponent <Room>().GetFirstOpenDoor())
            {
                continue;
            }
            //Debug.Log("Actually checking door: " + i);
            float   rot       = TransformUtils.NormalizeAngle(Mathf.RoundToInt(ro.doors[i].transform.rotation.eulerAngles.y));
            Vector3 direction = new Vector3();
            if (rot == 0)
            {
                ////Debug.Log("Door: " + i + " is facing: +X");
                direction = new Vector3(1f, 0f, 0f);
            }
            else if (rot == 180)
            {
                ////Debug.Log("Door: " + i + " is facing: -X");
                direction = new Vector3(-1f, 0f, 0f);
            }
            else if (rot == 90)
            {
                ////Debug.Log("Door: " + i + " is facing: -Z");
                direction = new Vector3(0f, 0f, -1f);
            }
            else if (rot == 270)
            {
                ////Debug.Log("Door: " + i + " is facing: +Z");
                direction = new Vector3(0f, 0f, 1f);
            }
            //Debug.Log("Drawing spheres");
            GameObject g = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            g.transform.position = ro.doors[i].voxelOwner.transform.position + (direction * Volume.VoxelScale);
            doorVoxelsTest.Add(g);

            if (globalVoxels.ContainsKey(TransformUtils.RoundVec3ToInt(ro.doors[i].voxelOwner.transform.position + (direction * Volume.VoxelScale))))
            {
                //we have a collision on the door neighbours
                //Debug.Log("WE HAVE A COLLISION WITH THE DOOR NEIGHBOURS");
                hasSpace = false;
                break;
            }
            else
            {
                //we good!
                //Debug.Log("We don't have a collision witht he door neighbours");
                //check doors against all other doors so that no door voxels overlap with other door  voxels
                for (int j = 0; j < openSet.Count; j++)
                {
                    for (int k = 0; k < openSet[j].doors.Count; k++)
                    {
                        if (!openSet[j].doors[k].open)
                        {
                            continue;
                        }
                        float   rot2       = TransformUtils.NormalizeAngle(Mathf.RoundToInt(openSet[j].doors[k].transform.rotation.eulerAngles.y));
                        Vector3 direction2 = new Vector3();
                        if (rot2 == 0)
                        {
                            ////Debug.Log("Door: " + i + " is facing: +X");
                            direction2 = new Vector3(1f, 0f, 0f);
                        }
                        else if (rot2 == 180)
                        {
                            ////Debug.Log("Door: " + i + " is facing: -X");
                            direction2 = new Vector3(-1f, 0f, 0f);
                        }
                        else if (rot2 == 90)
                        {
                            ////Debug.Log("Door: " + i + " is facing: -Z");
                            direction2 = new Vector3(0f, 0f, -1f);
                        }
                        else if (rot2 == 270)
                        {
                            ////Debug.Log("Door: " + i + " is facing: +Z");
                            direction2 = new Vector3(0f, 0f, 1f);
                        }

                        if (TransformUtils.RoundVec3ToInt(ro.doors[i].voxelOwner.transform.position + (direction * Volume.VoxelScale)) == TransformUtils.RoundVec3ToInt(openSet[j].doors[k].voxelOwner.transform.position + (direction2 * Volume.VoxelScale)))
                        {
                            hasSpace = false;
                            //Debug.Log("TWo door voxels overlapping!");
                            break;
                        }
                    }
                    if (!hasSpace)
                    {
                        break;
                    }
                }
            }
        }

        return(hasSpace);
    }