protected override void PreUpdate(CanvasContext2D context) { context.DrawImage(_backgroundImage, 0, 0); Position += BaseSpeed * DeltaTime; }
public override void Draw(RenderContext renderContext) { bool onScreen = true; double rad = radius; if (skyRelative) { rad /= renderContext.FovScale / 3600; } Vector3d screenSpacePnt = renderContext.WVP.Transform(center); if (screenSpacePnt.Z < 0) { onScreen = false; } if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, center) < .55) { onScreen = false; } if (renderContext.gl != null) { if (Annotation.BatchDirty || AnnotationDirty) { Vector3d up = Vector3d.Create(0, 1, 0); Vector3d xNormal = Vector3d.Cross(center, up); Vector3d yNormal = Vector3d.Cross(center, xNormal); double r = radius / 44; int segments = 72; double radiansPerSegment = Math.PI * 2 / segments; List <Vector3d> vertexList = new List <Vector3d>(); for (int j = 0; j <= segments; j++) { double x = Math.Cos(j * radiansPerSegment) * r; double y = Math.Sin(j * radiansPerSegment) * r; vertexList.Add(Vector3d.Create(center.X + x * xNormal.X + y * yNormal.X, center.Y + x * xNormal.Y + y * yNormal.Y, center.Z + x * xNormal.Z + y * yNormal.Z)); } if (strokeWidth > 0 && vertexList.Count > 1) { for (int i = 0; i < (vertexList.Count - 1); i++) { LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1)); } LineList.AddLine(vertexList[vertexList.Count - 1], vertexList[0], lineColor, new Dates(0, 1)); } if (fill) { List <int> indexes = Tessellator.TesselateSimplePoly(vertexList); for (int i = 0; i < indexes.Count; i += 3) { TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2); } } AnnotationDirty = false; } } else { if (onScreen) { CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Alpha = Opacity; ctx.BeginPath(); ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true); ctx.LineWidth = strokeWidth; ctx.FillStyle = fillColor.ToString(); if (fill) { ctx.Fill(); } ctx.Alpha = 1.0; ctx.StrokeStyle = lineColor.ToString(); ctx.Stroke(); ctx.Restore(); } } }
private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2, double sx0, double sy0, double sx1, double sy1, double sx2, double sy2) { if (!Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2)) { return(false); } //double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels; //Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), ExpansionInPixels); //Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), ExpansionInPixels); //Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), ExpansionInPixels); //Vector2d expandedS0 = MiterPoint(x0, y0, x1, y1, x2, y2); //Vector2d expandedS1 = MiterPoint(x1, y1, x0, y0, x2, y2); //Vector2d expandedS2 = MiterPoint(x2, y2, x1, y1, x0, y0); MiterPointOut(expandedS0, x0, y0, x1, y1, x2, y2, ExpansionInPixels); MiterPointOut(expandedS1, x1, y1, x0, y0, x2, y2, ExpansionInPixels); MiterPointOut(expandedS2, x2, y2, x1, y1, x0, y0, ExpansionInPixels); x0 = expandedS0.X; y0 = expandedS0.Y; x1 = expandedS1.X; y1 = expandedS1.Y; x2 = expandedS2.X; y2 = expandedS2.Y; ctx.Save(); if (RenderingOn) { ctx.BeginPath(); ctx.MoveTo(x0, y0); ctx.LineTo(x1, y1); ctx.LineTo(x2, y2); ctx.ClosePath(); ctx.Clip(); } double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0; //if (denom == 0) //{ // ctx.Restore(); // return false; //} double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom; double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom; double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom; double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom; double dx = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom; double dy = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom; ctx.Transform(m11, m12, m21, m22, dx, dy); if (RenderingOn) { ctx.Alpha = Opacity; if (lighting < 1.0) { ctx.Alpha = 1; ctx.FillStyle = "Black"; ctx.FillRect(0, 0, Width, Height); ctx.Alpha = lighting * Opacity; } ctx.DrawImage(im, 0, 0); } ctx.Restore(); return(true); }
/// <summary> /// Called at each iterarion. /// </summary> /// <param name="context"></param> public abstract void Update(CanvasContext2D context);
protected virtual void Update(CanvasContext2D context) { }
public override void Update(CanvasContext2D context) { context.DrawImage(_backgroundImage, 0, 0); }
protected override void PreUpdate(CanvasContext2D context) { // Draw background context.DrawImage(_backgroundImage, 0, 0); switch (Status) { case RaceStatus.Running: // Handle left and right turns if (Speed > 0) { float increment = (60 - Math.Max(Speed, 20)) / 80; if (Left) { Shift += increment * DeltaTime; CarSystem.CarObject.CurrentAnimation = Down ? "b-Left" : "Left"; } if (Right) { Shift -= increment * DeltaTime; CarSystem.CarObject.CurrentAnimation = Down ? "b-Right" : "Right"; } } if (!(Left ^ Right)) { CarSystem.CarObject.CurrentAnimation = Down ? "b-Forward" : "Forward"; } // Handle acceleration, braking and inertia if (Down) { Speed -= 0.4f; } else if (Up) { Speed += 0.3f; } else { Speed -= 0.1f; } if (Up) { _rpm += 40; } else { _rpm -= 40; } if (_rpm > 4500) { _rpm = 4500; } else if (_rpm < 200) { _rpm = 200; } // When driving off the road if (Math.Abs(Shift) > 350) { Speed *= 0.95f; if (Math.Abs(Shift) > 450) { Shift = (Shift / Math.Abs(Shift)) * 450; } } break; case RaceStatus.Win: case RaceStatus.Fail: Speed -= 1; _rpm -= 40; break; case RaceStatus.Crashing: Speed -= 0.3f; Shift -= Shift * DeltaTime / 1000; break; } // Speed capping if (Speed > MaxSpeed) { Speed = MaxSpeed; } if (Speed < 0) { Speed = 0; } // Calculating new position Position += Speed * DeltaTime; // Drift in turns Shift += Curve * Speed * 150; if (Position >= RoadLength && Status == RaceStatus.Running) { _music.Pause(); Status = RaceStatus.Win; CarSystem.CarObject.StartAnimation("Skid"); ShowMessage(_winMessage); RemoveSystem(_engineSoundSystem); RemoveSystem(_npcSystem); int timeLeft = Math.Floor(TimeLeft / 1000); CurrentGame.Score += 1000 + timeLeft * 500; //if (!_practice) //{ // pendingTimers.Add( // Window.SetTimeout(delegate() // { // UpdateMessage("<p>Time Left: " + timeLeft + "</p>"); // }, 1500)); // pendingTimers.Add( // Window.SetTimeout(delegate() // { // UpdateMessage("<p>Score: " + CurrentGame.Score + "</p>"); // }, 2500)); //} pendingTimers.Add( Window.SetTimeout(delegate() { UpdateMessage("<p>Press a key to continue.</p>"); }, 3000)); } }
public void Draw(RenderContext renderContext, float opacity, bool cull) { InitBuffer(renderContext); if (renderContext.gl == null) { if (!imageReady) { return; } renderContext.Device.Save(); renderContext.WVP.ProjectArrayToScreen(worldList, transformedList); CanvasContext2D ctx = renderContext.Device; ctx.Alpha = .4; double width = renderContext.Width; double height = renderContext.Height; Vector3d viewPoint = Vector3d.MakeCopy(renderContext.ViewPoint); double scaleFactor = renderContext.FovScale / 100; foreach (DataItem item in items) { // todo filter by date // if (Vector3d.Dot(viewPoint, item.Location) < 0) if (item.Tranformed.Z < 1) { double x = item.Tranformed.X; double y = item.Tranformed.Y; double size = .1 * item.Size / scaleFactor; double half = size / 2; if (x > -half && x < width + half && y > -half && y < height + half) { //ctx.DrawImage(starProfile, x - size / 2, y - size / 2, size, size); ctx.BeginPath(); // ctx.FillStyle = "rgb(200,0,0)"; ctx.FillStyle = item.Color.ToFormat(); ctx.Arc(x, y, size, 0, Math.PI * 2, true); ctx.Fill(); } } } renderContext.Device.Restore(); } else { Vector3d zero = new Vector3d(); Matrix3d matInv = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View); matInv.Invert(); Vector3d cam = Vector3d.TransformCoordinate(zero, matInv); foreach (TimeSeriesPointVertexBuffer pointBuffer in pointBuffers) { TimeSeriesPointSpriteShader.Use( renderContext, pointBuffer.VertexBuffer, starTexture.Texture2d, Color.FromArgb(255 * opacity, 255, 255, 255), DepthBuffered, (float)(this.JNow), this.TimeSeries ? (float)Decay : 0, cam, (float)(scale * (renderContext.Height / 960)), MinSize, ShowFarSide, Sky ); renderContext.gl.drawArrays(GL.POINTS, 0, pointBuffer.Count); } // renderContext.gl.disable(0x8642); } }
public Fish(FishTank tank, double x, double y, double z, ImageElement fishStrip, CanvasContext2D context) { _tank = tank; _x = x; _y = y; _z = z; _zFactor = 1; _species = Math.Floor(Math.Random() * FishTank.FishSpecies); _cellIndex = Math.Floor(Math.Random() * (FishTank.CellsInFishStrip - 1)); _cellReverse = -1; _angle = 2 * Math.PI * Math.Random(); _xAngle = Math.Cos(_angle); _yAngle = Math.Sin(_angle); _zAngle = 1 - 2 * Math.Round(Math.Random()); _scale = 0.1; _flip = 1; _velocity = 100; // Stop fish from swimming straight up or down if ((_angle > Math.PI * 4 / 3) && (_angle < Math.PI * 5 / 3) || (_angle > Math.PI * 1 / 3) && (_angle < Math.PI * 2 / 3)) { _angle = Math.PI * 1 / 3 * Math.Random(); _xAngle = Math.Cos(_angle); _yAngle = Math.Sin(_angle); } // Face the fish the right way if angle is between 6 o'clock and 12 o'clock if ((_angle > Math.PI / 2) && (_angle < Math.PI / 2 * 3)) { _flip = -1; } _fishStrip = fishStrip; _context = context; }
public void Draw() { CanvasElement canvas = Document.GetElementById <CanvasElement>("graph"); CanvasContext2D ctx = (CanvasContext2D)canvas.GetContext(Rendering.Render2D); if (image != null) { image.DrawHistogram(ctx); } string red = "rgba(255,0,0,255)"; string green = "rgba(0,255,0,255)"; string blue = "rgba(0,0,255,255)"; ctx.StrokeStyle = red; ctx.BeginPath(); ctx.MoveTo(lowPosition, 0); ctx.LineTo(lowPosition, 150); ctx.Stroke(); ctx.StrokeStyle = green; ctx.BeginPath(); ctx.MoveTo(highPosition, 0); ctx.LineTo(highPosition, 150); ctx.Stroke(); ctx.StrokeStyle = blue; ctx.BeginPath(); ctx.Arc(center, 75, 10, 0, Math.PI * 2, false); ctx.ClosePath(); ctx.Stroke(); List <Vector2d> Curve = new List <Vector2d>(); //todo get from combo box switch (SelectedCurveStyle) { case 0: // Linear { Curve.Clear(); Curve.Add(Vector2d.Create(lowPosition, 150)); Curve.Add(Vector2d.Create(highPosition, 0)); break; } case 1: // Log { Curve.Clear(); double factor = 150 / Math.Log(255); double diff = (highPosition - lowPosition); int jump = diff < 0 ? -1 : 1; double step = Math.Abs(256.0 / (diff == 0 ? .000001 : diff)); double val = .000001; for (int i = lowPosition; i != highPosition; i += jump) { Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Log(val) * factor)))); val += step; } } break; case 2: // Power 2 { Curve.Clear(); double factor = 150 / Math.Pow(255, 2); double diff = (highPosition - lowPosition); int jump = diff < 0 ? -1 : 1; double step = Math.Abs(256.0 / (diff == 0 ? .000001 : diff)); double val = .000001; for (int i = lowPosition; i != highPosition; i += jump) { Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Pow(val, 2) * factor)))); val += step; } } break; case 3: // Square Root { Curve.Clear(); double factor = 150 / Math.Sqrt(255); double diff = (highPosition - lowPosition); int jump = diff < 0 ? -1 : 1; double step = Math.Abs(256.0 / (diff == 0 ? .000001 : diff)); double val = .000001; for (int i = lowPosition; i != highPosition; i += jump) { Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Sqrt(val) * factor)))); val += step; } } break; } if (Curve.Count > 1) { ctx.BeginPath(); ctx.StrokeStyle = blue; ctx.MoveTo(Curve[0].X, Curve[0].Y); for (int i = 1; i < Curve.Count; i++) { ctx.LineTo(Curve[i].X, Curve[i].Y); } ctx.Stroke(); } }
protected override void Update(CanvasContext2D context) { context.DrawImage(_titleImage, (800 - _titleImage.NaturalWidth) / 2, 90 + Math.Cos(Ticks / 1000) * 20); }
public override void Update(CanvasContext2D context) { if (_level.Status == ShooterStatus.Running) { foreach (GameObject building in _level.Buildings.VisibleBuildings) { if (!Ship.Collides(building)) { continue; } _level.Crash(); return; } foreach (Dino dino in _level.Dinos.VisibleDinos) { if (dino.Dead || !Ship.Collides(dino)) { continue; } _level.Crash(); return; } } Ship.Update(); if (_level.Status != ShooterStatus.Running) { return; } float vertical = 0; float horizontal = 0; if (_level.Up) { Ship.StartAnimation("Up"); vertical -= _speed; } if (_level.Down) { Ship.StartAnimation("Down"); vertical += _speed; } if (!(_level.Up ^ _level.Down)) { Ship.StartAnimation("Default"); } if (_level.Left) { horizontal -= _speed; } if (_level.Right) { horizontal += _speed; } Ship.Location.TranslateByCoordinates(horizontal * _level.DeltaTime, vertical * _level.DeltaTime); if (Ship.Location.X < 0) { Ship.Location.X = 0; } else if (Ship.Location.X > 700) { Ship.Location.X = 700; } if (Ship.Location.Y < 30) { Ship.Location.Y = 30; } else if (Ship.Location.Y > 550) { Ship.Location.Y = 550; } }
private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2, double sx0, double sy0, double sx1, double sy1, double sx2, double sy2) { bool inside; if (factor == 1.0) { inside = Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2); } else { hw = Width / 2; qw = hw * factor; hh = Height / 2; qh = hh * factor; inside = Intersects(hw - qw, hw + qw, hh - qh, hh + qh, x0, y0, x1, y1, x2, y2); } if (!inside) { return(false); } double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels; Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), edgeOffset); Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), edgeOffset); Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), edgeOffset); x0 = expandedS0.X; y0 = expandedS0.Y; x1 = expandedS1.X; y1 = expandedS1.Y; x2 = expandedS2.X; y2 = expandedS2.Y; ctx.Save(); ctx.BeginPath(); ctx.MoveTo(x0, y0); ctx.LineTo(x1, y1); ctx.LineTo(x2, y2); ctx.ClosePath(); ctx.Clip(); double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0; if (denom == 0) { ctx.Restore(); return(false); } double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom; double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom; double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom; double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom; double dx = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom; double dy = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom; ctx.Transform(m11, m12, m21, m22, dx, dy); ctx.DrawImage(im, 0, 0); ctx.Restore(); if (factor != 1.0) { ctx.BeginPath(); ctx.MoveTo(hw - qw, hh - qh); ctx.LineTo(hw + qw, hh - qh); ctx.LineTo(hw + qw, hh + qh); ctx.LineTo(hw - qw, hh + qh); ctx.ClosePath(); ctx.StrokeStyle = "yellow"; ctx.Stroke(); } return(true); }
//bool hitTestInit = false; //void InitHitTest(RenderContext renderContext) //{ // Vector2d center = new Vector2d(); // double radius = 0; // Vector2d[] screenPoints = new Vector2d[points.Count]; // int index = 0; // foreach (Vector3d pnt in points) // { // Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt); // if (screenSpacePnt.Z < 0) // { // return; // } // if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55) // { // return; // } // screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y); // index++; // } // ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius); //} public override void Draw(RenderContext renderContext) { if (renderContext.gl != null) { if (Annotation.BatchDirty || AnnotationDirty) { //todo can we save this work for later? List <Vector3d> vertexList = points; if (strokeWidth > 0 && points.Count > 1) { for (int i = 0; i < (points.Count - 1); i++) { LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1)); } LineList.AddLine(vertexList[points.Count - 1], vertexList[0], lineColor, new Dates(0, 1)); } if (fill) { List <int> indexes = Tessellator.TesselateSimplePoly(vertexList); for (int i = 0; i < indexes.Count; i += 3) { TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2); } } AnnotationDirty = false; } } else { CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Alpha = Opacity; ctx.BeginPath(); bool first = true; foreach (Vector3d pnt in points) { Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt); if (screenSpacePnt.Z < 0) { ctx.Restore(); return; } if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75) { ctx.Restore(); return; } if (first) { first = false; ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y); } else { ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y); } } ctx.ClosePath(); ctx.LineWidth = strokeWidth; if (fill) { ctx.FillStyle = fillColor.ToString(); ctx.Fill(); } ctx.StrokeStyle = lineColor.ToString(); ctx.Alpha = 1; ctx.Stroke(); ctx.Restore(); } }
protected override void Update(CanvasContext2D context) { if (Status != RaceStatus.Fail && Status != RaceStatus.Win) { context.DrawImage(_timeLeftFrame, 308, 10); Type.SetField(context, "textAlign", "right"); context.FillStyle = "#00AD11"; if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0) { if (TimeLeft < 0) { TimeLeft = 0; } context.Font = "110px Digital"; context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105); } if (Speed > 0) { context.Save(); context.Scale(-1, 1); long width = Math.Floor((10 * Speed) / MaxSpeed) * 22; if (width > 0) { context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102); } context.Restore(); } context.Font = "30px Digital"; context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120); int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22; context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102); context.FillText(Math.Floor(_rpm) + " RPM", 130, 120); context.BeginPath(); context.LineWidth = 3; context.StrokeStyle = "#00AD11"; context.MoveTo(5, 150); float x = 5 + Math.Min(Position * 735 / RoadLength, 735); context.LineTo(x, 150); context.Stroke(); context.ClosePath(); context.BeginPath(); context.StrokeStyle = "#006808"; context.MoveTo(x, 150); context.LineTo(790, 150); context.Stroke(); context.ClosePath(); context.DrawImage(_markerImage, x, 142); } if (Status == RaceStatus.Running) { TimeLeft -= DeltaTime; if (TimeLeft < 0) { _music.Pause(); CarSystem.CarObject.CurrentAnimation = "Forward"; Status = RaceStatus.Fail; ShowMessage(_failMessage); RemoveSystem(_engineSoundSystem); RemoveSystem(_npcSystem); pendingTimers.Add(Window.SetTimeout(delegate() { UpdateMessage("<p>Press a key to continue.</p>"); }, 3000)); } } }
public override void Draw(RenderContext renderContext) { if (renderContext.gl != null) { if (Annotation.BatchDirty || AnnotationDirty) { //todo can we save this work for later? List <Vector3d> vertexList = points; if (strokeWidth > 0) { for (int i = 0; i < (points.Count - 1); i++) { LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1)); } } AnnotationDirty = false; } } else { CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Alpha = Opacity; bool first = true; foreach (Vector3d pnt in points) { Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt); if (screenSpacePnt.Z < 0) { ctx.Restore(); return; } if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75) { ctx.Restore(); return; } if (first) { first = false; ctx.BeginPath(); ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y); } else { ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y); } } ctx.LineWidth = strokeWidth; ctx.StrokeStyle = lineColor.ToString(); ctx.Stroke(); ctx.Restore(); } }
public void Paint() { CanvasContext2D g = (CanvasContext2D)Canvas.GetContext(Rendering.Render2D); g.FillStyle = "rgb(20, 22, 31)"; g.FillRect(0, 0, Width, Height); if (!ImagesLoaded) { return; } int netHeight = (Height - buffer * 2); int netWidth = (Width - buffer * 2); RowCount = Math.Round(Math.Max(netHeight / ThumbHeight, 1)); ColCount = Math.Round(Math.Max(netWidth / HorzSpacing, 1)); horzMultiple = ((float)netWidth + 13) / (float)ColCount; startIndex = Math.Round((startIndex / ItemsPerPage) * ItemsPerPage); Rectangle rectf; int index = startIndex; for (int y = 0; y < rowCount; y++) { for (int x = 0; x < colCount; x++) { if (index >= items.Count) { if (items.Count == 0 || showAddButton) { rectf = Rectangle.Create(Left + x * horzMultiple + 3f + startOffset, Top + y * VertSpacing, ThumbWidth - 10, 60); g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWide : bmpBackground, (int)((float)x * horzMultiple) + startOffset, y * VertSpacing); //g.FillText(emptyText, rectf.X,rectf,Y, rectf.Width); //g.DrawString(showAddButton ? addText : emptyText, UiTools.StandardRegular, (addButtonHover && showAddButton) ? UiTools.YellowTextBrush : UiTools.StadardTextBrush, rectf, UiTools.StringFormatCenterCenter); } break; } rectf = Rectangle.Create(Left + x * horzMultiple + 3 + startOffset, Top + y * VertSpacing, ThumbWidth - 14, 60); //Brush textBrush = UiTools.StadardTextBrush; string textBrush = "white"; if (index == hoverItem || (index == selectedItem && hoverItem == -1)) { g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWideHover : bmpBackgroundHover, Left + (int)((float)x * horzMultiple) + startOffset, Top + y * VertSpacing); textBrush = "yellow"; } else { g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWide : bmpBackground, Left + (int)((float)x * horzMultiple) + startOffset, Top + y * VertSpacing); } (items[index]).Bounds = Rectangle.Create((int)(Left + x * horzMultiple) + startOffset, Top + (int)(y * VertSpacing), (int)horzMultiple, (int)VertSpacing); try { ImageElement bmpThumb = items[index].Thumbnail; if (bmpThumb != null) { g.DrawImage(bmpThumb, Left + (int)(x * horzMultiple) + 2 + startOffset, Top + y * VertSpacing + 3); g.StrokeStyle = "rgb(0,0,0)"; g.Rect(Left + (int)((float)x * horzMultiple) + 2 + startOffset, Top + y * VertSpacing + 3, items[index].Thumbnail.Width, items[index].Thumbnail.Height); } else { items[index].Thumbnail = (ImageElement)Document.CreateElement("img"); items[index].Thumbnail.Src = items[index].ThumbnailUrl; items[index].Thumbnail.AddEventListener("load", delegate(ElementEvent e) { Refresh(); }, false); } } // TODO FIX this! catch { } //if (((IThumbnail)items[index]).IsImage) //{ // g.DrawImage(Properties.Resources.InsertPictureHS, (int)((float)x * horzMultiple) + 79, y * VertSpacing + 1); //} //if (((IThumbnail)items[index]).IsTour) //{ // g.DrawImage(Properties.Resources.TourIcon, (int)((float)x * horzMultiple) + 79, y * VertSpacing + 1); //} //g.DrawString(((IThumbnail), UiTools.StandardRegular, textBrush, rectf, UiTools.StringFormatThumbnails); g.FillStyle = textBrush; g.StrokeStyle = textBrush; g.LineWidth = 1; g.Font = "normal 8pt Arial"; g.FillText(items[index].Name, rectf.X, rectf.Y + rectf.Height, rectf.Width); //g.FillText(items[index].Name, 10, 10); index++; } if (index >= items.Count) { break; } } }
//protected Vector3d RaDecTo3d(double lat, double lng) //{ // return Vector3d.Create((Math.Cos(lng * RC) * Math.Cos(lat * RC) * radius), (Math.Sin(lat * RC) * radius), (Math.Sin(lng * RC) * Math.Cos(lat * RC) * radius)); //} private void DrawSingleConstellationOld(RenderContext renderContext, Lineset ls) { bool reverse = false; // todo get this working Place centroid = ConstellationCentroids[ls.Name]; if (centroid != null) { Vector3d pos = Coordinates.RADecTo3d(reverse ? -centroid.RA - 6 : centroid.RA, reverse ? centroid.Dec : centroid.Dec); if (Vector3d.Dot(renderContext.ViewPoint, pos) < maxSeperation) { return; } } drawCount++; string col; if (boundry) { if (constToDraw != ls.Name) { col = Settings.GlobalSettings.ConstellationBoundryColor; } else { col = Settings.GlobalSettings.ConstellationSelectionColor; } } else { col = Settings.GlobalSettings.ConstellationFigureColor; } if (renderContext.gl == null) { CanvasContext2D ctx = renderContext.Device; int count = ls.Points.Count; Vector3d lastPoint = new Vector3d(); ctx.Save(); bool linePending = false; ctx.BeginPath(); ctx.StrokeStyle = col; ctx.LineWidth = 2; ctx.Alpha = .25; for (int i = 0; i < count; i++) { if (ls.Points[i].PointType == PointType.Move || i == 0) { if (linePending) { ctx.Stroke(); } lastPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec)); ctx.MoveTo(lastPoint.X, lastPoint.Y); } else { Vector3d newPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec)); // if (lastPoint.Z > 0 && newPoint.Z > 0) { ctx.LineTo(newPoint.X, newPoint.Y); linePending = true; } } } if (boundry) { ctx.ClosePath(); } ctx.Stroke(); ctx.Restore(); } else { //todo add webgl method of drawing } }
//public static TextOverlay(Canvas canvas, TextObject textObject) //{ // this.canvas = canvas; // this.TextObject = textObject; // this.Name = textObject.Text.Split(new char[] { '\r', '\n' })[0]; // X = 0; // Y = 0; //} public override void Draw3D(RenderContext renderContext, bool designTime) { //TextBlock textBlock = new TextBlock(); //textBlock.Width = this.Width; //textBlock.Height = this.Height; //textBlock.Foreground = new SolidColorBrush(TextObject.ForgroundColor); //textBlock.Text = TextObject.Text; //textBlock.FontWeight = TextObject.Bold ? FontWeights.Bold : FontWeights.Normal; //textBlock.FontSize = TextObject.FontSize * 1.2; //textBlock.HorizontalAlignment = HorizontalAlignment.Left; //TranslateTransform tt = new TranslateTransform(); //tt.X = this.X - (Width / 2); //tt.Y = this.Y - (Height / 2); //textBlock.RenderTransform = tt; //canvas.Children.Add(textBlock); //textBlock.Opacity = this.Opacity; CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Translate(X, Y); ctx.Rotate(RotationAngle * RC); ctx.Alpha = Opacity; ctx.FillStyle = TextObject.ForgroundColor.ToString(); ctx.Font = (TextObject.Italic ? "italic" : "normal") + " " + (TextObject.Bold ? "bold" : "normal") + " " + Math.Round(TextObject.FontSize * 1.2).ToString() + "px " + TextObject.FontName; ctx.TextBaseline = TextBaseline.Top; String text = TextObject.Text; if (text.IndexOf("{$") > -1) { if (text.IndexOf("{$DATE}") > -1) { string date = String.Format("{0:yyyy/MM/dd}", SpaceTimeController.Now); text = text.Replace("{$DATE}", date); } if (text.IndexOf("{$TIME}") > -1) { string time = String.Format("{0:HH:mm:ss}", SpaceTimeController.Now); text = text.Replace("{$TIME}", time); } // text = text.Replace("{$DIST}", UiTools.FormatDistance(WWTControl.Singleton.SolarSystemCameraDistance)); text = text.Replace("{$LAT}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Lat)); text = text.Replace("{$LNG}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Lat)); text = text.Replace("{$RA}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.RA)); text = text.Replace("{$DEC}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Dec)); text = text.Replace("{$FOV}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.FovAngle)); } string[] lines = text.Split("\n"); double baseline = -(Height / 2); double lineSpace = TextObject.FontSize * 1.7; foreach (string line in lines) { List <string> parts = Util.GetWrappedText(ctx, line, Width); foreach (string part in parts) { ctx.FillText(part, -Width / 2, baseline); baseline += lineSpace; } } ctx.Restore(); }