I have a number of object drawn in world co-ordinates with arbitrary transforms - rotation & scaling. I want to pick one of the objects via a mouse click, I have the rectangles of the objects but need to transform the mouse click co-ordinates in order to select the picked object. At the simplest I draw an object with transform (middle of bitmap) and rotate (45). How do I map the mouse click in the graphics area back to the world space of the objects?
Thanks
Richard
Related
How can I set rotation of the placed on vertical plane object to make its bottom side pararell to floor? At the moment vertically placed objects are sticky to the wall but have random rotation. I have been trying to set object on horizontal plane and then adjust vetical objects vector forward to horizontal objects vector up. That seems to work somehow but multiple objects apart of being pararell to each other are rotated in christmas tree shape. Important thing - I want to rotate it relative to real world, not to bottom of the screen.
What I want:
What I get:
VerticallyPlacedObject.transform.forward = HorizontallyPlacedObject.transform.up;
Screenshot:
I have a map (2d) which is about 5 times the size of the screen area. I can touch drag the map. However the user must only be able to drag it as far as the map is still showing. So the empty area outside map isn't showing.
So my question is: which of the two methods are best:
1) have colliders at the side of the screen and then put colliders on each side of the map. Then checking for collision and if so move the map so its collider does not touch the screen collider.
Or
2) check for the position of the map (i have an adjustable screen size according to device) and then stop the drag if it gets dragged further than visibility of screen. Using coordinates and math.
Will it take up more space (the ios/android) file if I use solution 1?
Thanks.
I have a 2D unity project.
I cannot depend on OnMouseExit because overlapping 2D box colliders cause the method to trigger even when the mouse is inside the bounds, since something else is in front (which is not my intention).
I was going to manually check for the mouse exiting on every frame by using:
if(!_collider.bounds.contains(Input.MousePosition))
But this does not work because `mouse position' is in terms of the number of pixels across the screen, and 'bounds' is in terms of "units" relative to the origin of the scene. The camera is Orthographic and slides around to look at the 2D plane that the world's sprites sit on. I have no idea how many "units" fit across the screen and suspect that it would change as soon as you change the aspect ratio or screen size.
You can use ScreenToWorldPoint(), to convert from screen point to 3D/2D point based on the camera's viewport, something like this:
if(!_collider.bounds.contains(Camera.main.ScreenToWorldPoint(Input.MousePosition)))
I plot a surface in a Plot Cube with TwoDMode = true, when I try to zoom using the mouse left drag, the selection zoom rectangle goes behind the surface, therefore, it is not properly shown. Is it possible to force the selection rectangle to be on top of the surface? Moreover, is it possible by hovering or clicking the mouse on the surface, the X, Y and Z values be shown in some textboxes? Thank you very much.
Surfaces are inherently 3D objects. By default, they are intended to be used with ILPlotCube.TwoDMode set to false. But you can try to access the selection rectangle object and modify it accordingly. Try starting with plotCube.ZoomRectangle.Lines.Positions by raising its Z coordinate in order to move it closer to the camera.
Archieving the point of the surface under the cursor is not easy - but doable. Keep in mind, only the vertices of the surface tiles are known explicitly. You can use picking and the mouse events to get informed, if the mouse is over the surface:
surface.MouseMove += (_s,_a) => { yourHandler(_a); }
Afterwards, you are on your own. First, you will have to find the actual surface 3D coordinates. If you can be sure that the surface has not been rotated, you can take a look here.
The method in that thread gives you the surface X and Y coordinates. You can go further and (manually) find the corresponding tile for that position. For the final and exact X,Y,Z coordinates, you would have to interpolate the tile (triangle) vertices to the actual mouse position, using barycentric interpolation.
In order to show the 3D coordinate, you can simply use an ILLabel. You may or may not want to put that into an ILScreenObject.
I have to draw a map with Managed DirectX. The map arrived in MapInfo format (lines, polylines, regions/polygons). Polygons are already triangulated (done with GLUtesselator).
The idea:
GPS Coordinates are converted to x,y points (Mercator Projection)
I use PositionColored VertexFormat
Center of the view is [x,y] (can modify by mouse move)
Camera is always positioned to [x,y,z] where z is the zoom (-100 by default, can modify by mouse wheel)
Camera target is: [x,y,0], camera up: [0,1,0]
The layers of the map are positioned by Z (+1.0, 0.99, 0.98, 0.97...etc)
I can already do:
Draw lines and polylines
Draw one layer of polygons
My problem is: when I want to draw all layers I see only one of them. I think there is some problem with z ordering. What should I do to solve this? Modify the RenderState? The best would be if I could draw as in GDI (first in the back, last in the front).
Other question: how can I get the coordinate of a pixel under the mouse cursor? (in the GDI version of the map I could do it because I used my own viewport for rendering, but now directx do everything)
Thanks!
If your map is purely 2D, make sure that Z buffering is turned off. Once it is, things will display in the order you draw them in.