Пример #1
0
    public override Vector3 FindNearestFace(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false)
    {
        //get a temporary point (world space)
        Vector3 toPoint = FindNearestBox(fromPoint);

        //snap to the plane
        toPoint[(int)thePlane] = FindNearestVertex(fromPoint)[(int)thePlane];

        //debugging
        if (doDebug)
        {
            Vector3 debugCube = spacing;
            debugCube[(int)thePlane] = 0.0f;

            //store the old matrix and create a new one based on the grid's roation and the point's position
            Matrix4x4 oldRotationMatrix = Gizmos.matrix;
            Matrix4x4 newRotationMatrix = Matrix4x4.TRS(toPoint, transform.rotation, Vector3.one);

            Gizmos.matrix = newRotationMatrix;
            Gizmos.DrawCube(Vector3.zero, debugCube);            //Position zero because the matrix already contains the point
            Gizmos.matrix = oldRotationMatrix;
        }

        return(toPoint);
    }
Пример #2
0
    public override Vector3 NearestFaceW(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false)
    {
        //get a temporary point (world space)
        //Vector3 toPoint = NearestBoxW(fromPoint);

        //snap to the plane
        //toPoint[(int)thePlane] = NearestVertexW(fromPoint)[(int)thePlane];

        //debugging
        if (doDebug)
        {
            Vector3 debugCube = spacing;
            debugCube[(int)thePlane] = 0.0f;

            //store the old matrix and create a new one based on the grid's roation and the point's position
            Matrix4x4 oldRotationMatrix = Gizmos.matrix;
            //Matrix4x4 newRotationMatrix = Matrix4x4.TRS(toPoint, transform.rotation, Vector3.one);
            Matrix4x4 newRotationMatrix = Matrix4x4.TRS(GridToWorld(NearestFaceG(fromPoint, thePlane) + 0.5f * Vector3.one - 0.5f * units[(int)thePlane]), transform.rotation, Vector3.one);

            Gizmos.matrix = newRotationMatrix;
            Gizmos.DrawCube(Vector3.zero, debugCube);            //Position zero because the matrix already contains the point
            Gizmos.matrix = oldRotationMatrix;
        }

        //return toPoint;
        return(GridToWorld(NearestFaceG(fromPoint, thePlane) + 0.5f * Vector3.one - 0.5f * units[(int)thePlane]));
    }
Пример #3
0
    public EnemySpawner(GridPlane plane)
    {
        resources  = 0;
        this.plane = plane;
        for (int x = 0; x < LEVEL_SIZE.X; ++x)
        {
            if (!plane.grid[x, 0].solid)
            {
                available.Add(plane.grid[x, 0]);
            }
            if (!plane.grid[x, LEVEL_SIZE.Y - 1].solid)
            {
                available.Add(plane.grid[x, LEVEL_SIZE.Y - 1]);
            }
        }

        for (int y = 0; y < LEVEL_SIZE.Y; ++y)
        {
            if (!plane.grid[0, y].solid)
            {
                available.Add(plane.grid[0, y]);
            }
            if (!plane.grid[LEVEL_SIZE.X - 1, y].solid)
            {
                available.Add(plane.grid[LEVEL_SIZE.X - 1, y]);
            }
        }
    }
Пример #4
0
        void InitializePlanes(GraphicsDevice graphicsDevice, int gridSize, float cellSize, Color color)
        {
            int   halfGridSize = gridSize / 2;
            float offset       = halfGridSize * cellSize;

            var upTransform = Matrix.CreateTranslation(new Vector3(0, offset, 0));

            Up = GridPlane.CreatePlaneXZ(graphicsDevice, gridSize, gridSize, cellSize, color, upTransform);

            var downTransform = Matrix.CreateTranslation(new Vector3(0, -offset, 0));

            Down = GridPlane.CreatePlaneXZ(graphicsDevice, gridSize, gridSize, cellSize, color, downTransform);

            var forwardTransform = Matrix.CreateTranslation(new Vector3(0, 0, -offset));

            Forward = GridPlane.CreatePlaneXY(graphicsDevice, gridSize, gridSize, cellSize, color, forwardTransform);

            var backwardTransform = Matrix.CreateTranslation(new Vector3(0, 0, offset));

            Backward = GridPlane.CreatePlaneXY(graphicsDevice, gridSize, gridSize, cellSize, color, backwardTransform);

            var leftTransform = Matrix.CreateTranslation(new Vector3(-offset, 0, 0));

            Left = GridPlane.CreatePlaneZY(graphicsDevice, gridSize, gridSize, cellSize, color, leftTransform);

            var rightTransform = Matrix.CreateTranslation(new Vector3(offset, 0, 0));

            Right = GridPlane.CreatePlaneZY(graphicsDevice, gridSize, gridSize, cellSize, color, rightTransform);
        }
