int turn_obj_away_from_steep_floor(TriangleDataModel objFloor, float floorY, float objVelX, float objVelZ) { float floor_nX, floor_nY, floor_nZ, objVelXCopy, objVelZCopy, objYawX, objYawZ; if (objFloor == null) { Yaw = MoreMath.NormalizeAngleUshort(Yaw + 32767); return(0); } floor_nX = objFloor.NormX; floor_nY = objFloor.NormY; floor_nZ = objFloor.NormZ; if (floor_nY < 0.5 && floorY > Y) { objVelXCopy = objVelX; objVelZCopy = objVelZ; turn_obj_away_from_surface( objVelXCopy, objVelZCopy, floor_nX, floor_nY, floor_nZ, out objYawX, out objYawZ); Yaw = InGameTrigUtilities.InGameATan(objYawZ, objYawX); return(0); } return(1); }
void calc_new_obj_vel_and_pos_y(TriangleDataModel objFloor, float objFloorY, float objVelX, float objVelZ) { float floor_nX = objFloor.NormX; float floor_nY = objFloor.NormY; float floor_nZ = objFloor.NormZ; float objFriction; YSpeed -= Gravity; if (YSpeed > 75.0) { YSpeed = 75.0f; } if (YSpeed < -75.0) { YSpeed = -75.0f; } Y += YSpeed; if (Y < objFloorY) { Y = objFloorY; if (YSpeed < -17.5) { YSpeed = -(YSpeed / 2); } else { YSpeed = 0; } } if ((int)Y >= (int)objFloorY && (int)Y < (int)objFloorY + 37) { objVelX += floor_nX * (floor_nX * floor_nX + floor_nZ * floor_nZ) / (floor_nX * floor_nX + floor_nY * floor_nY + floor_nZ * floor_nZ) * Gravity * 2; objVelZ += floor_nZ * (floor_nX * floor_nX + floor_nZ * floor_nZ) / (floor_nX * floor_nX + floor_nY * floor_nY + floor_nZ * floor_nZ) * Gravity * 2; if (objVelX < 0.000001 && objVelX > -0.000001) { objVelX = 0; } if (objVelZ < 0.000001 && objVelZ > -0.000001) { objVelZ = 0; } if (objVelX != 0 || objVelZ != 0) { Yaw = InGameTrigUtilities.InGameATan(objVelZ, objVelX); } calc_obj_friction(out objFriction, floor_nY); HSpeed = (float)Math.Sqrt(objVelX * objVelX + objVelZ * objVelZ) * objFriction; } }
public override ContextMenuStrip GetContextMenuStrip() { if (_contextMenuStrip == null) { ToolStripMenuItem addMoreTrisItem = new ToolStripMenuItem("Add More Tris"); addMoreTrisItem.Click += (sender, e) => { string text = DialogUtilities.GetStringFromDialog(labelText: "Enter triangle addresses as hex uints."); List <uint> triAddressList = MapUtilities.ParseCustomTris(text, TriangleClassification.Wall); if (triAddressList == null) { return; } _triList.AddRange(triAddressList.ConvertAll(address => TriangleDataModel.CreateLazy(address))); }; _contextMenuStrip = new ContextMenuStrip(); _contextMenuStrip.Items.Add(addMoreTrisItem); _contextMenuStrip.Items.Add(new ToolStripSeparator()); GetWallToolStripMenuItems().ForEach(item => _contextMenuStrip.Items.Add(item)); _contextMenuStrip.Items.Add(new ToolStripSeparator()); GetTriangleToolStripMenuItems().ForEach(item => _contextMenuStrip.Items.Add(item)); } return(_contextMenuStrip); }
private static TriangleDataModel FindCeilingFromList(short shortX, short shortY, short shortZ, int cellX, int cellZ, bool isStaticParition) { uint partitionAddress = isStaticParition ? TriangleConfig.StaticTrianglePartitionAddress : TriangleConfig.DynamicTrianglePartitionAddress; int type = 1; // ceiling int typeSize = 2 * 4; int xSize = 3 * typeSize; int zSize = 16 * xSize; uint address = (uint)(partitionAddress + cellZ * zSize + cellX * xSize + type * typeSize); address = Config.Stream.GetUInt32(address); while (address != 0) { uint triAddress = Config.Stream.GetUInt32(address + 4); TriangleDataModel tri = TriangleDataModel.Create(triAddress); bool isLegitimateTriangle = tri.NormX != 0 || tri.NormY != 0 || tri.NormZ != 0; if (isLegitimateTriangle && tri.IsPointInsideAndBelowTriangle(shortX, shortY, shortZ)) { return(tri); } address = Config.Stream.GetUInt32(address); } return(null); }
/** * Every level is split into 16x16 cells, this takes a surface, finds * the appropriate cells (with a buffer), and adds the surface to those * cells. * @param surface The surface to check * @param dynamic Boolean determining whether the surface is static or dynamic */ public static List <(int x, int z)> GetCells(TriangleDataModel tri) { // minY/maxY maybe? s32 instead of s16, though. short minX, minZ, maxX, maxZ; short minCellX, minCellZ, maxCellX, maxCellZ; short cellZ, cellX; minX = min_3(tri.X1, tri.X2, tri.X3); minZ = min_3(tri.Z1, tri.Z2, tri.Z3); maxX = max_3(tri.X1, tri.X2, tri.X3); maxZ = max_3(tri.Z1, tri.Z2, tri.Z3); minCellX = lower_cell_index(minX); maxCellX = upper_cell_index(maxX); minCellZ = lower_cell_index(minZ); maxCellZ = upper_cell_index(maxZ); List <(int x, int z)> cells = new List <(int x, int z)>(); for (cellZ = minCellZ; cellZ <= maxCellZ; cellZ++) { for (cellX = minCellX; cellX <= maxCellX; cellX++) { cells.Add((cellX, cellZ)); } } return(cells); }
public static (float newMarioX, float newMarioZ) HandleWallDisplacement( float marioX, float marioY, float marioZ, TriangleDataModel surf, float radius, float offsetY) { return(HandleWallDisplacement(marioX, marioY, marioZ, new List <TriangleDataModel>() { surf }, radius, offsetY)); }
private void UpdateBasedOnCoordinates() { foreach (uint triangleAddress in TriangleAddresses) { TriangleDataModel tri = TriangleDataModel.Create(triangleAddress); UpdateBasedOnCoordinates(triangleAddress, tri.X1, tri.Y1, tri.Z1, tri.X2, tri.Y2, tri.Z2, tri.X3, tri.Y3, tri.Z3); } }
public TriangleDataModel GetTriangleStruct(uint address) { if (_triangleCache.ContainsKey(address)) { return(_triangleCache[address]); } TriangleDataModel triStruct = new TriangleDataModel(address); _triangleCache.Add(address, triStruct); return(triStruct); }
public static List <TriangleDataModel> GetTrianglesInRange(uint startAddress, int numTriangles) { List <TriangleDataModel> triangleList = new List <TriangleDataModel>(); for (int i = 0; i < numTriangles; i++) { uint address = startAddress + (uint)(i * TriangleConfig.TriangleStructSize); TriangleDataModel triangle = new TriangleDataModel(address); triangleList.Add(triangle); } return(triangleList); }
public static (TriangleDataModel, float) FindFloorAndY(float floatX, float floatY, float floatZ) { TriangleDataModel tri = FindFloor(floatX, floatY, floatZ); if (tri == null) { return(tri, -11000); } float y = tri.GetTruncatedHeightOnTriangle(floatX, floatZ); return(tri, y); }
public static (TriangleDataModel, float) FindCeilingAndY(float floatX, float floatY, float floatZ) { TriangleDataModel tri = FindCeiling(floatX, floatY + 80, floatZ); if (tri == null) { return(tri, 20000); } float y = tri.GetTruncatedHeightOnTriangle(floatX, floatZ); return(tri, y); }
public static MapObjectLevelWall Create(string text) { List <uint> triAddressList = MapUtilities.ParseCustomTris(text, null); if (triAddressList == null) { return(null); } List <TriangleDataModel> triList = triAddressList.ConvertAll(address => TriangleDataModel.CreateLazy(address)); return(new MapObjectLevelWall(triList)); }
private static void perform_ground_step( MutableMarioState marioState, TriangleDataModel floor, List <TriangleDataModel> walls) { for (int i = 0; i < 4; i++) { float intendedPosX = marioState.X + floor.NormY * (marioState.XSpeed / 4.0f); float intendedPosZ = marioState.Z + floor.NormY * (marioState.ZSpeed / 4.0f); float intendedPosY = marioState.Y; perform_ground_quarter_step( marioState, intendedPosX, intendedPosY, intendedPosZ, floor, walls); } }
private short object_step() { float objX = X; float objY = Y; float objZ = Z; float waterY = FLOOR_LOWER_LIMIT_MISC; float objVelX = HSpeed * InGameTrigUtilities.InGameSine(Yaw); float objVelZ = HSpeed * InGameTrigUtilities.InGameCosine(Yaw); short collisionFlags = 0; if (obj_find_wall(objX + objVelX, objY, objZ + objVelZ, objVelX, objVelZ) == 0) { Dead = true; } (TriangleDataModel staticFloor, float floorY) = CellSnapshot.FindFloorAndY(objX + objVelX, objY, objZ + objVelZ); StaticFloor = staticFloor; if (turn_obj_away_from_steep_floor(StaticFloor, floorY, objVelX, objVelZ) == 1) { waterY = CellSnapshot.GetWaterAtPos(objX + objVelX, objZ + objVelZ); if (waterY > objY) { calc_new_obj_vel_and_pos_y_underwater(StaticFloor, floorY, objVelX, objVelZ, waterY); collisionFlags += OBJ_COL_FLAG_UNDERWATER; } else { calc_new_obj_vel_and_pos_y(StaticFloor, floorY, objVelX, objVelZ); } } else { collisionFlags = (short)(collisionFlags + ((collisionFlags & OBJ_COL_FLAG_HIT_WALL) ^ OBJ_COL_FLAG_HIT_WALL)); } obj_update_pos_vel_xz(); if ((int)Y == (int)floorY) { collisionFlags += OBJ_COL_FLAG_GROUNDED; } if ((int)YSpeed == 0) { collisionFlags += OBJ_COL_FLAG_NO_Y_VEL; } return(collisionFlags); }
public static float GetHeightOnTriangle(float x, float z) { float normX = -0.0339056774973869f; float normY = 0.919187009334564f; float normZ = 0.392358928918839f; float normOffset = 969.59228515625f; x = (int)x; z = (int)z; return((float)TriangleDataModel.GetHeightOnTriangle( x, z, normX, normY, normZ, normOffset)); }
private void OnUpdate(object sender, EventArgs e) { this.TryInvoke(new Action(() => { UpdateComboBoxes(); DataModels.Update(); FormManager.Update(); Config.ObjectSlotsManager.Update(); Config.ObjectManager.Update(tabControlMain.SelectedTab == tabPageObject); Config.MarioManager.Update(tabControlMain.SelectedTab == tabPageMario); Config.CameraManager.Update(tabControlMain.SelectedTab == tabPageCamera); Config.HudManager.Update(tabControlMain.SelectedTab == tabPageHud); Config.ActionsManager.Update(tabControlMain.SelectedTab == tabPageActions); Config.WaterManager.Update(tabControlMain.SelectedTab == tabPageWater); Config.SnowManager.Update(tabControlMain.SelectedTab == tabPageSnow); Config.InputManager.Update(tabControlMain.SelectedTab == tabPageInput); Config.FileManager.Update(tabControlMain.SelectedTab == tabPageFile); Config.MainSaveManager.Update(tabControlMain.SelectedTab == tabPageMainSave); Config.QuarterFrameManager.Update(tabControlMain.SelectedTab == tabPageQuarterFrame); Config.CustomManager.Update(tabControlMain.SelectedTab == tabPageCustom); Config.VarHackManager.Update(tabControlMain.SelectedTab == tabPageVarHack); Config.CamHackManager.Update(tabControlMain.SelectedTab == tabPageCamHack); Config.MiscManager.Update(tabControlMain.SelectedTab == tabPageMisc); Config.TriangleManager.Update(tabControlMain.SelectedTab == tabPageTriangles); Config.AreaManager.Update(tabControlMain.SelectedTab == tabPageArea); Config.DebugManager.Update(tabControlMain.SelectedTab == tabPageDebug); Config.PuManager.Update(tabControlMain.SelectedTab == tabPagePu); Config.TasManager.Update(tabControlMain.SelectedTab == tabPageTas); Config.TestingManager.Update(tabControlMain.SelectedTab == tabPageTesting); Config.GfxManager.Update(tabControlMain.SelectedTab == tabPageGfx); Config.PaintingManager.Update(tabControlMain.SelectedTab == tabPagePainting); Config.MusicManager.Update(tabControlMain.SelectedTab == tabPageMusic); Config.SoundManager.Update(tabControlMain.SelectedTab == tabPageSound); Config.OptionsManager.Update(tabControlMain.SelectedTab == tabPageOptions); Config.MemoryManager.Update(tabControlMain.SelectedTab == tabPageMemory); Config.SearchManager.Update(tabControlMain.SelectedTab == tabPageSearch); Config.CellsManager.Update(tabControlMain.SelectedTab == tabPageCells); Config.CoinManager.Update(tabControlMain.SelectedTab == tabPageCoin); Config.M64Manager.Update(tabControlMain.SelectedTab == tabPageM64); Config.MapManager.Update(tabControlMain.SelectedTab == tabPageMap); Config.ScriptManager.Update(tabControlMain.SelectedTab == tabPageScript); Config.WarpManager.Update(tabControlMain.SelectedTab == tabPageWarp); Config.ModelManager?.Update(); Config.InjectionManager.Update(); Config.HackManager.Update(); WatchVariableLockManager.Update(); TestUtilities.Update(); TriangleDataModel.ClearCache(); })); }
private static void perform_ground_quarter_step( MutableMarioState marioState, float intendedPosX, float intendedPosY, float intendedPosZ, TriangleDataModel floor, List <TriangleDataModel> walls) { (intendedPosX, intendedPosZ) = WallDisplacementCalculator.HandleWallDisplacement( intendedPosX, intendedPosY, intendedPosZ, walls, 50, 60); float floorHeight = floor.GetTruncatedHeightOnTriangle(intendedPosX, intendedPosZ); marioState.X = intendedPosX; marioState.Y = floorHeight; marioState.Z = intendedPosZ; }
public CorkBox(float x, float y, float z, CellSnapshot cellSnapshot) { X = x; Y = y; Z = z; XSpeed = 0; YSpeed = 0; ZSpeed = 0; HSpeed = 0; Yaw = 0; InactivityTimer = 0; Dead = false; StaticFloor = null; CellSnapshot = cellSnapshot; }
public void RefreshAndSort() { dataGridView.Rows.Clear(); List <(uint address, double dist)> dataList = _triAddressList.ConvertAll(address => { TriangleDataModel tri = TriangleDataModel.Create(address); double dist = tri.GetDistToMidpoint(); return(address, dist); }); dataList = Enumerable.OrderBy(dataList, data => data.dist).ToList(); dataList.ForEach(data => { dataGridView.Rows.Add(HexUtilities.FormatValue(data.address), Math.Round(data.dist, 3)); }); labelNumTriangles.Text = _triAddressList.Count + " Triangles"; }
public static TriangleDataModel FindCeiling(float floatX, float floatY, float floatZ) { int LEVEL_BOUNDARY_MAX = 0x2000; int CELL_SIZE = 0x400; short shortX = (short)floatX; short shortY = (short)floatY; short shortZ = (short)floatZ; if (shortX <= -LEVEL_BOUNDARY_MAX || shortX >= LEVEL_BOUNDARY_MAX) { return(null); } if (shortZ <= -LEVEL_BOUNDARY_MAX || shortZ >= LEVEL_BOUNDARY_MAX) { return(null); } int cellX = ((shortX + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & 0xF; int cellZ = ((shortZ + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & 0xF; TriangleDataModel staticTri = FindCeilingFromList(shortX, shortY, shortZ, cellX, cellZ, true); TriangleDataModel dynamicTri = FindCeilingFromList(shortX, shortY, shortZ, cellX, cellZ, false); if (staticTri == null && dynamicTri == null) { return(null); } if (staticTri == null) { return(dynamicTri); } if (dynamicTri == null) { return(staticTri); } double yOnStaticTri = staticTri.GetHeightOnTriangle(shortX, shortZ); double yOnDynamicTri = dynamicTri.GetHeightOnTriangle(shortX, shortZ); return(yOnDynamicTri < yOnStaticTri ? dynamicTri : staticTri); }
private static bool TrianglePassesClassification(TriangleDataModel tri, TriangleClassificationExtended classification) { switch (classification) { case TriangleClassificationExtended.FloorTris: return(tri.Classification == TriangleClassification.Floor); case TriangleClassificationExtended.WallTris: return(tri.Classification == TriangleClassification.Wall); case TriangleClassificationExtended.CeilingTris: return(tri.Classification == TriangleClassification.Ceiling); case TriangleClassificationExtended.AllTris: return(true); default: throw new ArgumentOutOfRangeException(); } }
private void OnUpdate(object sender, EventArgs e) { using (new AccessScope <StroopMainForm>(this)) { labelFpsCounter.Text = "FPS: " + (int)Config.Stream?.FpsInPractice ?? "<none>"; UpdateComboBoxes(); DataModels.Update(); FormManager.Update(); ObjectSlotsManager.Update(); //Config.InjectionManager.Update(); foreach (TabPage page in tabControlMain.TabPages) { Tabs.STROOPTab.UpdateTab(page, tabControlMain.SelectedTab == page); } WatchVariableLockManager.Update(); TriangleDataModel.ClearCache(); } }
private Color GetColorForTri(TriangleDataModel tri, int vertex) { double clampedNormY = MoreMath.Clamp(tri.NormY, -1, 1); Color color; switch (tri.Classification) { case TriangleClassification.Wall: color = tri.XProjection ? Color.FromArgb(58, 116, 58) : Color.FromArgb(116, 203, 116); break; case TriangleClassification.Floor: color = Color.FromArgb(130, 130, 231).Darken(0.6 * (1 - clampedNormY)); break; case TriangleClassification.Ceiling: color = Color.FromArgb(231, 130, 130).Darken(0.6 * (clampedNormY + 1)); break; default: throw new ArgumentOutOfRangeException(); } double amount = MoreMath.Clamp(Size / 100, 0, 1); switch (vertex) { case 1: return(color.Lighten(amount)); case 2: return(color); case 3: return(color.Darken(amount)); default: throw new ArgumentOutOfRangeException(); } }
public override void Update() { TriangleDataModel tri = _triangleData; Displayed = tri != null; if (tri == null) { return; } Color4 color = new Color4( MyColor.Value.R / 255f, MyColor.Value.G / 255f, MyColor.Value.B / 255f, Opacity); _triGraphics.SetTriangles(new Vertex[] { new Vertex(new Vector3(tri.X1, tri.Y1, tri.Z1), color), new Vertex(new Vector3(tri.X2, tri.Y2, tri.Z2), color), new Vertex(new Vector3(tri.X3, tri.Y3, tri.Z3), color), }); }
public MapObjectHoverData( MapObject mapObject, double x, double y, double z, uint?objAddress = null, TriangleDataModel tri = null, bool isTriUnit = false, int?index = null, int?index2 = null, string info = null) { MapObject = mapObject; X = x; Y = y; Z = z; ObjAddress = objAddress; Tri = tri; IsTriUnit = isTriUnit; Index = index; Index2 = index2; Info = info; }
void obj_check_floor_death(short collisionFlags, TriangleDataModel floor) { if (floor == null) { return; } if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == OBJ_COL_FLAG_GROUNDED) { switch (floor.SurfaceType) { case 0x0001: Dead = true; break; case 0x000A: Dead = true; break; default: break; } } }
public override ContextMenuStrip GetContextMenuStrip() { if (_contextMenuStrip == null) { ToolStripMenuItem itemAutoUpdate = new ToolStripMenuItem("Auto Update"); itemAutoUpdate.Click += (sender, e) => { _autoUpdate = !_autoUpdate; itemAutoUpdate.Checked = _autoUpdate; }; itemAutoUpdate.Checked = _autoUpdate; ToolStripMenuItem itemReset = new ToolStripMenuItem("Reset"); itemReset.Click += (sender, e) => ResetTriangles(); ToolStripMenuItem itemRemoveCurrentTri = new ToolStripMenuItem("Remove Current Tri"); itemRemoveCurrentTri.Click += (sender, e) => { _removeCurrentTri = !_removeCurrentTri; itemRemoveCurrentTri.Checked = _removeCurrentTri; }; ToolStripMenuItem itemShowTriData = new ToolStripMenuItem("Show Tri Data"); itemShowTriData.Click += (sender, e) => { List <TriangleDataModel> tris = _triAddressList.ConvertAll(address => TriangleDataModel.Create(address)); TriangleUtilities.ShowTriangles(tris); }; ToolStripMenuItem itemOpenForm = new ToolStripMenuItem("Open Form"); itemOpenForm.Click += (sender, e) => { if (_triangleListForm != null) { return; } _triangleListForm = new TriangleListForm( this, TriangleClassification.Floor, _triAddressList); _triangleListForm.Show(); }; _contextMenuStrip = new ContextMenuStrip(); _contextMenuStrip.Items.Add(itemAutoUpdate); _contextMenuStrip.Items.Add(itemReset); _contextMenuStrip.Items.Add(itemRemoveCurrentTri); _contextMenuStrip.Items.Add(itemShowTriData); _contextMenuStrip.Items.Add(itemOpenForm); _contextMenuStrip.Items.Add(new ToolStripSeparator()); GetFloorToolStripMenuItems().ForEach(item => _contextMenuStrip.Items.Add(item)); _contextMenuStrip.Items.Add(new ToolStripSeparator()); GetHorizontalTriangleToolStripMenuItems().ForEach(item => _contextMenuStrip.Items.Add(item)); _contextMenuStrip.Items.Add(new ToolStripSeparator()); GetTriangleToolStripMenuItems().ForEach(item => _contextMenuStrip.Items.Add(item)); } return(_contextMenuStrip); }
public void SetTriangles(List <TriangleDataModel> triangleList) { this.Text = "Triangle Info"; textBoxTitle.Text = "Triangles"; textBoxTriangleInfo.Text = TriangleDataModel.GetFieldNameString() + "\n" + String.Join("\n", triangleList); }
void DrawOrthogonalProjection(MapGraphics graphics, TriangleDataModel tri, (Vector3 pNor, float pD) plane, Vector4 color)
public static List <TriangleDataModel> GetTrianglesInRange(uint startAddress, int numTriangles) { return(GetTriangleAddressesInRange(startAddress, numTriangles) .ConvertAll(triAddress => TriangleDataModel.Create(triAddress))); }