ipad missing overlapped annotations - ipad

While I'm trying to draw cross lines on iPad view , Its erasing the overlapped part of previous line. I'm using setNeedsDisplayInRect() method to refresh drawings. please suggest me to overcome this issue.
I wrote code for this is
I'm using the below code to draw:
context.MoveTo (penVertices [0].X, penVertices [0].Y);
for (int i = 1; i < penVertices.Count; i++) {
context.AddLineToPoint (penVertices [i].X, penVertices [i].Y);
}
context.StrokePath();
And using below code to display the line
SetNeedsDisplayInRect(RectangleF.FromLTRB(minX - (lineWidth/2), minY - (lineWidth/2), maxX + (lineWidth/2), maxY + (lineWidth/2)));

Hi to avoid erasing of previous made annotations at overlapped place, Use paths to draw annotations instead of simple context.

Related

How to hide value labels when zooming out in MPAndroidChart?

I'm using Swift version of MPAndroidChart and trying to figure out how to hide value labels when a few of them are located too close together and start to overlap on a line chart.
Hiding all the value labels when zoomed out to a certain point works too(still don't know how to do it), but hiding only the ones that are overlapping would be the best.
I know that I can manually call setDrawValues = false, but I want it to be called automatically on zoom.
enter image description here
In Android, I use the same as iOS
1: Find the difference between 1st and 2nd index y-axis label(YAxisRenderer)
for (int i = from; i < to; i++)
{
String text = mYAxis.getFormattedLabel(i);
double value1=Double.parseDouble(mYAxis.getFormattedLabel(1).replace(",",""));
double value2=Double.parseDouble(mYAxis.getFormattedLabel(2).replace(",",""));
result=(value2-value1)-40;
//POPreferences.setDifference(String.valueOf(result));
c.drawText(text, fixedPosition, positions[i * 2 + 1] + offset, mAxisLabelPaint);
}
2: Use result variable when text draws on bar or line(BarChartRenderer.java):
if (result >= vals[k / 2])
{
drawValue(c,dataSet.getValueFormatter(),vals[k / 2], entry, i, x, y,color);
}

How to move/animate CGRects

I'm having trouble moving CGRects around. I'm trying to make a breakout game. In my drawView file, I have written code in the drawRect function by removing the comments.
I end my drawRect function with this moveBall(&_ball, &_context, rect);
moveball() is declared/implemented in my viewController.h/viewController.m.
I'm not sure how to then move/animate the ball once it is in my controller. I have the following code:
void moveBall(CGRect *ball, CGContextRef *context, CGRect rect)
{
CGFloat velX = 1;
CGFloat velY = 1;
while (ball->origin.x + CGRectGetWidth(*ball) < CGRectGetWidth(rect))
{
CGContextClearRect(*context, *ball);
*ball = CGRectOffset(*ball, velX, velY);
CGContextFillEllipseInRect(*context, *ball);
}
};
What happens is that the ball is "moved" to a different place, not animated there. The problem is that the while loop is implemented and the final result is displayed. I want the while loop to run after the drawing is done.
Can anyone guide me to make the ball move?
Trying to make animations inside the drawRect method using CoreGraphics framework is exercise in futility.
For animations you should use other frameworks/technologies intended for that.
Standard apps - Core Animation
Games - SpriteKit, OpenGL ES, Metal, cocos2D, Unity3D,

How to implement MKAnnotationViews that rotate with the map

I have an app with some annotations on it, and up until now they are just symbols that look good with the default behavior (e.g. like numbers and letters). Their directions are fixed in orientation with the device which is appropriate.
Now however I need some annotations that need to be fixed in orientation to the actual map, so if the map rotates, then the annotation symbols need to rotate with it (like an arrow indicating the flow of a river for example).
I don't want them to scale with the map like an overlay but I do want them to rotate with the map.
I need a solution that primarily works when the user manually rotates the map with their fingers, and also when it rotates due to be in tracking with heading mode.
On Google Maps (at least on android) this is very easy with a simple MarkerOptions.flat(true)
I am sure it won't be too much more difficult on ios, I hope.
Thanks in advance!
Here's what I used for something similar.
- (void)rotateAnnotationView:(MKAnnotationView *)annotationView toHeading:(double)heading
{
// Convert mapHeading to 360 degree scale.
CGFloat mapHeading = self.mapView.camera.heading;
if (mapHeading < 0) {
mapHeading = fabs(mapHeading);
} else if (mapHeading > 0) {
mapHeading = 360 - mapHeading;
}
CGFloat offsetHeading = (heading + mapHeading);
while (offsetHeading > 360.0) {
offsetHeading -= 360.0;
}
CGFloat headingInRadians = offsetHeading * M_PI / 180;
annotationView.layer.affineTransform = CGAffineTransformMakeRotation(headingInRadians);
}
And then, this is called in regionDidChange etc.
Unfortunately, this solution doesn't rotate while the user is rotating the map, but it corrects itself afterwards to make sure it has the proper heading. I wrap some of the affineTransform into an animation block to make it look nice.
Hopefully this can help, or maybe help get you pointed in the right direction.

Center of rotation for cc.RotateBy applied on a cc.DrawNode in cocos2d-js

I made a drawNode to draw primitive using this code:
var.drawNode = cc.DrawNode.create();
drawNode.drawSegment(this.pos, cc.p(this.pos.x + this.length * Math.sin(this.rotation), this.pos.y + this.length * Math.cos(this.rotation)), STICK_THICKESS, cc.color(255,255,0,255));
It basically draws a line from this.pos to another point.
Now I want to rotate the line around this.pos, so I thought I just need to simply add this:
drawNode.setAnchorPoint(this.pos);
var rotate = cc.RotateBy.create(2, 360);
drawNode.runAction(rotate);
But it's still rotating around some random point.
Ugly but working method:
drawNode.setContentSize(1, 1);
drawNode.setAnchorPoint(this.pos);
drawNode.setPosition(this.pos);
var rotate = cc.RotateBy.create(2, 360);
drawNode.runAction(rotate);
BTW create methods are deprecated in Cocos2d-html5 3.0+. Use cc.rotateBy() instead of cc.RotateBy.Create(), new cc.DrawNode() instead of cc.DrawNode.create()

Vertices behind are being drawn infront - XNA

Well, I am creating a minecraft terrain thing just for the heck of it. The problem I have is that if you look on a certain angle some faces which are actually behind others are drawn in front of them, thus not showing the actual ones which are there. Like minecraft I have the terrain seperated into regions, and when the vertexbuffer is built, only the "outside" faces are shown. It is also for some reason is not drawing the very top nor the left blocks. In addition to all of these problems faces seem to be overlapping ie (only half of a face can be seen)
Here is what it looks like (note I am only drawing the top faces because I have to fix the others up): http://s1100.photobucket.com/albums/g420/darestium/?action=view&current=minecraftliketerrain.png
I am also drawing all the regions in one go with the following method (i'm using reimer's effect file until I can write my own :):
public void Draw(Player player, World world)
{
effect.CurrentTechnique = effect.Techniques["TexturedNoShading"];
effect.Parameters["xWorld"].SetValue(Matrix.Identity);
effect.Parameters["xProjection"].SetValue(player.Camera.ProjectionMatrix);
effect.Parameters["xView"].SetValue(player.Camera.ViewMatrix);
effect.Parameters["xCamPos"].SetValue(player.Camera.Position);
effect.Parameters["xTexture"].SetValue(world.TextureAlias.SheetTexture);
effect.Parameters["xCamUp"].SetValue(player.Camera.UpDownRotation);
for (int x = 0; x < world.regions.GetLength(0); x++)
{
for (int y = 0; y < world.regions.GetLength(1); y++)
{
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
Region region = world.regions[x, y];
if (player.Camera.BoundingFrustum.Contains(region.BoundingBox) != ContainmentType.Disjoint)
{
device.SetVertexBuffer(region.SolidVertexBuffer);
//device.Indices = region.SolidIndices;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, region.VertexCount);
//device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, region.VertexCount, 0, region.SolidIndices.IndexCount / 3);
}
}
}
}
}
Help would be much appreciated thanks :)
Looks like the Z-buffer is disabled. Try setting:
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
The issue with it not drawing the top/left blocks, that you mention, is probably an issue to do with your vertex buffer generation code (if so, try asking another question specifically about that issue).

Resources