//http://dunnbypaul.net/perlin/ Hardware implementation public Noise() { Frequency = 0.5f; Decay = 0.5f; Octaves = 2; m_pntOffset = new EPointF(); //default grayscale colortable: m_aColorTable = new List<Color>(); for (int i = 0; i < 256; i++) m_aColorTable.Add(Color.FromArgb(i,i,i)); m_nNoiseWidth = 100; m_nNoiseHeight = 100; Random rnd = new Random(); m_aNoise = new int[m_nNoiseWidth,m_nNoiseHeight]; for (int x = 0; x<m_nNoiseWidth; x++) { for (int y = 0; y<m_nNoiseHeight; y++) { m_aNoise[x,y] = rnd.Next(255); //m_aNoise[x,y] = (int)(127.5+127.5*Math.Sin((double)x*0.5+(double)y*0.5)); } } }
public void Shoot(int a_nAngle) { float fSpeed = 8; double dAngle = (double)a_nAngle * Math.PI / 180; m_pntVel = new EPointF(-fSpeed * (float)Math.Sin(dAngle), -fSpeed * (float)Math.Cos(dAngle)); }
public void ShowPath() { m_shootingBall = (Ball)m_aComingBalls[0]; EPointF loc = m_shootingBall.Loc; double dAngle = -Math.PI * Angle / 180; float fSpeed = 1000; EPointF pntVel = EPointF.FromLengthAndAngle(fSpeed, (float)dAngle); EPoint pntGridStick = null; EPointF pntBounce; int nMaxTests = 40; //if more bounces than this is calculated, then something has gone wrong as it's outside the system // EH.Put("Start at "+loc.ToString()); while (nMaxTests-- > 0) { if (m_playArea.m_pathCalc.GetFirstStickOrBounce(ref loc, ref pntVel, out pntGridStick, out pntBounce, true) == false) { // EH.Put("Test num:"+nMaxTests.ToString() + " loc"+loc.ToString()); // EH.Put("Bounce:" + loc.ToString()+" vel:"+pntVel.ToString()); // loc = pntBounce.Copy(); } else { // if (m_spTarget!=null) // m_spTarget.Loc = m_playArea.Grid.GetGfxLocFromGridLoc(pntGridStick); break; } } }
public override void Start() { Random rnd = new Random(); this.Interactor.Loc = new EPointF(rnd.Next(100), rnd.Next(100)) + new EPointF(300, 300); this._locOrg = this.Interactor.Loc.Copy(); }
public static EPointF GetClosestPointOnLine(EPointF pLineStartingAtOrigo, EPointF pCheck) { EPointF pHit; if (pLineStartingAtOrigo.X == 0) { pHit = new EPointF(pCheck.X, 0); } else { if (pLineStartingAtOrigo.Y == 0) { pHit = new EPointF(0, pCheck.Y); } else { //equation: y = ax + b //we know a for pDiff line: float a1 = (float)pLineStartingAtOrigo.Y / pLineStartingAtOrigo.X; //and we want a for other line to be perpendicular to a1 float a2 = -1f / a1; //b for line 1 is always 0. For line 2, we have to calculate. //We know that it goes through pMouse: //pMouse.Y = a2*pMouse.X + b2 float b2 = pCheck.Y - a2 * pCheck.X; //a1x + b1 = a2x + b2 -> a1x - a2x = b2 - b1 -> x = (b2-b1)/(a1-a2) (b2 == 0) float x = b2 / (a1 - a2); float y = a1 * x; pHit = new EPointF(x, y); } } //TODO: test if outside line end points return pHit; }
public static float GetDistanceFromLine(EPointF pLine1, EPointF pLine2, EPointF pCheck) { EPointF p = GetClosestPointOnLine(pLine1, pLine2, pCheck); EPointF pDiff = pCheck - p; return(pDiff.Length);// (float)Math.Sqrt(pDiff.X * pDiff.X + pDiff.Y * pDiff.Y); }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (this._changingHue) { EPointF diff = new EPointF(e.X, e.Y) - this.Center; float angle = diff.Angle * 180 / (float)Math.PI; angle += 60; if (angle < 0) { angle += 360; } else if (angle > 360) { angle -= 360; } ColorHsb hsb = this.HSB; hsb.H = angle; this.HSB = hsb; //this.Invalidate(); //this.pictureBox1.Invalidate(); } else if (this._changingSB) { this.SetSBFromLoc(new EPointF(e.X, e.Y)); } this.pictureBox1.Invalidate(); if (this.ColorChanged != null) { this.ColorChanged(this, null); } }
public static Bitmap CreateLineBitmap(ERectangleF rctLine, Color clrBg, Color clrPen, float penWidth, out EPointF locOffset) { //Because GDI+ arrows are so limited Bitmap bmp = null; locOffset = new EPointF(); if (rctLine.Width != 0 && rctLine.Height != 0) { bmp = new Bitmap((int)Math.Abs(rctLine.Width) + 1, (int)Math.Abs(rctLine.Height) + 1, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(clrBg), 0, 0, bmp.Width, bmp.Height); ERectangleF rctOrigo = rctLine.Copy(); rctOrigo.MakeTopLeftAtOrigo(); Pen pen = new Pen(clrPen, penWidth); g.DrawLine(pen, rctOrigo.X, rctOrigo.Y, rctOrigo.X + rctOrigo.Width, rctOrigo.Y + rctOrigo.Height); g.Dispose(); if (rctOrigo.Width < 0) { locOffset.X = rctOrigo.Width; } if (rctOrigo.Height < 0) { locOffset.Y = rctOrigo.Height; } } return(bmp); }
public static Bitmap CreateLineBitmap(ERectangleF rctLine, Color clrBg, Color clrPen, float penWidth, out EPointF locOffset) { //Because GDI+ arrows are so limited Bitmap bmp = null; locOffset = new EPointF(); if (rctLine.Width != 0 && rctLine.Height != 0) { bmp = new Bitmap((int)Math.Abs(rctLine.Width)+1, (int)Math.Abs(rctLine.Height)+1, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(clrBg), 0,0,bmp.Width,bmp.Height); ERectangleF rctOrigo = rctLine.Copy(); rctOrigo.MakeTopLeftAtOrigo(); Pen pen = new Pen(clrPen, penWidth); g.DrawLine(pen, rctOrigo.X, rctOrigo.Y, rctOrigo.X+rctOrigo.Width, rctOrigo.Y+rctOrigo.Height); g.Dispose(); if (rctOrigo.Width < 0) locOffset.X = rctOrigo.Width; if (rctOrigo.Height < 0) locOffset.Y = rctOrigo.Height; } return bmp; }
public TestCircle() { m_pntVel = new EPointF(0, 0); m_pntThrust = new EPoint(0, 0); aKeysPressedX = new ArrayList(); aKeysPressedY = new ArrayList(); Bitmap bmp = new Bitmap(40, 40, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.FillEllipse(new SolidBrush(Color.Red), 0, 0, 40, 40); g.Dispose(); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); mb.CenterRegPoint(); Member = mb; m_aLines = new ArrayList(); for (int i = 0; i < 1; i++) { TestLine line = new TestLine(m_endogine); line.SetLine(new EPointF((i) * 150, 0), new EPointF((i + 1) * 150, 150)); m_aLines.Add(line); } LocZ = 10; Loc = new EPointF(171, 171); m_endogine.KeyEvent += new KeyEventHandler(m_endogine_KeyEvent); }
public static bool CalcFirstCircleCircleCollisions(EPointF loc1, EPointF loc2, EPointF vel1, EPointF vel2, float r1, float r2, out EPointF collLoc, out float fTime) { collLoc = new EPointF(0, 0); fTime = -1; ArrayList aLocs; ArrayList aTimes; if (CalcCircleCircleCollisions(loc1, loc2, vel1, vel2, r1, r2, out aLocs, out aTimes)) { fTime = (float)aTimes[0]; collLoc = (EPointF)aLocs[0]; if (fTime > 1) { return(false); } if (fTime < 0) { fTime = (float)aTimes[1]; collLoc = (EPointF)aLocs[1]; if (fTime < 0 || fTime > 1) { return(false); } } // else // { // CalcCircleCircleCollisions(loc1, loc2, vel1, vel2, r1, r2, out aLocs, out aTimes); // } CalcCircleCircleCollisions(loc1, loc2, vel1, vel2, r1, r2, out aLocs, out aTimes); return(true); } return(false); }
private Bitmap CreateBitmap() { //creates a 24-bit topology bitmap int radius = (int)this.fMaxRange; Bitmap bmpQuarter = new Bitmap(radius, radius, System.Drawing.Imaging.PixelFormat.Format24bppRgb); //Render 1/4 of the circle and copy/paste the others for (int y = 0; y < radius; y++) { for (int x = 0; x < radius; x++) { EPointF pnt = new EPointF(radius - x, radius - y); float altitude = this.GetAltitudeOnDistance(pnt.Length); float fMaxAltitude = 20; int nClr = 8388608 + (int)(altitude / fMaxAltitude * 8388608); Color clr = Color.FromArgb(nClr); bmpQuarter.SetPixel(x, y, clr); } } Bitmap bmp = Endogine.BitmapHelpers.Filters.FoldOut(bmpQuarter, (float)Math.PI * 2, 3); return(bmp); }
public override void EnterFrame() { float f = (float)Math.Sin((double)this.FramesAlive * 0.5f); float factor = 1f - (float)this.FramesAlive / 70; EPointF ptNew = new EPointF(0, this._intensity * f * factor * 20); if (this._ptOffset == null) { this._ptOffset = ptNew; } EPointF ptDiff = ptNew - this._ptOffset; this._ptOffset = ptNew; this.Parent.Loc += ptDiff; //this.Parent.Rotation = f*(float)Math.PI*intensity; //EH.Put(this.Rotation.ToString()); base.EnterFrame(); if (factor <= 0) { //this.Parent.Rotation = 0; this.Dispose(); } }
protected override void OnMouse(MouseEventArgs e, MouseEventType t) { if (t == MouseEventType.Down) { this.Color = Color.FromArgb(this.Color.R, this.Color.G, 0); } else if (t == MouseEventType.Up || t == MouseEventType.UpOutside || t == MouseEventType.Click) { this.Color = Color.FromArgb(this.Color.R, this.Color.G, 255); } else if (t == MouseEventType.Enter) { this.Color = Color.FromArgb(0, this.Color.G, this.Color.B); } else if (t == MouseEventType.Leave) { this.Color = Color.FromArgb(255, this.Color.G, this.Color.B); } else if (t == MouseEventType.StillDown) { Scaling = new EPointF(1.0f + 0.005f * e.X, 1); Loc = new EPointF(e.X, e.Y); Blend = (int)(100 * e.X * 1.0 / 100); } }
public void Fall() { m_nFallCount = 1; Random rnd = new Random(GridLoc.X * 100 + GridLoc.Y); m_pntVel = new EPointF((float)(rnd.NextDouble() * 6 - 3), (float)(-rnd.NextDouble() * 5 - 2)); }
public override System.Collections.ArrayList GeneratePoints(EPoint ptStart) { //Calculate curve's control and end anchor points: //Control point is the start point + offset to control EPoint ptControl = ptStart + this._ptControl; //End point is control point + offset to anchor: EPoint ptAnchor = ptControl + this._ptAnchor; //now calculate two bezier handles for the curve (Flash uses quadratic beziers, GDI+ uses cubic). //The two handles are 2/3rds from each endpoint to the control point. EPointF diff = (ptControl - ptStart).ToEPointF(); EPointF ctrl1 = EPointF.FromLengthAndAngle(diff.Length * 2 / 3, diff.Angle) + ptStart.ToEPointF(); //EPointF ctrl1 = ptStart.ToEPointF() + diff/2f; //EPointF ctrl1 = new EPointF(ptStart.X + (1f * (ptControl.X - ptStart.X) / 2f), ptStart.Y + (1f * (ptControl.Y - ptStart.Y) / 2f)); diff = (ptControl - ptAnchor).ToEPointF(); EPointF ctrl2 = EPointF.FromLengthAndAngle(diff.Length * 2 / 3, diff.Angle) + ptAnchor.ToEPointF(); //diff = (ptAnchor-ptControl).ToEPointF(); //EPointF ctrl2 = ptControl.ToEPointF() + diff/2f; //ctrl2 = new EPointF(ptControl.X + (1f * (ptAnchor.X - ptControl.X) / 2f), ptControl.Y + (1f * (ptAnchor.Y - ptControl.Y) / 2f)); System.Collections.ArrayList pts = new System.Collections.ArrayList(); pts.Add(ptStart.ToEPointF()); pts.Add(ctrl1); pts.Add(ctrl2); pts.Add(ptAnchor.ToEPointF()); return(pts); }
//http://dunnbypaul.net/perlin/ Hardware implementation public Noise() { Frequency = 0.5f; Decay = 0.5f; Octaves = 2; m_pntOffset = new EPointF(); //default grayscale colortable: m_aColorTable = new List <Color>(); for (int i = 0; i < 256; i++) { m_aColorTable.Add(Color.FromArgb(i, i, i)); } m_nNoiseWidth = 100; m_nNoiseHeight = 100; Random rnd = new Random(); m_aNoise = new int[m_nNoiseWidth, m_nNoiseHeight]; for (int x = 0; x < m_nNoiseWidth; x++) { for (int y = 0; y < m_nNoiseHeight; y++) { m_aNoise[x, y] = rnd.Next(255); //m_aNoise[x,y] = (int)(127.5+127.5*Math.Sin((double)x*0.5+(double)y*0.5)); } } }
public static EPointF GetClosestPointOnLine(EPointF pLine1, EPointF pLine2, EPointF pCheck) { EPointF pDiff = pLine2 - pLine1; pCheck = pCheck - pLine1; EPointF p = GetClosestPointOnLine(pDiff, pCheck); return p + pLine1; }
protected EPointF GetWhereOnSides(float fPhase, ERectangleF rct) { float fCircum = rct.Width*2 + rct.Height*2; EPointF pnt = new EPointF(); if (fPhase < rct.Width/fCircum) { pnt.X = rct.X+fPhase*fCircum; pnt.Y = rct.Y; } else { fPhase-= rct.Width/fCircum; if (fPhase < rct.Height/fCircum) { pnt.X = rct.Right; pnt.Y = rct.Y+fPhase*fCircum; } else { fPhase-= rct.Height/fCircum; if (fPhase < rct.Width/fCircum) { pnt.Y = rct.Bottom; pnt.X = rct.Right-fPhase*fCircum; } else { fPhase-= rct.Width/fCircum; pnt.X = rct.X; pnt.Y = rct.Bottom-fPhase*fCircum; } } } return pnt; }
public override void EnterFrame() { base.EnterFrame(); EPointF loc = this.ConvParentLocToRootLoc(Loc); m_rctWrap.WrapPointInside(loc); Loc = this.ConvRootLocToParentLoc(loc); }
public static float CalcMovingLineLineCollision(ERectangleF lineRect1, ERectangleF lineRect2, EPointF vel1, EPointF vel2, out EPointF pntCollision) { //TODO: will work like this: //Check line/line collision from each of the line's endpoints to endpoints+vel against the other line. //Do this for both lines, as a collision maybe missed or misinterpreted pntCollision = new EPointF(); return(0f); }
private void m_frame_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, MouseEventType t) { if (t == Sprite.MouseEventType.StillDown) { EPointF pntDiff = new EPointF(e.X - m_frame.MouseLastLoc.X, e.Y - m_frame.MouseLastLoc.Y); this.Parent.Move(pntDiff); } }
private EPointF GetLocFromSB() { ColorHsb hsb = this.HSB; EPointF pnt = this._quad.MapFromRect(new EPointF(hsb.S, 1f - hsb.B), new ERectangleF(0, 0, 1, 1)); return(pnt + this._offset); }
public static bool CalcCircleLineCollision(EPointF circleLoc, float radius, EPointF circleMovement, ERectangleF lineRect, out EPointF pntFirstCollision, out EPointF circleLocAtCollision) { //first calc two lines parallel with line, at radius distance from it double dAngleLine = Math.Atan2((double)lineRect.Width, -(double)lineRect.Height); double dAnglePerp = dAngleLine+Math.PI/2; EPointF pntOffset = new EPointF(radius*(float)Math.Sin(dAnglePerp), -radius*(float)Math.Cos(dAnglePerp)); ERectangleF lineRect1 = lineRect; ERectangleF circleMovementLine = new ERectangleF(circleLoc, new EPointF(circleMovement.X, circleMovement.Y)); float fTimeFirstCollision = 1000; pntFirstCollision = new EPointF(0,0); circleLocAtCollision = new EPointF(0,0); for (int i = -1; i < 2; i+=2) { ERectangleF lineRectParallel = lineRect.Copy(); lineRectParallel.Offset(pntOffset.X*i, pntOffset.Y*i); EPointF pntCollision; if (CalcLineLineCollision(circleMovementLine, lineRectParallel, out pntCollision)) { EPointF pntDiff = new EPointF(pntCollision.X-circleMovementLine.X, pntCollision.Y-circleMovementLine.Y); //circleMovementLine.Left, pntCollision.Y-circleMovementLine.Top float fTimeCollision = Endogine.Collision.PointLine.PointIsWhereOnLine(pntDiff, circleMovementLine); if (fTimeCollision < fTimeFirstCollision) { fTimeFirstCollision = fTimeCollision; pntFirstCollision = new EPointF(pntCollision.X-pntOffset.X*i, pntCollision.Y-pntOffset.Y*i); circleLocAtCollision = pntCollision; } } } //also calc circle/circle collision (for line end points) ArrayList aLocs, aTimes; EPointF pntLinePointToTest = lineRect.Location; for (int i = 0; i < 2; i++) { if (CalcCircleCircleCollisions(circleLoc, pntLinePointToTest, circleMovement, new EPointF(0,0), radius, 0, out aLocs, out aTimes)) { EPointF pntCollision = (EPointF)aLocs[0]; float fTimeCollision = (float)aTimes[0]; if (fTimeCollision < 0) { fTimeCollision = (float)aTimes[1]; if (fTimeCollision < 0 || fTimeCollision > 1) continue; pntCollision = (EPointF)aLocs[1]; } if (fTimeCollision < fTimeFirstCollision) { fTimeFirstCollision = fTimeCollision; pntFirstCollision = pntLinePointToTest; circleLocAtCollision = new EPointF(circleLoc.X+circleMovement.X*fTimeCollision, circleLoc.Y+circleMovement.Y*fTimeCollision); } } pntLinePointToTest = new EPointF(lineRect.X+lineRect.Width, lineRect.Y+lineRect.Height); //lineRect.Left+lineRect.Width, lineRect.Top } if (fTimeFirstCollision <= 1) return true; return false; }
private MeterBar Create1DMeter(EPointF ptLoc, string prop, float max) { MeterBar bar = new MeterBar(); bar.Rect = new ERectangleF(ptLoc.X, ptLoc.Y, 100, 8); bar.MaxValue = max; bar.SetAutoFetch(this._car, prop); return(bar); }
public static EPointF GetClosestPointOnLine(EPointF pLine1, EPointF pLine2, EPointF pCheck) { EPointF pDiff = pLine2 - pLine1; pCheck = pCheck - pLine1; EPointF p = GetClosestPointOnLine(pDiff, pCheck); return(p + pLine1); }
public float CheckCollisionsWithBallFromTime(Ball a_ball, float a_fTime, ref PropsAtCollision[] propsAtCollisionList) { propsAtCollisionList[0].Ball = this; propsAtCollisionList[1].Ball = a_ball; float fCollisionTime; EPointF pntCircleAtCollisionLoc; EPointF pntTouchLoc; EPointF locThis = this.Loc + this.Velocity*a_fTime; EPointF velThis = this.Velocity*(1.0f-a_fTime); EPointF locOther = a_ball.Loc + a_ball.Velocity*a_fTime; EPointF velOther = a_ball.Velocity*(1.0f-a_fTime); if (Endogine.Collision.Collision.CalcFirstCircleCircleCollisions(locThis, locOther, velThis, velOther, this.Radius, a_ball.Radius, out pntCircleAtCollisionLoc, out fCollisionTime)) { propsAtCollisionList[0].Loc = locThis+velThis*fCollisionTime; propsAtCollisionList[1].Loc = locOther + velOther*fCollisionTime; propsAtCollisionList[0].Velocity = this.Velocity.Copy(); propsAtCollisionList[1].Velocity = a_ball.Velocity.Copy(); EPointF relativeVel = this.Velocity-a_ball.Velocity; EPointF pntTmp = EPointF.FromLengthAndAngle(this.Radius, (propsAtCollisionList[1].Loc-propsAtCollisionList[0].Loc).Angle); pntTouchLoc = propsAtCollisionList[0].Loc+pntTmp; EPointF debugLoc = propsAtCollisionList[1].Loc-propsAtCollisionList[0].Loc; //the amount of energy transferred to the other depends on the collision angle vs the C:\Documents and Settings\Jonas\Mina dokument\Visual Studio Projects\EndoTest01\Endogine\Sprite.csrelative velocity's angle float velAngle = relativeVel.Angle; EPointF pntX = propsAtCollisionList[0].Loc - pntTouchLoc; float angleOrientation = Endogine.Collision.Collision.GetOrientationAngle(pntX.Angle - velAngle); //if "wall" is same angle as relative move angle: no energy transferred. //if "wall" is 90 degrees off, all energy is transferred. float fTransferredEnergyFactor = Math.Abs((float)((angleOrientation-Math.PI/2)/(Math.PI/2))); //float fTransferredEnergyFactor = (float)(Math.Cos(angleOrientation*2)); EPointF pntDiff = propsAtCollisionList[1].Loc - pntTouchLoc; EPointF pntAddedVel = EPointF.FromLengthAndAngle(relativeVel.Length*fTransferredEnergyFactor, pntDiff.Angle); propsAtCollisionList[1].Velocity+=pntAddedVel; //total energy and angle must be the same, so adjust the other's velocity (must be an thought error somewhere?) propsAtCollisionList[0].Velocity = (this.Velocity+a_ball.Velocity) - propsAtCollisionList[1].Velocity; // propsAtCollisionList[0].Velocity = EPointF.FromLengthAndAngle( // (this.Velocity+a_ball.Velocity).Length - propsAtCollisionList[1].Velocity.Length, // (this.Velocity+a_ball.Velocity).Angle - propsAtCollisionList[1].Velocity.Angle); propsAtCollisionList[0].Velocity.Length = this.Velocity.Length+a_ball.Velocity.Length - propsAtCollisionList[1].Velocity.Length; return fCollisionTime * (1.0f-a_fTime) + a_fTime; } else return -1; }
public static float PointIsWhereOnLine(EPointF pnt, ERectangleF rct) { //NormalizeRect(ref rct); if (rct.Width != 0) return pnt.X / rct.Width; if (rct.Height != 0) return pnt.Y / rct.Height; return -1000; }
public override void EnterFrame() { base.EnterFrame(); ERectangleF rct = new ERectangleF(0, 0, 640, 480); EPointF loc = this.ConvParentLocToRootLoc(Loc); rct.WrapPointInside(loc); Loc = this.ConvRootLocToParentLoc(loc); }
public ReferencePoint(BinaryPSDReader reader) : base(reader) { BinaryPSDReader r = this.GetDataReader(); this.Point = new EPointF(); this.Point.X = (float)r.ReadPSDDouble(); this.Point.Y = (float)r.ReadPSDDouble(); this.Data = null; }
public bool CheckCollision(Sprite sp) { EPointF pntHit = this.GetCollisionPoint(sp); if (pntHit != null) { //TODO: per-pixel collision detection. Make part of cover disappear. return(true); } return(false); }
private void UpdateColorAndSize() { float l=(float)LifeCounter/(float)LifeMax; Color = m_psys.ColorInterpolator.GetValueAtTime(l); float fSize = (float)m_psys.SizeInterpolator.GetValueAtTime(l); fSize*=m_fSizeFact; Scaling = new EPointF(fSize,fSize); //Blend = (int)((((float)clr0.A)*(1f-l)+((float)clr1.A)*l)); }
/// <summary> /// Stretching sprite /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="t"></param> private void spSquare_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.StillDown) { EPoint pntWhichSquare = (EPoint)sender.Tag; EPointF pntDiff = new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); EPointF pntRestrictTo = new EPointF(); if (pntWhichSquare.Y == 1) { pntRestrictTo.X = 1; } else if (pntWhichSquare.X == 1) { pntRestrictTo.Y = 1; } else { pntRestrictTo = new EPointF(1, 1); } EPointF pntMove = pntDiff * pntRestrictTo; ERectangleF rct = this.m_sp.Rect.Copy(); if (pntWhichSquare.X == 0 || pntWhichSquare.Y == 0) { if (pntWhichSquare.X == 0 && pntWhichSquare.Y == 2) { rct.X += pntMove.X; rct.Width -= pntMove.X; rct.Height += pntMove.Y; } else if (pntWhichSquare.X == 2 && pntWhichSquare.Y == 0) { rct.Y += pntMove.Y; rct.Height -= pntMove.Y; rct.Width += pntMove.X; } else { rct.Location += pntMove; rct.Size -= pntMove; } } else { rct.Size += pntMove; } this.m_sp.Rect = rct; this.Update(); } }
private void UpdateColorAndSize() { float l = (float)LifeCounter / (float)LifeMax; Color = m_psys.ColorInterpolator.GetValueAtTime(l); float fSize = (float)m_psys.SizeInterpolator.GetValueAtTime(l); fSize *= m_fSizeFact; Scaling = new EPointF(fSize, fSize); //Blend = (int)((((float)clr0.A)*(1f-l)+((float)clr1.A)*l)); }
private void sp_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.Down) { } else if (t == Endogine.Sprite.MouseEventType.StillDown) { EPoint pntAxis = (EPoint)sender.Tag; EPointF pntDiff = new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); this.m_sp.Move(pntDiff * pntAxis); } }
public static bool CalcCircleCircleCollisions(EPointF loc1, EPointF loc2, EPointF vel1, EPointF vel2, float r1, float r2, out ArrayList aLocs, out ArrayList aTimes) { aLocs = new ArrayList(); aTimes = new ArrayList(); EPointF loc = loc2 - loc1; //new EPointF(loc2.X-loc1.X, loc2.Y-loc1.Y); EPointF vel = vel2 - vel1; //new EPointF(vel2.X-vel1.X, vel2.Y-vel1.Y); if (vel.X == 0 && vel.Y == 0) { return(false); } //(velx*velx + vely*vely)X^2 + 2*(locx*velx + locy*vely)*X + locx*locx + locy*locy - (r1 + r2)(r1 + r2) = 0 float r = r1 + r2; EPointF locPwr2 = new EPointF(loc.X * loc.X, loc.Y * loc.Y); EPointF velPwr2 = new EPointF(vel.X * vel.X, vel.Y * vel.Y); float a = 2f * (loc.X * vel.X + loc.Y * vel.Y); float b = locPwr2.X + locPwr2.Y - r * r; float divide = velPwr2.X + velPwr2.Y; a /= divide; b /= divide; float roots = a * a / 4 - b; if (roots < 0) { return(false); } roots = (float)Math.Sqrt(roots); float mid = -a / 2; EPointF pntHit; float fTime; fTime = mid - roots; for (int n = 0; n < 2; n++) { pntHit = loc1 + vel1 * fTime; // -?? aLocs.Add(pntHit); aTimes.Add(fTime); fTime = mid + roots; } return(true); }
public override void EnterFrame() { if (m_keysSteering.GetKeyActive("left")) { Rotation -= m_fAngleStep; } else if (m_keysSteering.GetKeyActive("right")) { Rotation += m_fAngleStep; } float fThrust = 0; if (m_keysSteering.GetKeyActive("up")) { m_particleSystem.NumNewParticlesPerFrame = m_fThrustParticles; fThrust = m_fThrustPower; } else if (m_keysSteering.GetKeyActive("down")) { fThrust = -m_fThrustPower; } if (fThrust <= 0) { m_particleSystem.NumNewParticlesPerFrame = 0; } float fRot = Rotation; Velocity += new EPointF((float)Math.Sin(fRot), (float)-Math.Cos(fRot)) * fThrust; base.EnterFrame(); //TODO: should be able to just set the particleSystem's parent to the player, but inherited rotation isn't implemented yet. m_particleSystem.Loc = Loc; m_particleSystem.Rotation = Rotation + (float)Math.PI; m_particleSystem.AddedVelocity = Velocity; m_endogine.Stage.Camera.CenterLoc = this.Loc; //collision detection with asteroids: foreach (Asteroid sp in m_gameMain.Asteroids) { if (sp.Rect.IntersectsWith(this.Rect)) { //TODO: lose a life! sp.Hit(); break; } } }
public static bool PointsOnSameSideOfLine(EPointF p1, EPointF p2, EPointF lineEnd1, EPointF lineEnd2) { Vector3 v1 = new Vector3(p1.X, p1.Y, 0); Vector3 v2 = new Vector3(p2.X, p2.Y, 0); Vector3 vLine1 = new Vector3(lineEnd1.X, lineEnd1.Y, 0); Vector3 vLine2 = new Vector3(lineEnd2.X, lineEnd2.Y, 0); Vector3 cp1 = Vector3.Cross(vLine2 - vLine1, v1 - vLine1); Vector3 cp2 = Vector3.Cross(vLine2 - vLine1, v2 - vLine1); return (cp1.Dot(cp2) >= 0); }
public static bool PointsOnSameSideOfLine(EPointF p1, EPointF p2, EPointF lineEnd1, EPointF lineEnd2) { Vector3 v1 = new Vector3(p1.X, p1.Y, 0); Vector3 v2 = new Vector3(p2.X, p2.Y, 0); Vector3 vLine1 = new Vector3(lineEnd1.X, lineEnd1.Y, 0); Vector3 vLine2 = new Vector3(lineEnd2.X, lineEnd2.Y, 0); Vector3 cp1 = Vector3.Cross(vLine2 - vLine1, v1 - vLine1); Vector3 cp2 = Vector3.Cross(vLine2 - vLine1, v2 - vLine1); return(cp1.Dot(cp2) >= 0); }
protected override void OnMouse(System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t==Endogine.Sprite.MouseEventType.StillDown) { EPointF pntDiff = new EPointF(e.X-MouseLastLoc.X, e.Y-MouseLastLoc.Y); Move(pntDiff); //if (!GetConstrainRect().Contains(new Point((int)Loc.X,(int)Loc.Y))) //{ // Move(new PointF(-pntDiff.X,-pntDiff.Y)); //} } base.OnMouse (e, t); }
public static bool CalcCircleCircleCollisions(EPointF loc1, EPointF loc2, EPointF vel1, EPointF vel2, float r1, float r2, out ArrayList aLocs, out ArrayList aTimes) { aLocs = new ArrayList(); aTimes = new ArrayList(); EPointF loc = loc2-loc1; //new EPointF(loc2.X-loc1.X, loc2.Y-loc1.Y); EPointF vel = vel2-vel1; //new EPointF(vel2.X-vel1.X, vel2.Y-vel1.Y); if (vel.X == 0 && vel.Y == 0) return false; //(velx*velx + vely*vely)X^2 + 2*(locx*velx + locy*vely)*X + locx*locx + locy*locy - (r1 + r2)(r1 + r2) = 0 float r = r1 + r2; EPointF locPwr2 = new EPointF(loc.X*loc.X, loc.Y*loc.Y); EPointF velPwr2 = new EPointF(vel.X*vel.X, vel.Y*vel.Y); float a = 2f*(loc.X*vel.X + loc.Y*vel.Y); float b = locPwr2.X + locPwr2.Y - r*r; float divide = velPwr2.X + velPwr2.Y; a/=divide; b/=divide; float roots = a*a/4 - b; if (roots < 0) return false; roots = (float)Math.Sqrt(roots); float mid = -a/2; EPointF pntHit; float fTime; fTime = mid-roots; for (int n = 0; n < 2; n++) { pntHit = loc1+vel1*fTime; // -?? aLocs.Add(pntHit); aTimes.Add(fTime); fTime = mid+roots; } return true; }
public ParticleEmitter() { m_bMeInvisibleButNotChildren = true; Name = "ParticleEmitter"; m_endogine = EndogineHub.Instance; particlelist=new ArrayList(); this.Ink = RasterOps.ROPs.AddPin; SortedList aColors = new SortedList(); aColors.Add(0.0, Color.FromArgb(255,255,255)); aColors.Add(1.0, Color.FromArgb(0,0,0)); m_interpolator = new InterpolatorColor(aColors); SortedList aSize = new SortedList(); aSize.Add(0.0, 1.0); aSize.Add(1.0, 0.0); m_interpolatorSize = new Interpolator(); m_interpolatorSize.KeyFramesList = aSize; m_particleSizeFact = 1; m_particleSizeFactRange = 0.5f; chaos=0f; m_fNewParticlesPerFrame = 1; m_nMaxNumParticles = 200; rotationrange=90f; m_pntAddedVelocity = new EPointF(); life = 50; liferange = 20; sprayangle = 0f; sprayanglerange = 0.0f; speed = 3f; speedrange = 0.5f; gravity = 0.3f; gravityangle = 0f; wind = 0f; windangle = 0f; }
public override void SubDraw() { ERectangleF rctDraw = m_sp.CalcRectInDrawTarget(); // Matrix QuadMatrix = Matrix.Scaling(rctDraw.Width, rctDraw.Height, 1); EPointF pntRegOff = m_sp.RegPoint.ToEPointF()/new EPointF(m_sp.SourceRect.Width, m_sp.SourceRect.Height) * new EPointF(rctDraw.Width, rctDraw.Height); // QuadMatrix.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y,0)); // QuadMatrix.Multiply(Matrix.RotationZ(-m_sp.Rotation)); // QuadMatrix.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y,0)); EPoint renderControlSize = new EPoint(800,600); EPointF pntLoc = new EPointF(rctDraw.X-renderControlSize.X/2, rctDraw.Y-renderControlSize.Y/2); //QuadMatrix.Multiply(Matrix.Translation(pntLoc.X, -pntLoc.Y, 0f)); int tx = ((MemberSpriteBitmapRenderStrategyA)this.m_sp.Member.RenderStrategy).TextureId; Gl.glBindTexture(Gl.GL_TEXTURE_2D, tx); //Gl.glRotatef(m_sp.Rotation, 0, 0, 1); Gl.glBegin(Gl.GL_QUADS); if (false) { Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-1, -1, 1); Gl.glTexCoord2f(1, 0); Gl.glVertex3f(1, -1, 1); Gl.glTexCoord2f(1, 1); Gl.glVertex3f(1, 1, 1); Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-1, 1, 1); } rctDraw = rctDraw*0.01f; rctDraw.Offset(-1f,-1f); // rctDraw.Y = 1f-rctDraw.Y; Gl.glTexCoord2f(0, 0); Gl.glVertex3f(rctDraw.Left, rctDraw.Top, 1); Gl.glTexCoord2f(1, 0); Gl.glVertex3f(rctDraw.Right, rctDraw.Top, 1); Gl.glTexCoord2f(1, 1); Gl.glVertex3f(rctDraw.Right, rctDraw.Bottom, 1); Gl.glTexCoord2f(0, 1); Gl.glVertex3f(rctDraw.Left, rctDraw.Bottom, 1); Gl.glEnd(); }
public ReferencePoint(EPointF point) { Point = point; }
private ERectangleF[,] CreateRectanglesFromCuttingRect(ERectangleF rct, EPointF fullSize) { ERectangleF[,] rects = new ERectangleF[3,3]; float left = 0; float right = 0; for (int x=0; x<3; x++) { if (x==0) right = rct.Left; else if (x==1) right = rct.Right; else right = fullSize.X; float top = 0; float bottom = 0; for (int y=0; y<3; y++) { if (y==0) bottom = rct.Top; else if (y==1) bottom = rct.Bottom; else bottom = fullSize.Y; //if (!(bottom-top == 0 || right-left == 0)) //right-left: could be optimized outside this loop rects[x,y] = ERectangleF.FromLTRB(left,top,right,bottom); top = bottom; } left = right; } return rects; }
public PathInfo(ImageResource imgRes) : base(imgRes) { BinaryPSDReader reader = imgRes.GetDataReader(); this.PathNum = this.ID - 2000; this.ID = 2000; ushort numKnots = 0; int cnt = 0; this.Commands = new List<object>(); while (reader.BytesToEnd > 0) { RecordType rtype = (RecordType)(int)reader.ReadUInt16(); //Should always start with PathFill (0) if (cnt == 0 && rtype != RecordType.PathFill) throw new Exception("PathInfo start error!"); switch (rtype) { case RecordType.InitialFill: reader.BaseStream.Position += 1; bool allPixelStart = reader.ReadBoolean(); reader.BaseStream.Position += 22; break; case RecordType.PathFill: if (cnt != 0) throw new Exception("Path fill?!?"); reader.BaseStream.Position += 24; break; case RecordType.Clipboard: ERectangleF rct = new ERectangleF(); rct.Top = reader.ReadPSDSingle(); rct.Left = reader.ReadPSDSingle(); rct.Bottom = reader.ReadPSDSingle(); rct.Right = reader.ReadPSDSingle(); Clipboard clp = new Clipboard(); clp.Rectangle = rct; clp.Scale = reader.ReadPSDSingle(); reader.BaseStream.Position += 4; this.Commands.Add(clp); break; case RecordType.ClosedPathLength: case RecordType.OpenPathLength: numKnots = reader.ReadUInt16(); reader.BaseStream.Position += 22; NewPath np = new NewPath(); np.Open = (rtype == RecordType.OpenPathLength); this.Commands.Add(np); break; case RecordType.ClosedPathBezierKnotLinked: case RecordType.ClosedPathBezierKnotUnlinked: case RecordType.OpenPathBezierKnotLinked: case RecordType.OpenPathBezierKnotUnlinked: BezierKnot bz = new BezierKnot(); EPointF[] pts = new EPointF[3]; for (int i = 0; i < 3; i++) { float y = reader.ReadPSDFixedSingle(); //y comes first... pts[i] = new EPointF(reader.ReadPSDFixedSingle(), y) / 256; } bz.Control1 = pts[0]; bz.Anchor = pts[1]; bz.Control2 = pts[2]; bz.Linked = (rtype == RecordType.ClosedPathBezierKnotLinked || rtype == RecordType.OpenPathBezierKnotLinked); //bz.Open = (rtype == RecordType.OpenPathBezierKnotLinked || rtype == RecordType.OpenPathBezierKnotUnlinked); this.Commands.Add(bz); numKnots--; break; } cnt++; } reader.Close(); }
public List<EPointF> GenerateLocList(string text, int maxWidth, float kerningStrength, float lineSpacingFactor) { List<EPointF> locs = new List<EPointF>(); //TODO: only works for certain charsets!! int bottomOfG = this['g'].SourceRectangle.Height-this['g'].Offset.Y; int topOfAuml = -this['Å'].Offset.Y; int lineHeight = bottomOfG-topOfAuml; lineHeight=(int)(lineSpacingFactor*lineHeight); float extraSpace = 0; EPointF loc = new EPointF(0,0); for (int i=0; i<text.Length;i++) { PicRef p = this[text[i]]; if (p == null) { loc.X += 0.2f * lineHeight; //TODO: define space width! locs.Add(loc.Copy()); loc.X += extraSpace; } else { int kern = 0; if (i > 0) kern = this.GetKerningBetween(text[i - 1], text[i]); loc.X -= kerningStrength * kern; locs.Add(loc.Copy()); loc.X += (int)p.SourceRectangle.Width + extraSpace; } if (loc.X > maxWidth) { //TODO: go back to last whitespace or hypen and break there loc.Y+=lineHeight; loc.X = 0; } } return locs; }
public static bool PointInTriangle(EPointF point, EPointF p1, EPointF p2, EPointF p3) { return (PointsOnSameSideOfLine(point, p1, p2, p3) && PointsOnSameSideOfLine(point, p2, p1, p3) && PointsOnSameSideOfLine(point, p3, p1, p2)); }
public static float GetDistanceFromLine(EPointF pLine1, EPointF pLine2, EPointF pCheck) { EPointF p = GetClosestPointOnLine(pLine1, pLine2, pCheck); EPointF pDiff = pCheck - p; return pDiff.Length;// (float)Math.Sqrt(pDiff.X * pDiff.X + pDiff.Y * pDiff.Y); }
public Matrix CreateMatrix(ERectangleF rctDrawTarget, float rotation, EPoint regPoint, EPoint sourceRectSize) { System.Drawing.Rectangle rctView = this._device.ScissorRectangle; //this._device.Viewport Matrix m = Matrix.Scaling(rctDrawTarget.Width, rctDrawTarget.Height, 1); EPointF pntRegOff = regPoint.ToEPointF() / new EPointF(sourceRectSize.X, sourceRectSize.Y) * new EPointF(rctDrawTarget.Width, rctDrawTarget.Height); m.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y, 0)); m.Multiply(Matrix.RotationZ(-rotation)); m.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y, 0)); EPointF pntLoc = new EPointF(rctDrawTarget.X - rctView.Width / 2, rctDrawTarget.Y - rctView.Height / 2); m.Multiply(Matrix.Translation(pntLoc.X, -pntLoc.Y, 0f)); m.M43 = 9000f; return m; }
public AnimationKey(float fTime, float fValue) { m_pntKey = new EPointF(fTime, fValue); m_pntAnchorBefore = new EPointF(); m_pntAnchorAfter = new EPointF(); }
public static Bitmap RenderToBitmap(int nTwipSize, ArrayList commandList, ArrayList fillStyles, ArrayList lineStyles, out EPoint ptOffset) { EPoint pntCurrentLoc = new EPoint(); ArrayList pathInfos = new ArrayList(); PathInfo pathInfoCurrent = new PathInfo(); pathInfos.Add(pathInfoCurrent); bool hasDrawnSinceLastStyleChange = false; EPointF ptScale = new EPointF(1,1)/nTwipSize; string sDebug = ""; foreach (ShapeCommand.Base cmd in commandList) { if (cmd.MovesTurtle) { if (cmd.Draws) { ((ShapeCommand.Draw)cmd).AddToPath(pathInfoCurrent.Path, pntCurrentLoc, ptScale.X); if (Shape.Debug) { ArrayList pts = ((ShapeCommand.Draw)cmd).GeneratePoints(pntCurrentLoc); if (cmd is ShapeCommand.Curve) sDebug+="Curve"; else sDebug+="Line"; sDebug+="\r\n"; foreach (EPointF pt in pts) sDebug+=pt.ToString()+"\r\n"; } hasDrawnSinceLastStyleChange = true; } else { pathInfoCurrent.Path.CloseAllFigures(); pathInfoCurrent.Path.StartFigure(); } pntCurrentLoc = cmd.GetNewLoc(pntCurrentLoc); } else { if (hasDrawnSinceLastStyleChange) { pathInfoCurrent = new PathInfo(); pathInfos.Add(pathInfoCurrent); } if (cmd is ShapeCommand.FillStyle) { ShapeCommand.FillStyle fs = (ShapeCommand.FillStyle)cmd; Brush brush = null; if (fs.StyleId > 0) brush = ((Style.FillStyle)fillStyles[fs.StyleId-1]).GetBrush(); if (fs.Side == 0) pathInfoCurrent.Brush0 = brush; else pathInfoCurrent.Brush1 = brush; } else if (cmd is ShapeCommand.LineStyle) { ShapeCommand.LineStyle ls = (ShapeCommand.LineStyle)cmd; Pen pen = null; if (ls.StyleId > 0) pen = ((Style.LineStyle)lineStyles[ls.StyleId-1]).GetPen(); pathInfoCurrent.Pen = pen; if (pen!=null) pen.Width*= ptScale.X; } hasDrawnSinceLastStyleChange = false; } } Matrix transform = new Matrix(); transform.Scale(ptScale.X,ptScale.Y); ERectangle bounds = ERectangle.FromLTRB(99999,99999,-99999,-99999); foreach (PathInfo pathInfo in pathInfos) { //pathInfo.Path.Transform(transform); bounds.Expand(pathInfo.GetBounds().ToERectangle()); } ptOffset = bounds.TopLeft; if (bounds.Width == 0 || bounds.Height == 0) return null; //this.Bounds = bounds; if (Shape.Debug) Endogine.Files.FileReadWrite.Write("__s.txt", sDebug); transform = new Matrix(); transform.Translate(-bounds.X, -bounds.Y); foreach (PathInfo pathInfo in pathInfos) pathInfo.Path.Transform(transform); Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb); Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(bmp); canvas.Locked = true; canvas.Fill(Color.FromArgb(0, 255, 255, 255)); canvas.Dispose(); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.HighQuality; foreach (PathInfo pathInfo in pathInfos) { if (pathInfo.Pen!=null) g.DrawPath(pathInfo.Pen, pathInfo.Path); if (pathInfo.Brush0!=null) g.FillPath(pathInfo.Brush0, pathInfo.Path); if (pathInfo.Brush1!=null) //TODO: can GDI+ handle Flash's two different fills (0 and 1)? g.FillPath(pathInfo.Brush1, pathInfo.Path); } return bmp; }
public Marble() { m_pntPeriods = new EPointF(15,30); }
private void DrawLineWithCaps(Graphics g, Pen pen, EPointF start, EPointF end, float capLength) { //pen caps aren't flexible enough... // pen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; // pen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; EPointF pntDiff = end-start; g.DrawLine(pen, start.ToPointF(), end.ToPointF()); g.DrawLine(pen, start.ToPointF(), (start+EPointF.FromLengthAndAngle(capLength, pntDiff.Angle+(float)Math.PI/4)).ToPointF()); g.DrawLine(pen, start.ToPointF(), (start+EPointF.FromLengthAndAngle(capLength, pntDiff.Angle-(float)Math.PI/4)).ToPointF()); g.DrawLine(pen, end.ToPointF(), (end+EPointF.FromLengthAndAngle(capLength, pntDiff.Angle+(float)Math.PI+(float)Math.PI/4)).ToPointF()); g.DrawLine(pen, end.ToPointF(), (end+EPointF.FromLengthAndAngle(capLength, pntDiff.Angle+(float)Math.PI-(float)Math.PI/4)).ToPointF()); }
private void moveSprite_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.StillDown) { EPointF pntNow = new EPointF(e.X, e.Y); EPointF gridSpacing = new EPointF(30, 30); EPointF gridOffset = new EPointF(0, 0); if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control) //Snap to grid { pntNow -= _gridOffset.ToEPointF(); pntNow /= _gridSpacing.ToEPointF(); pntNow = new EPointF((float)Math.Round(pntNow.X), (float)Math.Round(pntNow.Y)) * _gridSpacing.ToEPointF(); pntNow += _gridOffset.ToEPointF(); } EPointF pntDiff = pntNow - sender.MouseDownLoc.ToEPointF(); if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Shift) //Force horizontal/vertical movement { if ((pntDiff.Angle > (float)Math.PI/4 && pntDiff.Angle < 3*(float)Math.PI/4) || (pntDiff.Angle < -(float)Math.PI/4 && pntDiff.Angle > -3*(float)Math.PI/4)) pntDiff*=new EPointF(1,0); else pntDiff*=new EPointF(0,1); } this.m_sp.Loc = pntDiff + this.pntStartMove; this.Update(); } else if (t == Endogine.Sprite.MouseEventType.Down) this.pntStartMove = this.m_sp.Loc.Copy(); }
private void sp_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.Down) { } else if (t == Endogine.Sprite.MouseEventType.StillDown) { EPoint pntAxis = (EPoint)sender.Tag; EPointF pntDiff = new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); this.m_sp.Move(pntDiff*pntAxis); } }
/// <summary> /// Stretching sprite /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="t"></param> private void spSquare_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.StillDown) { EPoint pntWhichSquare = (EPoint)sender.Tag; EPointF pntDiff = new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); EPointF pntRestrictTo = new EPointF(); if (pntWhichSquare.Y == 1) pntRestrictTo.X = 1; else if (pntWhichSquare.X == 1) pntRestrictTo.Y = 1; else pntRestrictTo = new EPointF(1,1); EPointF pntMove = pntDiff*pntRestrictTo; ERectangleF rct = this.m_sp.Rect.Copy(); if (pntWhichSquare.X == 0 || pntWhichSquare.Y == 0) { if (pntWhichSquare.X == 0 && pntWhichSquare.Y == 2) { rct.X+=pntMove.X; rct.Width-=pntMove.X; rct.Height+=pntMove.Y; } else if (pntWhichSquare.X == 2 && pntWhichSquare.Y == 0) { rct.Y+=pntMove.Y; rct.Height-=pntMove.Y; rct.Width+=pntMove.X; } else { rct.Location+=pntMove; rct.Size-=pntMove; } } else rct.Size+=pntMove; this.m_sp.Rect = rct; this.Update(); } }
private void rotateSprite_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { EPointF pivotLoc = this.m_sp.Loc; if (t == Endogine.Sprite.MouseEventType.StillDown) { EPointF pntNow = new EPointF(e.X, e.Y) - pivotLoc; float fAngleDiff = pntNow.Angle - this.pntMouseStartRotate.Angle; if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Shift) { } this.m_sp.Rotation = fAngleDiff; } else if (t == Endogine.Sprite.MouseEventType.Down) this.pntMouseStartRotate = new EPointF(e.X, e.Y) - pivotLoc; }
private void ReadPSDChannelTag(BinaryReverseReader reader) { string sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { reader.BaseStream.Position-=4; //back it up before throwing exception throw(new Exception("Effect header incorrect")); } string sKey = new string(reader.ReadChars(4)); uint nLength = reader.ReadUInt32(); long nPosStart = reader.BaseStream.Position; switch (sKey) { case "lyid": this.LayerID = (int)reader.ReadUInt32(); break; case "fxrp": this.ReferencePoint = new EPointF(); this.ReferencePoint.X = reader.ReadPSD8BitSingle(); this.ReferencePoint.Y = reader.ReadPSD8BitSingle(); break; case "clbl": //blend clipping this.BlendClipping = reader.ReadBoolean(); reader.BaseStream.Position+=3; //padding break; case "infx": //blend interior elements this.Blend = reader.ReadBoolean(); reader.BaseStream.Position+=3; //padding break; case "knko": //Knockout setting this.Knockout = reader.ReadBoolean(); reader.BaseStream.Position+=3; //padding break; case "lspf": //Protected settings //TODO: reader.ReadBytes(4); //nLength? //bits 0-2 = Transparency, composite and position break; case "lclr": //Sheet Color setting this.SheetColor = System.Drawing.Color.FromArgb( reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); reader.BaseStream.Position+=2; //padding break; case "lnsr": //Layer Name Source setting string sWhatIsThis = new string(reader.ReadChars((int)nLength)); //this.NameSourceSetting = reader.ReadUInt32(); break; case "luni": //Unicode Layer name uint nUnicodeLength = reader.ReadUInt32(); this.UnicodeName = new string(reader.ReadChars((int)nUnicodeLength*2)); break; case "lrFX": //Effects Layer info reader.BaseStream.Position+=2; //unused ushort nNumEffects = reader.ReadUInt16(); // aEffectsInfo = [] // paInfo[#EffectsInfo] = aEffectsInfo for (int nEffectNum = 0; nEffectNum < nNumEffects; nEffectNum++) { sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") throw(new Exception("Effect header incorrect")); EffectLayers.Effect effectForReading = new Endogine.Serialization.Photoshop.EffectLayers.Effect(reader); //reader.JumpToEvenNthByte(2); EffectLayers.Effect effect = null; //long nEffectEndPos = reader.BaseStream.Position + effect.Size; switch (effectForReading.Name) { case "cmnS": //common state BinaryReverseReader subreader = effectForReading.GetDataReader(); bool bVisible = subreader.ReadBoolean(); //reader.BaseStream.Position+=2; //unused break; case "dsdw": case "isdw": //drop/inner shadow if (effectForReading.Version == 0) effect = new Endogine.Serialization.Photoshop.EffectLayers.Shadow(effectForReading); else { //TODO: } break; case "oglw": case "iglw": //outer/inner glow if (effectForReading.Version == 0) effect = new Endogine.Serialization.Photoshop.EffectLayers.Glow(effectForReading); else { //TODO: } break; case "bevl": //bevel if (effectForReading.Version == 0) effect = new Endogine.Serialization.Photoshop.EffectLayers.Bevel(effectForReading); else { //TODO: } break; case "sofi": //unknown break; } this.Effects.Add(effect); //reader.BaseStream.Position = nEffectEndPos; } break; case "lsct": //TODO: what is this? reader.BaseStream.Position+=4; break; case "TySh": case "lfx2": //TODO: what are these? break; default: string sMsg = "Unknown layer setting: " + sKey + " Length:" + nLength.ToString() + " Pos: "+reader.BaseStream.Position.ToString(); //EH.Put(sMsg); break; } //add to nLength so it's padded to 4 int nLengthMod = (int)(nLength % (long)4); if (nLengthMod > 0) nLength+= 4-(uint)nLengthMod; reader.BaseStream.Position = nPosStart + nLength; reader.JumpToEvenNthByte(2); }