Пример #5
0
        public void CopyFrom(BrushSettings other)
        {
            brushRadius              = other.brushRadius;
            brushSpacing             = other.brushSpacing;
            brushOverlapCheckMode    = other.brushOverlapCheckMode;
            brushOverlapDistance     = other.brushOverlapDistance;
            brushOverlapCheckObjects = other.brushOverlapCheckObjects;
            brushOverlapCheckLayers  = other.brushOverlapCheckLayers;

            surfaceOffset = other.surfaceOffset;

            orientationTransformMode = other.orientationTransformMode;
            orientationMode          = other.orientationMode;
            alongBrushStroke         = other.alongBrushStroke;
            rotation = other.rotation;
            randomizeOrientationX = other.randomizeOrientationX;
            randomizeOrientationY = other.randomizeOrientationY;
            randomizeOrientationZ = other.randomizeOrientationZ;

            scaleTransformMode = other.scaleTransformMode;
            scaleMode          = other.scaleMode;
            scaleUniformMin    = other.scaleUniformMin;
            scaleUniformMax    = other.scaleUniformMax;
            scalePerAxisMin    = other.scalePerAxisMin;
            scalePerAxisMax    = other.scalePerAxisMax;

            pinFixedRotation      = other.pinFixedRotation;
            pinFixedRotationValue = other.pinFixedRotationValue;
            pinFixedScale         = other.pinFixedScale;
            pinFixedScaleValue    = other.pinFixedScaleValue;

            placeScale       = other.placeScale;
            placeEulerAngles = other.placeEulerAngles;

            multibrushEnabled           = other.multibrushEnabled;
            multibrushPaintSelectedSlot = other.multibrushPaintSelectedSlot;
            multibrushMode            = other.multibrushMode;
            multibrushPattern         = other.multibrushPattern;
            multibrushPatternContinue = other.multibrushPatternContinue;

            for (int i = 0; i < kNumMultibrushSlots; i++)
            {
                multibrushSlots[i] = other.multibrushSlots[i];
            }

            slopeEnabled      = other.slopeEnabled;
            slopeAngleMin     = other.slopeAngleMin;
            slopeAngleMax     = other.slopeAngleMax;
            slopeVector       = other.slopeVector;
            slopeVectorCustom = other.slopeVectorCustom;
            slopeVectorFlip   = other.slopeVectorFlip;

            gridEnabled = other.gridEnabled;
            gridOrigin  = other.gridOrigin;
            gridStep    = other.gridStep;
            gridPlane   = other.gridPlane;
            gridNormal  = other.gridNormal;
            gridAngle   = other.gridAngle;
        }
