geotools draw symbol on overlay - geotools

I'm new to Geotools. I am developing a simple application that shows a map and I would like to dynamically place a bitmap or vector symbol on it (for example to show where the current position is, like in navigation systems).
Now, what I've done already is:
showing a map given one or more shapefile.
center the map on the last inserted position.
add shapes to new layers when needed.
What I need to do is to create an overlay with images at given coordinates on the map area (to be clear, I don't want to generate a raster layer on disk, I just want to paint on the screen).
My guess is that I have to somehow directly use the Graphics2D instance inside JMapPane, is that correct? In this case how can I convert from the geographic coordinates to pixel coordinates on the drawing pane? Or are there some geotools functions/classes that I should be looking for?
Thank you.

Answering myself, since I found the solution.
I did it by extending class org.geotools.map.DirectLayer, which provides a way to define a custom layer by extending its draw(Graphics2D, MapContent) method. Graphic elements are placed at the correct coordinates by using the worldToScreen affine transform provided by geotools. For example, to define a Point2D placed at the current position given real-world coordinates:
AffineTransform worldToScreen = viewport.getWorldToScreen();
Point2D worldPoint = new Point2D.Double(currentPosition.x, currentPosition.y);
Point2D screenPoint = worldToScreen.transform(worldPoint, null);
Once the draw() method is defined, just instantiate and add as a layer to your MapContent instance.

Related

How can i convert a Quad to a Rectangle using Starling on Flash Develop (AS3)?

I wish to use the "intersects" (from Starling) to create a collision, but i don't know how to convert my Quad "player" and my Quad "block" to Rectangles.
Can someone help?
Quad contains a getBounds public method that returns a new rectangle (or an updated one if passed in on the second param), so:
var playerRect:Rectangle = quadPlayer.getBounds(this);
var blockRect:Rectangle = blockPlayer.getBounds(this);
if (playerRect.intersects(blockRect)) {
trace("Collision!");
}
Now, I am using this as I do not know your display list hierarchy and this do not know which coordinate system your quads are in, so adjust accordingly.
http://doc.starling-framework.org/current/starling/display/DisplayObject.html
Transforming coordinates
Within the display tree, each object has its own local coordinate system. If you rotate a container, you rotate that coordinate system - and thus all the children of the container.
Sometimes you need to know where a certain point lies relative to another coordinate system. That's the purpose of the method getTransformationMatrix. It will create a matrix that represents the transformation of a point in one coordinate system to another.
http://doc.starling-framework.org/current/starling/display/Quad.html
getBounds(targetSpace:DisplayObject, out:Rectangle = null):Rectangle
[override] Returns a rectangle that completely encloses the object as it appears in another coordinate system.

Libgdx bullet offset origin

i am using blender to create my models, and loading them into Libgdx, if i create them with the Origin in the center of the model like below and then use this code to create the rigid body, all works fine
Vector3 hescoWallHalfExtents = new Vector3(hescoWall.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);
however if i place the bottom of the model level with the ground like this
then the btRigidbody is offset like this
is there an obvious way that i can offset the height of the rigidbody?
many thanks.
Spriggsy
The center (origin) of the rigid body is the same as the center of mass and therefor an important property for the physics simulation. You could "move" this center using a btCompoundShape if you like, but this will also influence the physics simulation and therefore probably won't give you satisfying results.
Alternatively, you could compensate for the difference of physics origin and visual origin in your btMotionState. For example by setting ModelInstance#transform to the provided worldTransform multiplied by the a Matrix4 instance which contains the offset (use Matrix4#translate for example).
However, this is probably just making it more complex than it needs to be. You could say that the real question is why you want offset the center of model compared to the body? For example, in you second image the center of the model appears to be same as the in the first image. You only moved the Node, basically indicating that you want to provide an initial value for the ModelInstance#transform member. You can achieve this by instantiating the ModelInstance as follows:
modelInstance = new ModelInstance(model, "coneNode", true);
Replace "coneNode" with the name of the node as created it in your modeling application. The last (true) argument tells the ModelInstance to set its transform member to the transformation you've given it in the modeling application. If needed, you can call modelInstance.transform.translate(x, y, z); or modelInstance.transform.trn(x, y, z); to move the modelInstance relative to this transformation.
A more in-depth explanation of this can be found here: http://blog.xoppa.com/loading-a-scene-with-libgdx/
Note that this only works if you're using .g3db or .g3dj files (e.g. using fbx-conv) created from a file format that supports node transformations (e.g. .fbx, but not .obj)

Update dynamic heightmap in Away3d 4.x Broomstick

How do I update my Elevation Object when I change the bimapdata of its height map?
I noticed that getHeightAtPosition() updates to the values of the new bitmap, but the Elevation still looks the same..
(I know it is possible to loop through all vertices in the geometry mesh and adjust them based on the bitmap, but the nice thing with Elevation is that you don't have to do that. If it can adjust to the bitmap on creation it should be able to update..)
Ok, I found the answer on the away 3D forum:
http://away3d.com/forum/viewthread/1110/#3808
Basically, you need to change one line in the Elevation class:
Go to elevation.as and change
private function updateGeometry()
to
public function updateGeometry()
then on the render after you change the parameters call
_elevation.updateGeometry();

Points from Sprite.graphics in AS3

I need to know where the Sprite.graphics start to do some stuff. When I add the sprite to my MovieClip, (x,y) coordinates are (0,0) but I need to know coordinates from Sprite.graphics, not Sprite. There are some images so clarify what I want:
I have this board where user can draw some forms (lines, arrows, polygons, etc.) When the user draw a line, I interpret that Sprite is created (with Sprite.graphics inside it, the real form).
How can I catch the point where Sprite.graphics is created? Actually I can't because Sprite.graphics is read-only.
Thanks!
EDIT: some source code
line = new Sprite();
line.graphics.moveTo(posX,posY);
line.graphics.lineStyle(10);
line.graphics.lineTo(endposX,endposY);
Global.board.addChild(line);
To get the bounds of visual part, you can try:
var bounds: Rectangle = line.getBounds(line);
There is also a getRect() method, but that leaves out space taken by strokes.
You cannot access the graphics data like that. Your best chance would be to save the coordinates posX and posY yourself when the line is being drawn.

Trying to convert openGL to MFC coordinates and having Problems with "gluProject"

To clarify things, what i am trying to do is to get the openGL coordinates and manipulate them in my mfc code. not to get an openGL object. i'm using the mfc to control the position of the objects in the openGL.
Hi, i'm trying to find the naswer on the web and can't find a full solution that i can use and that will work...
I'm developing a MFC project with static picture as the canvas for an openGL class that draw the grphics for my game.
On moush down, i need to retrive a shape coordinate from the openGL class.
I'm looking for a way to convert the openGL coordinates to MFC coordinates but no matter what i try i get junk after using the gluProject or gluUnProject (i've tried to do both ways but non is working)
GLdouble modelMatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
GLdouble projMatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
int viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
POINT mouse; // Stores The X And Y Coords For The Current Mouse Position
GetCursorPos(&mouse); // Gets The Current Cursor Coordinates (Mouse Coordinates)
ScreenToClient(hWnd, &mouse);
GLdouble winX, winY, winZ; // Holds Our X, Y and Z Coordinates
winX; = (float)point.x; // Holds The Mouse X Coordinate
winY; = (float)point.y; // Holds The Mouse Y Coordinate
winY = (float)viewport[3] - winY;
glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
GLdouble posX=s1->getPosX(), posY=s1->getPosY(), posZ=s1->getPosZ(); // Hold The Final Values
gluUnProject( winX, winY, winZ, modelMatrix, projMatrix, viewport, &posX, &posY, &posZ);
gluProject(posX, posY, posZ, modelMatrix, projMatrix, viewport, &winX, &winY, &winZ);
This is just part of the code i've tried. ofcourse not gluProject and gluUnProject together. just had them both here to show.....and i know there is lots of junk over there, its from some of my tries...
p.s. i've tried many many more combinations and examples from the web and nothing seem to work in my case....
Can any one show me what is the right way to do the transformation?
10x
It looks like you're trying to retrieve the object (or objects) that is/are at a particular point. If this is the case, gluProject and/or gluUnProject isn't really a very suitable tool for the task. OpenGL has a selection mode intended specifically for this kind of task.
In typical use, you specify a small square (e.g., 5x5 pixels) around the mouse click spot with gluPickMatrix, set selection mode with glRenderMode, set a buffer with glSwelectBuffer, and then draw your scene. The drawing doesn't go to the screen, but fills the buffer you specified wiyh records of what was drawn within the specified area.