How do I draw a Rectangle on a rotated GraphicsContext and find the rotated co-ordinates - javafx-8

I an using GraphicsContext (gc) inside an AnimationTimer. I am scaling gc, drawing some objects, rotating gc and then drawing an image.
The image appears rotated as planned!
I need to be able to get the rotated rectangle that represents the image so I can check for proximity of the 4 (rotated) corners to other, non rotated objects.
I cannot see how to do this.
I have tried creating a rotated Rectangle to 'mirror' the objects rotation but I cannot see how to draw the Rectangle in the gc.
There is no gc.draw(Node), gc.draw(Rectangle) or gc.draw(Polygon). I need to draw it to confirm on screen that the two match.
My only other option is to break out the geometry set and rotate the points myself but it seem odd that javafx cannot do what I need.
Could somebody please help.

Related

Spawn objects in same place on screen on different aspect ratios, but retain distances between one another

I am trying to make connect the dots game in landscape mode, and i need to spawn dots from coordinates(0-1000) in json file onto screen. It's easy to map out different viewport size to coordinates and make them spawn in same location from the edges / center of the screen, but since when you connect the dots it's suppose to be a drawing I don't want it to strech. F.e 4/3 display and 21/9 one will stretch the drawing completely differently. How can I make sure it looks the same on all devices?
I am thinking of making an invisible rectangular shape in the middle of the screen with a size 1000x1000 or max screen height) and maping coordinates to that shape, so the drawing will always be in center of the screen and will always look exactly the same, but not sure if it's possible to get a specific point in shape.
I just think there's easy solution and I overcomplicate this.

How to keep mapbox-gl-draw features aligned with the perspective?

I am trying to draw rectangles in Mapbox that stay upright, while the map gets rotated (and are drawn upright, when the map is already rotated).
I've used the following code to draw rectangles: https://github.com/dqunbp/mapbox-gl-draw-rectangle-restrict-area
However, when I rotate the map, the rectangle rotates too (likewise, when the map is already rotated, the rectangles will be tilted too). Is there any option to keep the rectangle in the upright orientation while the map rotates?
Example of a rectangle rotating with the orientation of the map

How can you get the 3D space coordinates of the 4 corners of an ImageTarget in Vuforia Unity?

I am able to detect images in Vuforia images and overlay 3d objects on them. But I want to draw borders around the ImageTarget.
The problem is that I can only get the center of it such as,
productTarget.transform.position
How can I get the corners of the image ? It is simply a 2D image but Vuforia doesn't have anything to help with this.
There is no way to detect coordinates of the corners, but you can manually calculate it.
This will help you to get the height and width of the image
for example: coordinates of upper left corner will be center - (width/2) - (height/2)
I recommend you just make flat border which you want, and then just resize it on tracking image, because its scale is always the same and vuforia only moves the camera.
image
border
after tracking just child border to image
after parenting

ios game make a mask layer effect

I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.

iPhone animation: how do I animate the filling up of an area?

Consider a circle. Now consider a radius of the circle, drawn from the center of the circle towards the right. Now imagine that the radius is rotating about the center of the circle, sweeping out an area as it rotates. My problem is: I want to use iPhone's animation techniques to fill up the swept out area with a different color from the background area of the circle, as the radius rotates from 0 degrees to any chosen number of degrees about the circle.
I've looked through the Core Animation API, KeyFrame Animations, etc. but I am not able to find out how to do this. Any hints will be most welcome.
Thanks,
Sandeep
Check out CAShapeLayer. It lets you animate between two Core Graphics paths, which can be as complex as you want. In this case, you might want to animate between a path which defines a thin filled wedge and a filled wedge that covers a larger angle of the circle. You may need to use a CAKeyframeAnimation to make sure that it is animated in the sweeping motion you desire, and in the direction you want.