private void HandleMouseClick() { //Use a ray cast to figure what cube we are clicking Ray pointerRay = Camera.main.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (!Physics.Raycast(pointerRay, out hitInfo, PointerRayDist)) { return; } //Get the cube object or ignore the object if it isn't one. ColoredCube clickableCube = hitInfo.collider.gameObject.GetComponent <ColoredCube>(); if (clickableCube == null) { return; } if (clickableCube.m_Owner != null) { clickableCube.m_Owner.DeactivateAll(); } }
public void ChangeIdentically(ColoredCube cCube) { if (leftOrDownSideCubes.Contains(cCube)) { ColoredCube cCubeOpposite = rightOrUpbSideCubes[leftOrDownSideCubes.IndexOf(cCube)]; if (cCube.IsWhite() == cCubeOpposite.IsWhite() && isOpposite) { StartCoroutine(ChangeColorLater(cCubeOpposite)); } else if (cCube.IsWhite() != cCubeOpposite.IsWhite() && !isOpposite) { StartCoroutine(ChangeColorLater(cCubeOpposite)); } } else { ColoredCube cCubeOpposite = leftOrDownSideCubes[rightOrUpbSideCubes.IndexOf(cCube)]; if (cCube.IsWhite() == cCubeOpposite.IsWhite() && isOpposite) { StartCoroutine(ChangeColorLater(cCubeOpposite)); } else if (cCube.IsWhite() != cCubeOpposite.IsWhite() && !isOpposite) { StartCoroutine(ChangeColorLater(cCubeOpposite)); } } }
private void OnCollisionEnter(Collision collision) { PhysicsBody.velocity = Vector3.zero; PhysicsBody.angularVelocity = Vector3.zero; if (WasFired) { WasFired = false; LockedPosition = gameObject.transform.position; GameObject.Find("Turret Base").GetComponent <Cannon>().CurrentLiveAmmo = null; GameObject.Find("ColoredCubeGrid").GetComponent <ColoredCubeGrid>().AdjustGrid(this); ColoredCube cubeObj = collision.collider.gameObject.GetComponent <ColoredCube>(); if (ActivatedColor == cubeObj.ActivatedColor) { if (cubeObj.m_Owner != null) { cubeObj.m_Owner.DeactivateAll(); gameObject.SetActive(false); } } } }
public void AdjustGrid(ColoredCube NewCube) { float x = NewCube.gameObject.transform.position.x - gameObject.transform.position.x; float y = NewCube.gameObject.transform.position.y - gameObject.transform.position.y; int xArrayVal = (int)Mathf.Round(x / GridSpacing); int yArrayVal = (int)Mathf.Round(y / GridSpacing); NewCube.transform.parent = gameObject.transform; NewCube.transform.position = new Vector3(xArrayVal * GridSpacing, yArrayVal * GridSpacing); NewCube.LockedPosition = NewCube.transform.position + transform.position; NewCube.WasFired = false; bool gridChanged = false; if (xArrayVal > GridDimX) { } else if (xArrayVal < gridResizeX) { ColoredCube[,] newGrid = new ColoredCube[GridDimX - xArrayVal, GridDimY]; m_SetCells = new bool[GridDimX - xArrayVal, GridDimY]; CopyOverGridDetailsToCopy(ref newGrid, new IntVector2(-xArrayVal, 0)); newGrid[0, yArrayVal] = NewCube; gridResizeX--; m_Grid = newGrid; gridChanged = true; } if (yArrayVal < gridResizeY) { ColoredCube[,] newGrid = new ColoredCube[GridDimX, GridDimY - yArrayVal]; m_SetCells = new bool[GridDimX, GridDimY - yArrayVal]; CopyOverGridDetailsToCopy(ref newGrid, new IntVector2(0, -yArrayVal)); newGrid[xArrayVal, 0] = NewCube; gridResizeY--; m_Grid = newGrid; gridChanged = true; } if (yArrayVal >= gridResizeY && xArrayVal >= gridResizeX) { m_Grid[xArrayVal - gridResizeX, yArrayVal - gridResizeY] = NewCube; gridChanged = true; } if (gridChanged) { RecalcuateClusters(); } }
void Start() { //Create a 2D array to hold the cubes, then generate the cubes in it m_Grid = new ColoredCube[GridDimX, GridDimY]; //Create a grid of visited cells m_SetCells = new bool[GridDimX, GridDimY]; GenerateCubes(); m_CubeClusters = new List <ColoredCubeCluster>(); CalculatedCluster = false; RecalcuateClusters(); }
//Creates the cubes in the right position and puts them in the grid private void GenerateCubes() { for (int x = 0; x < GridDimX; ++x) { for (int y = 0; y < GridDimY; ++y) { Vector3 offset = new Vector3(x * GridSpacing, y * GridSpacing, 0.0f); GameObject cubeObj = (GameObject)GameObject.Instantiate(CubePrefab); ColoredCube color = cubeObj.GetComponent <ColoredCube>(); color.LockedPosition = offset + transform.position; cubeObj.transform.parent = transform; m_Grid[x, y] = cubeObj.GetComponent <ColoredCube>(); DebugUtils.Assert(m_Grid[x, y] != null, "Could not find ColoredCube component."); } } }
public void Load() { //Hololens renders in meters so 0.2f is 20cm _size = new CubeSize(0.2f, 0.2f, 0.2f); //Hold 10cm between the cubes _locationCube = new Vector3(0, 0, -2.0f); _locationPrettyCube = new Vector3(0.3f, 0.0f, -2.0f); _locationTexturedCube = new Vector3(-0.3f, 0.0f, -2.0f); //Color the center cube red _cube = new ColoredCube(_locationCube, _size, Color.Red(), _engine.GetWindow().GetDrawEngine()); //Load the pretty cube without an initial color _prettyCube = new ColoredCube(_locationPrettyCube, _size, _engine.GetWindow().GetDrawEngine()); //Load the image var imageData = ImageData.LoadImage("Assets\\logo.jpg"); _texturedCube = new TexturedCube(_locationTexturedCube, _size, _engine.GetWindow().GetDrawEngine(), imageData); _lightDirection = _texturedCube.LightDirection(); _lightDirection.Z = -1.0f; _lightDirection.X = -1.0f; //Get the rotation vector _rotationCube = _cube.Rotation(); _rotationPrettyCube = _prettyCube.Rotation(); _rotationTexturedCube = _texturedCube.Rotation(); //Modify the colors of the pretty cube //Colors in directx go from 0 to 1 which can be translated in bytes from 0 to 255 _prettyCube.ChangeColor(0, new Color(0, 0, 0)); _prettyCube.ChangeColor(1, new Color(0, 0, 1)); _prettyCube.ChangeColor(2, new Color(0, 1, 0)); _prettyCube.ChangeColor(3, new Color(0, 1, 1)); _prettyCube.ChangeColor(4, new Color(1, 0, 0)); _prettyCube.ChangeColor(5, new Color(1, 0, 0)); _prettyCube.ChangeColor(6, new Color(1, 1, 0)); _prettyCube.ChangeColor(7, new Color(1, 1, 1)); }
public void AddCube(ColoredCube cube, ColoredCubeGrid grid, IntVector2 coords) { grid.FlagSet(coords); AddCube(cube); }
public void AddCube(ColoredCube cube) { m_Cubes.Add(cube); cube.m_Owner = this; }
protected IDrawableShape CreateNeighbourBuildingGeometry(INeighborBuilding neighborBuilding) { var midle = neighborBuilding.Height/2; var angle = -Math.Atan(neighborBuilding.Angle); ColoredCube _coloredCube; _coloredCube = new ColoredCube((float)neighborBuilding.Breadth, (float)neighborBuilding.Height, (float)neighborBuilding.Width, new Color(0.0f, 1.0f, .0f, 1.0f)); var gd = GraphicsDeviceManager.Current.GraphicsDevice; _coloredCube.Device = gd; _coloredCube.LoadContent(); VertexColorEffect _coloredCubeEffect; _coloredCubeEffect = new VertexColorEffect(gd) { Alpha = 1, AmbientColor = new Color(.2f, .2f, .2f, 1), SceneAmbientColor = new Color(.2f, .2f, .2f, 1), SpecularPower = 16, SpecularColor = new Color(1.0f, 1, 1, 1), }; _coloredCube.Effect = _coloredCubeEffect; Matrix worldMatrix = Matrix.CreateTranslation((float)neighborBuilding.X, (float)neighborBuilding.Height / 2, (float)neighborBuilding.Y) * Matrix.CreateRotationY((float)angle); (_coloredCube.Effect as VertexColorEffect).World = worldMatrix; return _coloredCube; }
IEnumerator ChangeColorLater(ColoredCube cCube) { yield return(new WaitForSeconds(1f)); cCube.ChangeColor(); }
public void RecalcuateClusters() { //Clear all clusters m_CubeClusters.Clear(); //Clear all visited cells ClearVisitedCells(); //Create a container so we can store all cell that needs to be visited List <IntVector2> cellsToCheck = new List <IntVector2>(); IntVector2 startCoords; //Use function that can find non-visited cells //The logic below must be executed until all cells are visited while (FindNonVisitedCoord(out startCoords)) { //Create cell cluster and add it to the existing list of clusters ColoredCubeCluster newCluster = new ColoredCubeCluster(m_Grid[startCoords.x, startCoords.y].ActivatedColor); m_CubeClusters.Add(newCluster); //Add the same cell to the container which stores a coordinates/cells that needs to be visited newCluster.AddCube(m_Grid[startCoords.x, startCoords.y], this, startCoords); cellsToCheck.Add(startCoords); while (cellsToCheck.Count > 0) { //remove the initial start value but keep in temp memory int indexToRemove = cellsToCheck.Count - 1; IntVector2 currentCoord = cellsToCheck[indexToRemove]; cellsToCheck.RemoveAt(indexToRemove); if (m_Grid[currentCoord.x, currentCoord.y].m_Owner == null) { continue; } //for loop for the cardinal directions for (int i = 0; i < 4; i++) { //create coords IntVector2 potentialCoords = currentCoord; //check a cardinal direction based on index switch (i) { case 0: potentialCoords.x++; break; case 1: potentialCoords.x--; break; case 2: potentialCoords.y++; break; case 3: potentialCoords.y--; break; default: Debug.LogError("Something really f****d up happened."); break; } //check if coords are legal if (AreCoordsValid(potentialCoords) == false) { continue; } //check if this has been set already if (m_SetCells[potentialCoords.x, potentialCoords.y] == true) { continue; } //grab the cube and check if it matches our color ColoredCube potential = m_Grid[potentialCoords.x, potentialCoords.y]; if (potential) { if (potential.ActivatedColor != newCluster.ActivatedColor) { continue; } //add the cube to the cluster and add it to the need-to-check list newCluster.AddCube(potential, this, potentialCoords); cellsToCheck.Add(potentialCoords); } } } } }