public override bool Prepare(Vector3I[] marks) { a = marks[0]; c = marks[1]; b = marks[2]; d = new Vector3I(a.X + c.X - b.X, a.Y + c.Y - b.Y, a.Z + c.Z - b.Z); Bounds = new BoundingBox( Math.Min(Math.Min(a.X, b.X), Math.Min(c.X, d.X)), Math.Min(Math.Min(a.Y, b.Y), Math.Min(c.Y, d.Y)), Math.Min(Math.Min(a.Z, b.Z), Math.Min(c.Z, d.Z)), Math.Max(Math.Max(a.X, b.X), Math.Max(c.X, d.X)), Math.Max(Math.Max(a.Y, b.Y), Math.Max(c.Y, d.Y)), Math.Max(Math.Max(a.Z, b.Z), Math.Max(c.Z, d.Z)) ); Coords = Bounds.MinVertex; if (!base.Prepare(marks)) { return(false); } normal = (b - a).Cross(c - a); normalF = normal.Normalize(); BlocksTotalEstimate = GetBlockTotalEstimate(); s1 = normal.Cross(a - b).Normalize(); s2 = normal.Cross(b - c).Normalize(); s3 = normal.Cross(c - d).Normalize(); s4 = normal.Cross(d - a).Normalize(); return(true); }
public override bool Prepare(Vector3I[] marks) { a = marks[0]; c = marks[1]; b = marks[2]; d = new Vector3I(a.X + c.X - b.X, a.Y + c.Y - b.Y, a.Z + c.Z - b.Z); Bounds = new BoundingBox( Math.Min(Math.Min(a.X, b.X), Math.Min(c.X, d.X)), Math.Min(Math.Min(a.Y, b.Y), Math.Min(c.Y, d.Y)), Math.Min(Math.Min(a.Z, b.Z), Math.Min(c.Z, d.Z)), Math.Max(Math.Max(a.X, b.X), Math.Max(c.X, d.X)), Math.Max(Math.Max(a.Y, b.Y), Math.Max(c.Y, d.Y)), Math.Max(Math.Max(a.Z, b.Z), Math.Max(c.Z, d.Z)) ); Coords = Bounds.MinVertex; if (!base.Prepare(marks)) return false; normal = (b - a).Cross(c - a); normalF = normal.Normalize(); BlocksTotalEstimate = GetBlockTotalEstimate(); s1 = normal.Cross(a - b).Normalize(); s2 = normal.Cross(b - c).Normalize(); s3 = normal.Cross(c - d).Normalize(); s4 = normal.Cross(d - a).Normalize(); return true; }
public override bool Prepare(Vector3I[] marks) { a = marks[0]; b = marks[1]; c = marks[2]; if (a == b || b == c || c == a) { if (a != c) b = c; isLine = true; } Bounds = new BoundingBox( Math.Min(Math.Min(a.X, b.X), c.X), Math.Min(Math.Min(a.Y, b.Y), c.Y), Math.Min(Math.Min(a.Z, b.Z), c.Z), Math.Max(Math.Max(a.X, b.X), c.X), Math.Max(Math.Max(a.Y, b.Y), c.Y), Math.Max(Math.Max(a.Z, b.Z), c.Z) ); Coords = Bounds.MinVertex; if (!base.Prepare(marks)) return false; normal = (b - a).Cross(c - a); normalF = normal.Normalize(); BlocksTotalEstimate = GetBlockTotalEstimate(); s1 = normal.Cross(a - b).Normalize(); s2 = normal.Cross(b - c).Normalize(); s3 = normal.Cross(c - a).Normalize(); return true; }
public override bool Prepare(Vector3I[] marks) { a = marks[0]; b = marks[1]; c = marks[2]; if (a == b || b == c || c == a) { if (a != c) { b = c; } isLine = true; } Bounds = new BoundingBox( Math.Min(Math.Min(a.X, b.X), c.X), Math.Min(Math.Min(a.Y, b.Y), c.Y), Math.Min(Math.Min(a.Z, b.Z), c.Z), Math.Max(Math.Max(a.X, b.X), c.X), Math.Max(Math.Max(a.Y, b.Y), c.Y), Math.Max(Math.Max(a.Z, b.Z), c.Z) ); Coords = Bounds.MinVertex; if (!base.Prepare(marks)) { return(false); } normal = (b - a).Cross(c - a); normalF = normal.Normalize(); BlocksTotalEstimate = GetBlockTotalEstimate(); s1 = normal.Cross(a - b).Normalize(); s2 = normal.Cross(b - c).Normalize(); s3 = normal.Cross(c - a).Normalize(); return(true); }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition) { if (string.IsNullOrEmpty(blockDefinition.Model)) { return; } matrices.Add(matrix); models.Add(blockDefinition.Model); var data = new MyEntitySubpart.Data(); MyCubeBlockDefinition subBlockDefinition; MatrixD subBlockMatrix; Vector3 dummyPosition; MyModel modelData = MyModels.GetModelOnlyData(blockDefinition.Model); foreach (var dummy in modelData.Dummies) { if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, dummy.Key, dummy.Value, ref data)) { MatrixD mCopy = MatrixD.Multiply(data.InitialTransform, matrix); matrices.Add(mCopy); models.Add(data.File); } else if (MyFakes.ENABLE_SUBBLOCKS && MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, dummy.Key, dummy.Value, false, out subBlockDefinition, out subBlockMatrix, out dummyPosition)) { if (!string.IsNullOrEmpty(subBlockDefinition.Model)) { // Repair subblock matrix to have int axes (because preview renderer does not allow such non integer rotation). Vector3I forward = Vector3I.Round(Vector3.DominantAxisProjection(subBlockMatrix.Forward)); Vector3I invForward = Vector3I.One - Vector3I.Abs(forward); Vector3I right = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)subBlockMatrix.Right * invForward)); Vector3I up; Vector3I.Cross(ref right, ref forward, out up); subBlockMatrix.Forward = forward; subBlockMatrix.Right = right; subBlockMatrix.Up = up; MatrixD mCopy = MatrixD.Multiply(subBlockMatrix, matrix); matrices.Add(mCopy); models.Add(subBlockDefinition.Model); } } } }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition, float gridScale) { if (string.IsNullOrEmpty(blockDefinition.Model)) { return; } matrices.Add(matrix); models.Add(blockDefinition.Model); var data = new MyEntitySubpart.Data(); MyCubeBlockDefinition subBlockDefinition; MatrixD subBlockMatrix; Vector3 dummyPosition; MyModel modelData = VRage.Game.Models.MyModels.GetModelOnlyData(blockDefinition.Model); modelData.Rescale(gridScale); foreach (var dummy in modelData.Dummies) { if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, dummy.Key, dummy.Value, ref data)) { // Rescale model var model = VRage.Game.Models.MyModels.GetModelOnlyData(data.File); if (model != null) { model.Rescale(gridScale); } MatrixD mCopy = MatrixD.Multiply(data.InitialTransform, matrix); matrices.Add(mCopy); models.Add(data.File); } else if (MyFakes.ENABLE_SUBBLOCKS && MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, dummy.Key, dummy.Value, false, out subBlockDefinition, out subBlockMatrix, out dummyPosition)) { if (!string.IsNullOrEmpty(subBlockDefinition.Model)) { // Rescale model var model = VRage.Game.Models.MyModels.GetModelOnlyData(subBlockDefinition.Model); if (model != null) { model.Rescale(gridScale); } // Repair subblock matrix to have int axes (because preview renderer does not allow such non integer rotation). Vector3I forward = Vector3I.Round(Vector3.DominantAxisProjection(subBlockMatrix.Forward)); Vector3I invForward = Vector3I.One - Vector3I.Abs(forward); Vector3I right = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)subBlockMatrix.Right * invForward)); Vector3I up; Vector3I.Cross(ref right, ref forward, out up); subBlockMatrix.Forward = forward; subBlockMatrix.Right = right; subBlockMatrix.Up = up; MatrixD mCopy = MatrixD.Multiply(subBlockMatrix, matrix); matrices.Add(mCopy); models.Add(subBlockDefinition.Model); } } } // Precache models for generated blocks if (MyFakes.ENABLE_GENERATED_BLOCKS && !blockDefinition.IsGeneratedBlock && blockDefinition.GeneratedBlockDefinitions != null) { foreach (var generatedBlockDefId in blockDefinition.GeneratedBlockDefinitions) { MyCubeBlockDefinition generatedBlockDef; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(generatedBlockDefId, out generatedBlockDef)) { var model = VRage.Game.Models.MyModels.GetModelOnlyData(generatedBlockDef.Model); if (model != null) { model.Rescale(gridScale); } } } } }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition, float gridScale) { if (!string.IsNullOrEmpty(blockDefinition.Model)) { matrices.Add(matrix); models.Add(blockDefinition.Model); MyEntitySubpart.Data outData = new MyEntitySubpart.Data(); MyModel modelOnlyData = MyModels.GetModelOnlyData(blockDefinition.Model); modelOnlyData.Rescale(gridScale); foreach (KeyValuePair <string, MyModelDummy> pair in modelOnlyData.Dummies) { MyCubeBlockDefinition definition; MatrixD xd; Vector3 vector; if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, pair.Key, pair.Value, ref outData)) { MyModel model = MyModels.GetModelOnlyData(outData.File); if (model != null) { model.Rescale(gridScale); } MatrixD item = MatrixD.Multiply(outData.InitialTransform, matrix); matrices.Add(item); models.Add(outData.File); continue; } if (MyFakes.ENABLE_SUBBLOCKS && (MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, pair.Key, pair.Value, false, out definition, out xd, out vector) && !string.IsNullOrEmpty(definition.Model))) { Vector3I vectori4; MyModel model2 = MyModels.GetModelOnlyData(definition.Model); if (model2 != null) { model2.Rescale(gridScale); } Vector3I vectori = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)xd.Forward)); Vector3I vectori2 = Vector3I.One - Vector3I.Abs(vectori); Vector3I vectori3 = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)(xd.Right * vectori2))); Vector3I.Cross(ref vectori3, ref vectori, out vectori4); xd.Forward = (Vector3D)vectori; xd.Right = (Vector3D)vectori3; xd.Up = (Vector3D)vectori4; MatrixD item = MatrixD.Multiply(xd, matrix); matrices.Add(item); models.Add(definition.Model); } } if ((MyFakes.ENABLE_GENERATED_BLOCKS && !blockDefinition.IsGeneratedBlock) && (blockDefinition.GeneratedBlockDefinitions != null)) { foreach (MyDefinitionId id in blockDefinition.GeneratedBlockDefinitions) { MyCubeBlockDefinition definition2; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(id, out definition2)) { MyModel model3 = MyModels.GetModelOnlyData(definition2.Model); if (model3 != null) { model3.Rescale(gridScale); } } } } } }
/// <summary> /// Yields the first occupied cells encountered when raycasting a grid in a given base direction. /// </summary> /// <param name="grid">The grid to get blocks from.</param> /// <param name="baseDirection">The direction of ray.</param> public static IEnumerable <Vector3I> FirstBlocks(this IMyCubeGrid grid, Vector3I baseDirection) { Logger.DebugLog("baseDirection(" + baseDirection + ") has a magnitude", Logger.severity.FATAL, condition: baseDirection.RectangularLength() != 1); BoundingBox localAABB = grid.LocalAABB; Vector3I min = grid.Min, max = grid.Max; // ??? //Vector3 minF; Vector3.Divide(ref localAABB.Min, grid.GridSize, out minF); //Vector3 maxF; Vector3.Divide(ref localAABB.Max, grid.GridSize, out maxF); //Vector3I min, max; //Func<float, int> round = f => (int)Math.Round(f); //minF.ApplyOperation(round, out min); //maxF.ApplyOperation(round, out max); Vector3I perp0, perp1; perp0 = Base6Directions.GetIntVector(Base6Directions.GetPerpendicular(Base6Directions.GetDirection(baseDirection))); Vector3I.Cross(ref baseDirection, ref perp0, out perp1); int baseStart; Vector3I.Dot(ref baseDirection, ref min, out baseStart); int baseEnd; Vector3I.Dot(ref baseDirection, ref max, out baseEnd); if (baseStart > baseEnd) { int temp = baseStart; baseStart = baseEnd; baseEnd = temp; } bool incrementBase = baseStart <= baseEnd; int perp0Min; Vector3I.Dot(ref perp0, ref min, out perp0Min); int perp0Max; Vector3I.Dot(ref perp0, ref max, out perp0Max); if (perp0Max < perp0Min) { int temp = perp0Max; perp0Max = perp0Min; perp0Min = temp; } int perp1Min; Vector3I.Dot(ref perp1, ref min, out perp1Min); int perp1Max; Vector3I.Dot(ref perp1, ref max, out perp1Max); if (perp1Max < perp1Min) { int temp = perp1Max; perp1Max = perp1Min; perp1Min = temp; } Logger.TraceLog("min: " + min + ", max: " + max, Logger.severity.DEBUG); Logger.TraceLog("base: " + baseDirection + ", perp0: " + perp0 + ", perp1: " + perp1, Logger.severity.DEBUG); Logger.TraceLog("base range: " + baseStart + ":" + baseEnd, Logger.severity.DEBUG); Logger.TraceLog("perp0 range: " + perp0Min + ":" + perp0Max, Logger.severity.DEBUG); Logger.TraceLog("perp1 range: " + perp1Min + ":" + perp1Max, Logger.severity.DEBUG); for (int perp0Value = perp0Min; perp0Value <= perp0Max; perp0Value++) { for (int perp1Value = perp1Min; perp1Value <= perp1Max; perp1Value++) { int baseValue = baseStart; while (true) { Vector3I cell = baseValue * baseDirection + perp0Value * perp0 + perp1Value * perp1; if (grid.CubeExists(cell)) { yield return(cell); break; } if (baseValue == baseEnd) { break; } if (incrementBase) { baseValue++; } else { baseValue--; } } } } yield break; }
public void Cross() { Vector3I a = new Vector3I(1, 0, 0); Vector3I b = new Vector3I(0, 1, 0); Vector3I cross1 = a.Cross(b); Assert.AreEqual(0, cross1.X); Assert.AreEqual(0, cross1.Y); Assert.AreEqual(1, cross1.Z); Vector3I cross2 = b.Cross(a); Assert.AreEqual(0, cross2.X); Assert.AreEqual(0, cross2.Y); Assert.AreEqual(-1, cross2.Z); }