Пример #6
0
 public void ResetGrid()
 {
     gridOrigin = new Vector3(0, 0, 0);
     gridStep   = new Vector2(5, 5);
     gridPlane  = GridPlane.XZ;
     gridNormal = new Vector3(0, 1, 0);
     gridAngle  = 0.0f;
 }
 public static dynamic GetTSObject(GridPlane dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Пример #8
0
    public override void HandleInput(InputHelper inputHelper)
    {
        base.HandleInput(inputHelper);
        mousePos = inputHelper.MousePosition;

        plane = GameWorld.FindByType <Camera>()[0].currentPlane;
        node  = plane.NodeAt(mousePos / Camera.scale, false);
        if (previousNode != node)
        {
            if (previousNode != null)
            {
                previousNode.selected = false;
            }
            previousNode = node;
        }

        if (node == null)
        {
            return;
        }
        else
        {
            node.selected = true;
        }

        selectedPossible = !node.solid && node.available && inputHelper.MouseInGameWindow;

        if (inputHelper.MouseLeftButtonPressed() &&
            inputHelper.MouseInGameWindow &&
            selected != null &&
            selectedPossible)
        {
            Type       t    = Type.GetType(selected.itemType);              //Get the type of the object
            object     temp = Activator.CreateInstance(t);                  //Create an instance of that object
            GameObject obj  = temp as GameObject;                           //Cast it as a GameObject
            obj.Position = node.Position + new Vector2(NODE_SIZE.X / 2, 0); //Adjust the position to the middle of the GridNode
            if (selected.itemType.Equals("ResourceTower") && GameWorld.FindByType <ResourceTower>().Count > 2)
            {
                selected = null;
                return;
            }
            plane.Add(obj);                                        //Add it to the hierarchy
            obj.MyParticleControl.AddTowerBuildGlow(obj.Position); //Add particle effect
            EcResources -= selected.cost;                          //Subtract its cost from the resources
            PlaySound(SND_TOWERPLACE);

            if (!inputHelper.IsKeyDown(Keys.LeftShift) || selected.cost > EcResources) //allow shift-clicking multiple towers
            {
                selected = null;                                                       //Reset the selected object reference
            }
        }

        //Cancel the current selection with X or right click
        if (inputHelper.KeyPressed(Keys.X) && selected != null || inputHelper.MouseRightButtonPressed() && selected != null)
        {
            selected = null;
        }
    }
Пример #9
0
 public GsaGridPlaneSurface()
 {
     m_plane     = Plane.Unset;
     m_gridplane = new GridPlane();
     m_gp_guid   = Guid.NewGuid();
     m_gridsrf   = new GridSurface();
     m_gs_guid   = Guid.NewGuid();
     m_axis      = new Axis();
 }
Пример #10
0
	//transforms from quasi axis to real axis. Quasi axis is the relative X, Y and Z n the current grid plane,
	// all calculations are done in quasi space, so there is only one calculation, and then transformed into real space
	protected virtual int[] TransformIndices(GridPlane plane){
		if(plane == GridPlane.YZ){
			return new int[3] {2, 1, (int)gridPlane};
		} else if(plane == GridPlane.XZ){
			return new int[3] {0, 2, (int)gridPlane};
		} else{
			return new int[3] {0, 1, (int)gridPlane};
		}
	}
Пример #11
0
    public Camera() : base()
    {
        position = -LEVEL_CENTER + GAME_WINDOW_SIZE.toVector() / 2;
        scale    = new Vector2(1f);
        planes   = new List <GridPlane>();
        for (int i = 0; i < 1; ++i)
        {
            GridPlane p = new GridPlane((Plane)i);
            p.active = false;
            Add(p);
            switch ((Plane)i)
            {
            case Plane.Land:
                Land = p;
                planes.Add(Land);
                //Add items to the land plane (p.Add)
                p.Add(new Base {
                    Position = LEVEL_CENTER
                });
                //p.Add(new ParticleController());
                break;
            }
        }
        currentPlane = planes[(int)Plane.Land]; //Reference the current plane to one of the three
        Console.WriteLine("Current Plane: " + currentPlane.planeType.ToString());
        LevelGenerator levelGenerator = new LevelGenerator();
        List <int[, ]> list           = new List <int[, ]>();

        list = levelGenerator.GenerateNewLevel();
        for (int x = 0; x < LEVEL_SIZE.X; ++x)
        {
            for (int y = 0; y < LEVEL_SIZE.Y; ++y)
            {
                int tex = list[0][x, y];
                if (tex == 2) //Mountain
                {
                    tex = Functions.choose(new List <int> {
                        2, 7, 8
                    });
                }
                if (tex == 5)
                {
                    tex = Functions.choose(new List <int> {
                        5, 9
                    });
                }
                Land.grid[x, y].texture = tex;
            }
        }
        currentPlane.Add(new EnemySpawner(currentPlane)); // The grid must be finished

        for (int i = 1; i <= 5; i += 2)
        {
            currentPlane.Add(new Clouds(new Vector2(-1500 / i, SCREEN_SIZE.Y + 1800 / i)));
        }
    }
Пример #12
0
    //returns XYZ grid coordinates of a face close to a given point
    public override Vector3 GetFaceCoordinates(Vector3 fromPoint, GridPlane thePlane)
    {
        //get the grid coordinates of the face
        Vector3 face = GetBoxCoordinates(FindNearestFace(fromPoint, thePlane));

        // two of the face coordinates are in a box, the other is on the vertex closest to the face
        face[(int)thePlane] = FindNearestVertex(fromPoint)[(int)thePlane];

        return(face);
    }
Пример #13
0
    //returns XYZ grid coordinates of a face close to a given point
    public override Vector3 NearestFaceG(Vector3 fromPoint, GridPlane thePlane)
    {
        //get the grid coordinates of the face
        //Vector3 face = NearestBoxG(NearestFaceW(fromPoint, thePlane));
        // two of the face coordinates are in a box, the other is on the vertex closest to the face
        //face[(int)thePlane] = NearestVertexW(fromPoint)[(int)thePlane];

        //return face;
        return(RoundPoint(WorldToGrid(fromPoint) - 0.5f * Vector3.one + 0.5f * units[(int)thePlane]));
    }
Пример #14
0
    public override Vector3 NearestFaceW(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false)
    {
        Vector3 dest = PolarToWorld(NearestFaceP(fromPoint, thePlane));

        if (doDebug)
        {
            DrawSphere(dest);
        }
        return(dest);
    }
Пример #15
0
 protected Vector3 NearestFaceG(Vector3 world, GridPlane thePlane, HexCoordinateSystem coordianteSystem)
 {
     if (coordianteSystem == HexCoordinateSystem.Herring)
     {
         return(NearestFaceGHerring(world, thePlane));
     }
     else
     {
         return(Vector3.zero);
     }
 }
Пример #16
0
    public Vector3 NearestFaceP(Vector3 world, GridPlane thePlane)
    {
        Vector3 polar = WorldToPolar(world);

        polar        -= 0.5f * radius * units[idx[0]] + 0.5f * angle * units[idx[1]]; // virtually shift the point half an angle and half a radius down, this will simulate the shifted coordinates
        polar[idx[1]] = Mathf.Max(0, polar[idx[1]]);                                  // prevent the angle from becoming negative
        polar         = RoundPolarPoint(polar);                                       // round the point
        polar        += 0.5f * radius * units[idx[0]] + 0.5f * angle * units[idx[1]];
        //Debug.Log (polar);
        return(polar);
    }
Пример #17
0
    public bool InitializeDocument(params object[] args)
    {
      if (args.Length == 0 || !(args[0] is GridPlane))
        return false;

      bool isVirgin = null == _doc;

      _doc = (GridPlane)args[0];

      Initialize(true);
      return true;
    }
Пример #18
0
 /// <summary>transforms from quasi axis to real axis.</summary>
 /// <returns>Real indices of quasi-indices.</returns>
 /// <param name="plane">The plane.</param>
 ///
 /// Quasi axis is the relative X, Y and Z n the current grid plane, all calculations are done in quasi space, so there is only one calculation, and then transformed into real space.
 protected virtual int[] TransformIndices(GridPlane plane)
 {
     if (plane == GridPlane.YZ)
     {
         return(new int[] { 2, 1, (int)gridPlane });
     }
     if (plane == GridPlane.XZ)
     {
         return(new int[] { 0, 2, (int)gridPlane });
     }
     return(new int[] { 0, 1, (int)gridPlane });
 }
Пример #19
0
    //diese Funktion sorgt dafür dass unser Block nach der bewegung shön weich landed
    public void SnapToPosition(GridPlane gridPlane)
    {
        movementState = BlockMovementState.Dropping;
        if (currentAssignedGridPlane != null)
        {
            currentAssignedGridPlane.taken = false;
        }
        //transform.position = gridPlane.transform.position + new Vector3(0, 0.5f, 0);
        currentAssignedGridPlane       = gridPlane;
        currentAssignedGridPlane.taken = true;

        heightCorrector  = currentAssignedGridPlane.transform.up;
        heightCorrector *= transform.localScale.y / 2;
    }
Пример #20
0
        public bool InitializeDocument(params object[] args)
        {
            if (args.Length == 0 || !(args[0] is GridPlane))
            {
                return(false);
            }

            bool isVirgin = null == _doc;

            _doc = (GridPlane)args[0];

            Initialize(true);
            return(true);
        }
Пример #21
0
    //the cordinates inside the tile
    protected Vector2 GetTilePointCoordinates(Vector3 world, GridPlane thePlane)
    {
        Vector3 local     = _transform.GFInverseTransformPointFixed(world);
        Vector3 tile      = GetTileCoordinates(world, thePlane);
        Vector2 tilePoint = new Vector2();

        tilePoint[0] = (local[idx[0]] + 1.0f * radius) - tile[idx[0]] * side;
        float shift = 1 - Mathf.RoundToInt(Mathf.Abs(tile[idx[0]]) % 2);         // 1 for even, 0 for odd

        tilePoint[1] = (local[idx[1]] + shift * 0.5f * height) - tile[idx[1]] * height;
//		Debug.Log(tilePoint);

        return(tilePoint);
    }
Пример #22
0
    public Vector3 NearestFaceW(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false)
    {
        if (doDebug)
        {
            Vector3 debugCube = spacing;
            debugCube [(int)thePlane] = 0.0f;

            Matrix4x4 oldRotationMatrix = Gizmos.matrix;
            Matrix4x4 newRotationMatrix = Matrix4x4.TRS(GridToWorld(NearestFaceG(fromPoint, thePlane) + 0.5f * Vector3.one - 0.5f * units [(int)thePlane]), transform.rotation, Vector3.one);

            Gizmos.matrix = newRotationMatrix;
            Gizmos.DrawCube(Vector3.zero, debugCube);
            Gizmos.matrix = oldRotationMatrix;
        }
        return(GridToWorld(NearestFaceG(fromPoint, thePlane) + 0.5f * Vector3.one - 0.5f * units [(int)thePlane]));
    }
Пример #23
0
        public GridRender(Direct3d d3d, Camera camera, GEMSEnvironment enviroment)
            : base(d3d)
        {
            this.enviroment    = enviroment;
            this.gridDisplayed = enviroment.GridDisplayed;
            this.gridPlane     = enviroment.GridPlane;
            this.gridOffset    = enviroment.GidOffset;
            this.gridSize      = enviroment.GridSize.Value;

            this.camera = camera;
            enviroment.GridOptionChanged += new GEMSEnvironment.GridOptionChangedEventHandler(OnGridOptionChanged);
            camera.ViewChanged           += new Camera.ViewChangedEventHandler(OnViewChanged);
            camera.ProjectionChanged     += new Camera.ProjectionChangedEventHandler(OnProjectionChanged);

            isDisplayed = IsDisplay(camera.Look);
        }
Пример #24
0
    public override Vector3 NearestFaceW(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false)
    {
        Vector3 face    = NearestFaceG(fromPoint, thePlane);
        Vector3 toPoint = new Vector3();

        toPoint[idx[0]] = face[idx[0]] * side;
        toPoint[idx[1]] = face[idx[1]] * height + Mathf.Abs(face[idx[0]] % 2) * height / 2.0f;
        toPoint[idx[2]] = face[idx[2]] * depth;
        toPoint         = _transform.GFTransformPointFixed(toPoint);

        if (doDebug)
        {
            Gizmos.DrawSphere(toPoint, height / 2);
        }

        return(toPoint);
    }
Пример #25
0
    protected Vector3 GetTileCoordinates(Vector3 world, GridPlane thePlane)
    {
        //get the world point into local space
        Vector3 local = _transform.GFInverseTransformPointFixed(world);
//		Debug.Log(local);
        Vector3 tile = new Vector3();

        //find the coordinates of the tile
        tile[idx[0]] = Mathf.Floor((local[idx[0]] + 1.0f * radius) / side);
        float shift = 1 - Mathf.RoundToInt(Mathf.Abs(tile[idx[0]]) % 2);         // 1 for even, 0 for odd

        tile[idx[1]] = Mathf.Floor((local[idx[1]] + (shift * 0.5f * height)) / height);
        tile[idx[2]] = Mathf.Round(local[idx[2]] / depth);         // maybe I stil need the above instead

//		Debug.Log(tile);
        return(tile);
    }
Пример #26
0
    void Awake()
    {
        if (developerMode)
        {
            GameObject[] gridGO  = GameObject.FindGameObjectsWithTag("gridPlane");
            GameObject[] blockGO = GameObject.FindGameObjectsWithTag("blockObject");

            gridPlanes   = new GridPlane[gridGO.Length];
            blockObjects = new BlockObject[blockGO.Length];

            for (int i = 0; i < gridGO.Length; i++)
            {
                gridPlanes[i] = gridGO[i].GetComponent <GridPlane>();
            }

            for (int i = 0; i < blockGO.Length; i++)
            {
                blockObjects[i] = blockGO[i].GetComponent <BlockObject>();
            }
        }


        //suche für jedes BlockObjectk die näheste GridPlane, snappe
        foreach (BlockObject blockObject in blockObjects)
        {
            float     nearestDistance = float.PositiveInfinity;
            GridPlane nearestPlane    = null;

            foreach (GridPlane gridPlane in gridPlanes)
            {
                if (gridPlane.taken == false && !gridPlane.empthy)
                {
                    float currentDistance = Vector3.Distance(gridPlane.transform.position, blockObject.transform.position);
                    if (currentDistance < nearestDistance)
                    {
                        nearestDistance = currentDistance;
                        nearestPlane    = gridPlane;
                    }
                }
            }

            //blockObject.transform.position = nearestPlane.transform.position + new Vector3(0,0.5f,0);
            blockObject.currentAssignedGridPlane = nearestPlane;
        }
    }
Пример #27
0
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

    #region helper functions

    //transforms from quasi axis to real axis. Quasi axis is the relative X, Y and Z n the current grid plane,
    // all calculations are done in quasi space, so there is only one calculation, and then transformed into real space
    protected int[] TransformIndices(GridPlane plane)
    {
        int[] indices = new int[3];
        if (plane == GridPlane.YZ)
        {
            indices[0] = 2; indices[1] = 1; indices[2] = (int)gridPlane;
        }
        else if (plane == GridPlane.XZ)
        {
            indices[0] = 0; indices[1] = 2; indices[2] = (int)gridPlane;
        }
        else
        {
            indices[0] = 0; indices[1] = 1; indices[2] = (int)gridPlane;
        }
        Swap <int>(ref indices[0], ref indices[1], hexSideMode == HexOrientation.FlatSides);
        return(indices);
    }
Пример #28
0
    //idea: cover the hex grid with a grid of rectangular tiles, find the position inside the tile and then
    // the hex that belongs to that point's tile
    protected Vector3 NearestFaceGHerring(Vector3 world, GridPlane thePlane)
    {
        Vector3 tile      = GetTileCoordinates(world, thePlane);
        Vector3 tilePoint = GetTilePointCoordinates(world, thePlane);
        Vector3 face      = new Vector3();

        //there are three possible hexagons, find the one we need (left edge belongs to the hex, right one doesn't)
        face[idx[0]] = tilePoint[0] >= radius *Mathf.Abs(0.5f - tilePoint[1] / height) ? tile[idx[0]] : tile[idx[0]] - 1;

        int delta = tilePoint[1] > 0.5f * height ? 1 : 0;

        face[idx[1]] = tilePoint[0] >= radius *Mathf.Abs(0.5f - tilePoint[1] / height) ? tile[idx[1]] : tile[idx[1]] - Mathf.Abs(face[idx[0]] % 2) + delta;

        face[idx[2]] = tile[idx[2]];
        //Debug.Log(face);

        return(face);
    }
Пример #29
0
        public static void DrawCell(GridPlane gridPlane, int cellIndex, Color fillup, Color outline)
        {
            var cellCenterInWorld = gridPlane.GetCellCenter(cellIndex);
            var cellHalfSize      = gridPlane.CellSize / 2.0f;

            Vector3[] verts = new Vector3[]
            {
                cellCenterInWorld - gridPlane.transform.right * cellHalfSize.x - gridPlane.transform.forward * cellHalfSize.y,
                cellCenterInWorld - gridPlane.transform.right * cellHalfSize.x + gridPlane.transform.forward * cellHalfSize.y,
                cellCenterInWorld + gridPlane.transform.right * cellHalfSize.x + gridPlane.transform.forward * cellHalfSize.y,
                cellCenterInWorld + gridPlane.transform.right * cellHalfSize.x - gridPlane.transform.forward * cellHalfSize.y,
            };
            var rectColor = fillup;

            rectColor.a = 0.2f;
            var outlineColor = outline;

            outlineColor.a = 0.5f;
            Handles.DrawSolidRectangleWithOutline(verts, rectColor, outlineColor);
        }
Пример #30
0
    /// <summary>Returns the world position of the nearest face.</summary>
    /// <returns>World position of the nearest face.</returns>
    /// <param name="worldPoint">Point in world space.</param>
    /// <param name="plane">Plane on which the face lies.</param>
    /// <param name="doDebug">Whether to draw a small debug sphere at the vertex.</param>
    ///
    /// Similar to <see cref="NearestVertexW"/>, it returns the world
    /// coordinates of a face on the grid. Since the face is enclosed by four
    /// vertices, the returned value is the point in between all four of the
    /// vertices. You also need to specify on which plane the face lies. If
    /// <c>doDebug</c> is set a small gizmo face will drawn inside the face.
    public override Vector3 NearestFaceW(Vector3 worldPoint, GridPlane plane, bool doDebug)
    {
        //debugging
        if (doDebug)
        {
            Vector3 debugCube = spacing;
            debugCube[(int)plane] = 0.0f;

            //store the old matrix and create a new one based on the grid's roation and the point's position
            Matrix4x4 oldRotationMatrix = Gizmos.matrix;
            //Matrix4x4 newRotationMatrix = Matrix4x4.TRS(toPoint, transform.rotation, Vector3.one);
            Matrix4x4 newRotationMatrix = Matrix4x4.TRS(GridToWorld(NearestFaceG(worldPoint, plane)), transform.rotation, Vector3.one);

            Gizmos.matrix = newRotationMatrix;
            Gizmos.DrawCube(Vector3.zero, debugCube);            //Position zero because the matrix already contains the point
            Gizmos.matrix = oldRotationMatrix;
        }

        //return toPoint;
        return(GridToWorld(NearestFaceG(worldPoint, plane)));
    }
Пример #31
0
        public GsaGridPlaneSurface(Plane plane, bool tryUseExisting = false)
        {
            m_plane     = plane;
            m_gridplane = new GridPlane();
            if (tryUseExisting)
            {
                m_gp_guid = new Guid(); // will create 0000-00000-00000-00000
            }
            else
            {
                m_gp_guid = Guid.NewGuid(); // will create random guid
            }
            m_gridsrf = new GridSurface
            {
                Direction     = 0,
                Elements      = "all",
                ElementType   = GridSurface.Element_Type.ONE_DIMENSIONAL,
                ExpansionType = GridSurfaceExpansionType.UNDEF,
                SpanType      = GridSurface.Span_Type.ONE_WAY
            };
            if (tryUseExisting)
            {
                m_gs_guid = new Guid(); // will create 0000-00000-00000-00000
            }
            else
            {
                m_gs_guid = Guid.NewGuid(); // will create random guid
            }
            m_axis          = new Axis();
            m_axis.Origin.X = plane.OriginX;
            m_axis.Origin.Y = plane.OriginY;
            m_axis.Origin.Z = plane.OriginZ;

            m_axis.XVector.X = plane.XAxis.X;
            m_axis.XVector.Y = plane.XAxis.Y;
            m_axis.XVector.Z = plane.XAxis.Z;
            m_axis.XYPlane.X = plane.YAxis.X;
            m_axis.XYPlane.Y = plane.YAxis.Y;
            m_axis.XYPlane.Z = plane.YAxis.Z;
        }
Пример #32
0
        public static void DrawGizmos(GridPlane gridPlane, GizmoType gizmoType)
        {
            Gizmos.color = Color.black;
            for (var row = 0; row <= gridPlane.Row; ++row)
            {
                Gizmos.DrawLine(gridPlane.RowBeginPosition(row), gridPlane.RowEndPosition(row));
            }
            for (var col = 0; col <= gridPlane.Column; ++col)
            {
                Gizmos.DrawLine(gridPlane.ColumnBeginPosition(col), gridPlane.ColumnEndPosition(col));
            }
            Gizmos.color = Color.white;

            for (var cellIndex = 0; cellIndex != gridPlane.Cells.Length; ++cellIndex)
            {
                var cell       = gridPlane.Cells[cellIndex];
                var cellOrigin = gridPlane.GetCellOrigin(cellIndex) + new Vector3(1, 0, 1) * 0.25f;
                if (cell != null)
                {
                    if (cell.UsageFlag.HasFlag(CellUsage.Plant))
                    {
                        Gizmos.DrawIcon(GetCellItemPosition(cellOrigin, gridPlane.CellSize.x, gridPlane.CellSize.y, Vector3.right, Vector3.forward, 3, 0), GizmosPlant);
                    }
                    if (cell.UsageFlag.HasFlag(CellUsage.Furniture))
                    {
                        Gizmos.DrawIcon(GetCellItemPosition(cellOrigin, gridPlane.CellSize.x, gridPlane.CellSize.y, Vector3.right, Vector3.forward, 3, 1), GizmosFurniture);
                    }
                    if (cell.UsageFlag.HasFlag(CellUsage.Building))
                    {
                        Gizmos.DrawIcon(GetCellItemPosition(cellOrigin, gridPlane.CellSize.x, gridPlane.CellSize.y, Vector3.right, Vector3.forward, 3, 2), GizmosBuilding);
                    }
                }
                else
                {
                    Gizmos.DrawIcon(GetCellItemPosition(cellOrigin, gridPlane.CellSize.x, gridPlane.CellSize.y, Vector3.right, Vector3.forward, 3, 0), GizmosPlant);
                    Gizmos.DrawIcon(GetCellItemPosition(cellOrigin, gridPlane.CellSize.x, gridPlane.CellSize.y, Vector3.right, Vector3.forward, 3, 1), GizmosFurniture);
                    Gizmos.DrawIcon(GetCellItemPosition(cellOrigin, gridPlane.CellSize.x, gridPlane.CellSize.y, Vector3.right, Vector3.forward, 3, 2), GizmosBuilding);
                }
            }
        }
Пример #33
0
    /// <summary>Returns the world position of the nearest face.</summary>
    /// <returns>World position of the nearest face.</returns>
    /// <param name="worldPoint">Point in world space.</param>
    /// <param name="plane">Plane on which the face lies.</param>
    /// <param name="doDebug">Whether to draw a small debug sphere at the vertex.</param>
    /// 
    /// Similar to <see cref="NearestVertexW"/>, it returns the world
    /// coordinates of a face on the grid. Since the face is enclosed by four
    /// vertices, the returned value is the point in between all four of the
    /// vertices. You also need to specify on which plane the face lies. If
    /// <c>doDebug</c> is set a small gizmo face will drawn inside the face.
    public override Vector3 NearestFaceW(Vector3 worldPoint, GridPlane plane, bool doDebug)
    {
        //debugging
        if (doDebug) {
            Vector3 debugCube = spacing;
            debugCube[(int)plane] = 0.0f;

            //store the old matrix and create a new one based on the grid's roation and the point's position
            Matrix4x4 oldRotationMatrix = Gizmos.matrix;
            //Matrix4x4 newRotationMatrix = Matrix4x4.TRS(toPoint, transform.rotation, Vector3.one);
            Matrix4x4 newRotationMatrix = Matrix4x4.TRS(GridToWorld(NearestFaceG(worldPoint, plane)), transform.rotation, Vector3.one);

            Gizmos.matrix = newRotationMatrix;
            Gizmos.DrawCube(Vector3.zero, debugCube);//Position zero because the matrix already contains the point
            Gizmos.matrix = oldRotationMatrix;
        }

        //return toPoint;
        return GridToWorld(NearestFaceG(worldPoint, plane));
    }
Пример #34
0
    public override Vector3 FindNearestFace(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false)
    {
        //get a temporary point (world space)
        Vector3 toPoint = FindNearestBox(fromPoint);

        //snap to the plane
        toPoint[(int)thePlane] = FindNearestVertex(fromPoint)[(int)thePlane];

        //debugging
        if(doDebug){
            Vector3 debugCube = spacing;
            debugCube[(int)thePlane] = 0.0f;

            //store the old matrix and create a new one based on the grid's roation and the point's position
            Matrix4x4 oldRotationMatrix = Gizmos.matrix;
            Matrix4x4 newRotationMatrix = Matrix4x4.TRS(toPoint, transform.rotation, Vector3.one);

            Gizmos.matrix = newRotationMatrix;
            Gizmos.DrawCube(Vector3.zero, debugCube);//Position zero because the matrix already contains the point
            Gizmos.matrix = oldRotationMatrix;
        }

        return toPoint;
    }
Пример #35
0
	public override Vector3 NearestFaceG(Vector3 worldPoint, GridPlane plane) {
		return NearestFaceG(worldPoint);
	}
Пример #36
0
    //returns XYZ grid coordinates of a face close to a given point
    public override Vector3 GetFaceCoordinates(Vector3 fromPoint, GridPlane thePlane)
    {
        //get the grid coordinates of the face
        Vector3 face = GetBoxCoordinates(FindNearestFace(fromPoint, thePlane));
        // two of the face coordinates are in a box, the other is on the vertex closest to the face
        face[(int)thePlane] = FindNearestVertex(fromPoint)[(int)thePlane];

        return face;
    }
Пример #37
0
	/**
	 * @brief Returns the grid position of the nearest face.
	 * @param world Point in world space.
	 * @param thePlane Plane on which the face lies.
	 * @return Grid coordinates of the nearest face.
	 * 
	 * Similar to @c #NearestFaceW, except you get grid coordinates instead of world coordinates.
	 * Since faces lie between vertices two values will always have +0.5 compared to vertex coordinates, while the values that lies on the plane will have a round number.
	 * Example:
	 * @code
	 * var myGrid: GFRectGrid;
	 * var worldPoint: Vector3;
	 * var face = myGrid.NearestFaceG (worldPoint, GFGrid.GridPlane.XY); // something like (2.5, -1.5, 3)
	 * @endcode
	 */
	public override Vector3 NearestFaceG(Vector3 fromPoint, GridPlane thePlane){
		return RoundPoint(WorldToGrid(fromPoint) - 0.5f * Vector3.one + 0.5f * units[(int)thePlane]) + 0.5f * Vector3.one - 0.5f * units[(int)thePlane];
	}
Пример #38
0
	public override Vector3 NearestFaceW(Vector3 worldPoint, GridPlane plane, bool doDebug) {
		return NearestFaceW(worldPoint, doDebug);
	}
Пример #39
0
	// similar to the base class, except these ones swap quasi-X and quasi-Y when hexes have flat sides.
	private int[] TransformIndicesS(GridPlane plane){
		int[] indices = TransformIndices (plane);
		Swap<int>(ref indices[0], ref indices[1], hexSideMode == HexOrientation.FlatSides);
		return indices;
	}
Пример #40
0
 public abstract Vector3 GetFaceCoordinates(Vector3 world, GridPlane thePlane);
Пример #41
0
 public abstract Vector3 FindNearestFace(Vector3 fromPoint, GridPlane thePlane, bool doDebug = false);
Пример #42
0
      protected virtual XYPlotLayer SDeserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
      {

        XYPlotLayer s = (o == null ? new XYPlotLayer() : (XYPlotLayer)o);
        int count;

        // Background
        IBackgroundStyle bgs = (IBackgroundStyle)info.GetValue("Background", s);
        if (null!=bgs)
        {
          if (!s.GridPlanes.Contains(CSPlaneID.Front))
            s.GridPlanes.Add(new GridPlane(CSPlaneID.Front));
          s.GridPlanes[CSPlaneID.Front].Background = bgs.Brush;
        }


        // size, position, rotation and scale
        s.Location = (XYPlotLayerPositionAndSize)info.GetValue("LocationAndSize", s);
        s._cachedLayerSize = (SizeF)info.GetValue("CachedSize", typeof(SizeF));
        s._cachedLayerPosition = (PointF)info.GetValue("CachedPosition", typeof(PointF));
        s._coordinateSystem.UpdateAreaSize(s._cachedLayerSize);


        // LayerProperties
        bool clipDataToFrame = info.GetBoolean("ClipDataToFrame");
        s._dataClipping = clipDataToFrame ? LayerDataClipping.StrictToCS : LayerDataClipping.None;

        // axis related
        s.LinkedScales = (LinkedScaleCollection)info.GetValue("AxisProperties", s);

        // Styles
        G2DScaleStyleCollection ssc = (G2DScaleStyleCollection)info.GetValue("AxisStyles", s);
        GridPlane gplane = new GridPlane(CSPlaneID.Front);
        gplane.GridStyle[0] = ssc.ScaleStyle(0).GridStyle;
        gplane.GridStyle[1] = ssc.ScaleStyle(1).GridStyle;
        s.GridPlanes.Add(gplane);
        foreach (AxisStyle ax in ssc.AxisStyles)
          s._axisStyles.Add(ax);


        // Legends
        count = info.OpenArray("Legends");
        s.Legend = (TextGraphic)info.GetValue("e", s);
        info.CloseArray(count);

        // XYPlotLayer specific
        count = info.OpenArray("LinkedLayers");
        s.LinkedLayerLink = (Main.RelDocNodeProxy)info.GetValue("e", s);
        info.CloseArray(count);

        s.GraphObjects = (GraphicCollection)info.GetValue("GraphicGlyphs", s);

        s.PlotItems = (PlotItemCollection)info.GetValue("Plots", s);

        return s;
      }
Пример #43
0
 /// <summary>Returns the grid position of the nearest face.</summary>
 /// <returns>Grid position of the nearest face.</returns>
 /// <param name="worldPoint">Point in world space.</param>
 /// <param name="plane">Plane on which the face lies.</param>
 /// 
 /// Similar to <see cref="NearestFaceW"/>, except you get grid coordinates
 /// instead of world coordinates. Since faces lie between vertices two
 /// values will always have +0.5 compared to vertex coordinates, while the
 /// values that lies on the plane will have a round number.
 /// <example>
 /// Example:
 /// <code>
 /// GFRectGrid myGrid;
 /// Vector3 worldPoint;
 /// Vector3 face = myGrid.NearestFaceG(worldPoint, GFGrid.GridPlane.XY); // something like (2.5, -1.5, 3)
 /// </code>
 /// </example>
 public override Vector3 NearestFaceG(Vector3 worldPoint, GridPlane plane)
 {
     return RoundPoint(WorldToGrid(worldPoint) - 0.5f * Vector3.one + 0.5f * Units[(int)plane]) + 0.5f * Vector3.one - 0.5f * Units[(int)plane];
 }
Пример #44
0
 public GridPlaneController(GridPlane doc)
 {
   InitializeDocument(doc);
 }
Пример #45
0
			protected virtual XYPlotLayer SDeserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
			{
				XYPlotLayer s = (o == null ? new XYPlotLayer(info) : (XYPlotLayer)o);
				int count;

				// Background
				IBackgroundStyle bgs = (IBackgroundStyle)info.GetValue("Background", s);
				if (null != bgs)
				{
					if (!s.GridPlanes.Contains(CSPlaneID.Front))
						s.GridPlanes.Add(new GridPlane(CSPlaneID.Front));
					s.GridPlanes[CSPlaneID.Front].Background = bgs.Brush;
				}

				// size, position, rotation and scale
				var location = (XYPlotLayerPositionAndSize_V0)info.GetValue("LocationAndSize", s);
				s._cachedLayerSize = (SizeF)info.GetValue("CachedSize", s);
				s._cachedLayerPosition = (PointF)info.GetValue("CachedPosition", s);
				s._coordinateSystem.UpdateAreaSize(s._cachedLayerSize);
				s.Location = location.ConvertToCurrentLocationVersion(s._cachedLayerSize, s._cachedLayerPosition);

				// LayerProperties
				bool clipDataToFrame = info.GetBoolean("ClipDataToFrame");
				s._dataClipping = clipDataToFrame ? LayerDataClipping.StrictToCS : LayerDataClipping.None;

				// axis related
				var linkedScales = (Altaxo.Graph.Scales.Deprecated.LinkedScaleCollection)info.GetValue("AxisProperties", s);
				s.SetupOldAxes(linkedScales);

				// Styles
				G2DScaleStyleCollection ssc = (G2DScaleStyleCollection)info.GetValue("AxisStyles", s);
				GridPlane gplane = new GridPlane(CSPlaneID.Front);
				gplane.GridStyle[0] = ssc.ScaleStyle(0).GridStyle;
				gplane.GridStyle[1] = ssc.ScaleStyle(1).GridStyle;
				s.GridPlanes.Add(gplane);
				foreach (AxisStyle ax in ssc.AxisStyles)
					s._axisStyles.Add(ax);

				// Legends
				count = info.OpenArray("Legends");
				var legend = (TextGraphic)info.GetValue("e", s);
				info.CloseArray(count);

				// XYPlotLayer specific
				count = info.OpenArray("LinkedLayers");
				var linkedLayer = (Main.RelDocNodeProxy)info.GetValue("e", s);
				info.CloseArray(count);
				ProvideLinkedScalesWithLinkedLayerIndex(s, linkedLayer, info);

				s.GraphObjects.AddRange((IEnumerable<IGraphicBase>)info.GetValue("GraphicGlyphs", s));
				if (null != legend)
				{
					var legend1 = new LegendText(legend);
					s.GraphObjects.Add(legend1);
				}
				s.PlotItems = (PlotItemCollection)info.GetValue("Plots", s);

				return s;
			}