/// <summary> /// Creates a new instance of the ScreenShot class initialized with default values. /// </summary> public ScreenShot() { InitializeComponent(); m_bShowRuler = true; m_bIsActive = true; m_nMode = Mode.None; m_nSelectedBounds = RectangleBounds.None; m_oStringFormat = new StringFormat(); m_oStringFormat.FormatFlags = StringFormatFlags.DirectionVertical; }
/// <summary> /// Handles creating the collision box for the weapon. /// </summary> /// <param name="playerID">Player's EntityID</param> /// <param name="weaponID">Weapon's EntityID</param> private void CreateWeaponCollision(uint playerID, uint weaponID) { uint roomID = _positionComponent[playerID].RoomID; Collideable weaponCollision = new Collideable { EntityID = weaponID, RoomID = roomID }; Facing facing = (Facing)_game.SpriteAnimationComponent[playerID].CurrentAnimationRow; Vector2 position = updatePositionByFacing(_positionComponent[playerID], facing, 32); RectangleBounds rb = new RectangleBounds((int)position.X, (int)position.Y, 64, 64); weaponCollision.Bounds = rb; _collisionComponent.Add(weaponCollision.EntityID, weaponCollision); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var scale = transform.localScale; var bounds = new RectangleBounds { HalfWidthHeight = new float2(scale.x / 2.0f, scale.y / 2.0f), }; dstManager.AddComponentData(entity, bounds); dstManager.AddComponent <BrickScore>(entity); dstManager.AddComponent <Position2D>(entity); dstManager.RemoveComponent <Translation>(entity); dstManager.RemoveComponent <Rotation>(entity); }
/// <summary> /// Eats a bite of rock cake if hitpoints are above 1 /// </summary> /// <returns>true if a bite of rock cake is taken</returns> protected bool Hitpoints() { if (TimeSinceLastOverload < overloadDrainTime || Numerical.CloseEnough(overloadBoostTime, TimeSinceLastOverload, 0.02)) { return(false); //an overload might be taking effect or wearing off } const double oneHitpoint = 0.035714285714285712; RectangleBounds hitpoints = Minimap.HitpointsDigitsArea(); double redHitpointsMatch = Vision.FractionalMatchPiece(HitpointsRed, hitpoints.Left, hitpoints.Right, hitpoints.Top, hitpoints.Bottom); if (Numerical.WithinRange(redHitpointsMatch, oneHitpoint, 0.01 * oneHitpoint) || (Minimap.Hitpoints() > 0.25)) { return(false); //hitpoints are already at 1 or an overload has just worn off and hitpoints are no longer red } Inventory.RightClickInventoryOption(0, 0, 1, false); //guzzle rock cake SafeWaitPlus(1000, 250); return(true); }
public static RectangleSide IsBallIntersecting( float2 ballPosition, RectangleBounds ballBounds, float2 rectPosition, RectangleBounds rectBounds) { var dxy = (ballPosition) - (rectPosition); var widthHeight = ballBounds.HalfWidthHeight + rectBounds.HalfWidthHeight; if (math.all(math.abs(dxy) <= widthHeight)) { var crossWidthHeight = widthHeight * dxy; if (crossWidthHeight.x > crossWidthHeight.y) { return((crossWidthHeight.x > -crossWidthHeight.y) ? RectangleSide.Bottom : RectangleSide.Left); } return((crossWidthHeight.x > -crossWidthHeight.y) ? RectangleSide.Right : RectangleSide.Top); } return(RectangleSide.None); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var scale = transform.localScale; var bounds = new RectangleBounds { HalfWidthHeight = new float2(scale.x / 2.0f, scale.y / 2.0f), }; dstManager.AddComponentData(entity, bounds); dstManager.AddComponent(entity, typeof(PaddleTag)); dstManager.AddComponentData(entity, new MovementSpeed { Speed = MovementSpeed }); dstManager.AddComponentData <Position2D>(entity, new Position2D { Value = new float2(transform.position.x, transform.position.y) }); dstManager.RemoveComponent <Translation>(entity); dstManager.RemoveComponent <Rotation>(entity); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { m_nClickPosX = e.X; m_nClickPosY = e.Y; RectangleBounds nBounds; Rectangle Rect = new Rectangle(0, 0, this.Width, this.Height); if (ScaleHitTestTools.IsPositionInRectangleBounds(Rect, e.X, e.Y, BORDER_WIDTH)) m_nMode = Mode.Move; else if (ScaleHitTestTools.IsPositionOnRectangleBounds(Rect, e.X, e.Y, BORDER_WIDTH, RectangleBounds.Any, out nBounds)) { m_nMode = Mode.Resize; m_nSelectedBounds = nBounds; } base.OnMouseDown(e); }
/// <summary> /// Determines if the first row of chat is another player's message. /// </summary> /// <returns>True if the first row of chat is another's player's text.</returns> private bool OtherPlayer(RectangleBounds chatRow) { //TODO return(true); }
private void HandleDynamicDynamic(uint dID1, uint dID2) { //Need the position for position, the collideable for the bounds type, // and the movement to analyze the amount of pushing that should be done Position pos1 = _game.PositionComponent[dID1]; Position pos2 = _game.PositionComponent[dID2]; Collideable col1 = _game.CollisionComponent[dID1]; Collideable col2 = _game.CollisionComponent[dID2]; Movement mov1 = _game.MovementComponent[dID1]; Movement mov2 = _game.MovementComponent[dID2]; //We'll need different equations for different types of bounds. if (col1.Bounds.GetType() == typeof(CircleBounds) && col2.Bounds.GetType() == typeof(CircleBounds)) { CircleBounds c1 = (CircleBounds)col1.Bounds; CircleBounds c2 = (CircleBounds)col2.Bounds; //Angle from c1 to c2 double angle = Math.Atan2(c2.Center.Y - c1.Center.Y, c2.Center.X - c1.Center.X); double distance = Math.Abs((c2.Center.Y - c1.Center.Y) / Math.Sin(angle)); double ddistance = c1.Radius + c2.Radius - distance; double x = pos1.Center.X - (Math.Cos(angle) * ddistance); double y = pos1.Center.Y - (Math.Sin(angle) * ddistance); pos1.Center = new Vector2((float)x, (float)y); x = pos2.Center.X + (Math.Cos(angle) * ddistance); y = pos2.Center.Y + (Math.Sin(angle) * ddistance); pos2.Center = new Vector2((float)x, (float)y); //Now determine the pushback from the movement /*Vector2 dMove = (mov1.Direction * mov1.Speed + mov2.Direction * mov2.Speed) / 2; * double moveAngle = Math.Atan2(dMove.Y, dMove.X); * * double dAngle = moveAngle - angle; * * double moveDistance = Math.Cos(dAngle) * dMove.Length(); * * dMove.Normalize(); * * pos1.Center += dMove * (float)moveDistance; * pos2.Center += dMove * (float)moveDistance; */ _game.PositionComponent[dID1] = pos1; _game.PositionComponent[dID2] = pos2; c1.Center = pos1.Center; c2.Center = pos2.Center; col1.Bounds = c1; col2.Bounds = c2; _game.CollisionComponent[dID1] = col1; _game.CollisionComponent[dID2] = col2; } if (col1.Bounds.GetType() != col2.Bounds.GetType()) { bool col1IsRect = (col1.Bounds.GetType() == typeof(CircleBounds)); Position rectPos = (col1IsRect ? pos1 : pos2); Collideable rectCol = (col1IsRect ? col1 : col2); Movement rectMov = (col1IsRect ? mov1 : mov2); RectangleBounds rect = (RectangleBounds)rectCol.Bounds; Position circPos = (col1IsRect ? pos2 : pos1); Collideable circCol = (col1IsRect ? col2 : col1); Movement circMov = (col1IsRect ? mov2 : mov1); CircleBounds circ = (CircleBounds)rectCol.Bounds; //Do your thing here throw new NotImplementedException(); } if (col1.Bounds.GetType() == typeof(RectangleBounds) && col2.Bounds.GetType() == typeof(RectangleBounds)) { //Can this happen? throw new NotImplementedException(); } }
private void CreateLightmap(float dist2, Vector3 badPoint, string path, int texIndex, float hemisphereSizeDivisor, TextureMap texMap, ref float maxIntensity) { int gatherCount = 100; int width = (int)(texMap.Width); // * RadiosityHelper.LightmapScale); int height = (int)(texMap.Height); // * RadiosityHelper.LightmapScale); float heightF = (float)texMap.Height; // *RadiosityHelper.LightmapScale; float widthF = (float)texMap.Width; // *RadiosityHelper.LightmapScale; float currentMaxIntensity = float.MinValue; float diffuse = (float)RadiosityHelper.RadiosityDiffuseConstant; widthF -= 1f; heightF -= 1f; SetOperation("Creating texture #" + (texIndex + 1)); //List<CompressedPhoton> photons; Bitmap bitm = new Bitmap(width, height, PixelFormat.Format32bppRgb); RadiosityMaterial mat; Vector3 norm; for (int x = 0; x < width; x++) { for (int y = 0; y < heightF; y++) { bitm.SetPixel(x, y, m_bsp[0].ConvertUVTo3D(x, y, texIndex, 1, out mat, out norm) != Vector3.Empty ? new RealColor(1, 1, 1).ToARGB() : RealColor.Black.ToARGB()); } } bitm.Save("k:\\convmap_" + texIndex + "_" + 1); //CreateLightmapWork(dist2, ref badPoint, texIndex, hemisphereSizeDivisor, texMap, width, height, heightF, widthF, ref currentMaxIntensity); // We are going to cycle through the materials of the bsp. EnhancedMesh[] meshes = m_bsp[0].GetMeshes(texIndex); for (int m = 0; m < meshes.Length; m++) { EnhancedMesh material = meshes[m]; int faceCount = material.Indices.Length; RectangleBounds <float> bounds = new RectangleBounds <float>(material.Vertices[0].u2, material.Vertices[0].v2); // First we're going to figure out a rectangle for this material. for (int v = 0; v < material.Vertices.Length; v++) { bounds.Update(material.Vertices[v].u2, material.Vertices[v].v2); } int x = (int)Math.Floor((widthF * bounds.left)); int startX = x; int endX = (int)Math.Ceiling(widthF * bounds.right); int y = (int)Math.Floor(heightF * bounds.top); int endY = (int)Math.Ceiling(heightF * bounds.bottom); //System.Diagnostics.Debugger.Break(); for (; y <= endY; y++) { x = startX; for (; x <= endX; x++) { RadiosityMaterial illMaterial; Vector3 faceNormal; //if (y == 81) // // if (x == 2) //System.Diagnostics.Debugger.Break(); Vector3 worldPoint = m_bsp[0].ConvertUVTo3D(x, y, texIndex, m, out illMaterial, out faceNormal); //AddDebugRay(worldPoint, faceNormal); if (worldPoint != Vector3.Empty) { AddDebugPoint(worldPoint, RadiosityDebugPointListID.EstimateLocations); var photons = photonMap.RetrieveNearestNeighbors((PhotonVector3)worldPoint, dist2, gatherCount, faceNormal); RealColor estimate = RealColor.Black; if (photons.Count > 0) { for (int p = 0; p < photons.Count; p++) { if (photons.list[p].photonPtr == null) { continue; } float dotP = Vector3.Dot(photons.list[p].photonPtr.Direction, faceNormal); if (dotP < 0) { dotP *= -1; //AddDebugPoint(photons.list[p].photonPtr //AddDebugRay(photons.list[p].photonPtr.position.ToVector3(), photons.list[p].photonPtr.Direction); } estimate.Add(photons.list[p].photonPtr.Power.Copy().Multiply(dotP)); } estimate.Multiply(diffuse); estimate.Multiply(hemisphereSizeDivisor); estimate.Multiply(illMaterial.AmbientLight); //estimate.Multiply(1f / photons.Count); if (RadiosityHelper.DoDistantLights) { if (illMaterial.DistantLightCount > 1) { estimate.LambertianShade(faceNormal, illMaterial.DistantLight2Color, illMaterial.DistantLight2Direction, illMaterial.AmbientLight); estimate.LambertianShade(faceNormal, illMaterial.DistantLight1Color, illMaterial.DistantLight1Direction, illMaterial.AmbientLight); } else if (illMaterial.DistantLightCount > 0) { estimate.LambertianShade(faceNormal, illMaterial.DistantLight1Color, illMaterial.DistantLight1Direction, illMaterial.AmbientLight); } } texMap.SetPixel(x, y, estimate); } else { texMap.SetPixel(x, y, new RealColor(Color.Pink)); } } //else continue; // if there is no normal, the estimate is useless. } } } if (currentMaxIntensity > maxIntensity) { maxIntensity = currentMaxIntensity; } texMap.SaveHDR(path + "lightmap_" + texIndex + ".hdr"); bitm = texMap.Filter(new LinearToneMapper(), false); bitm.Save(path + "lightmap_" + texIndex + ".bmp"); }