Jump to content
  • Advertisement
Sign in to follow this  
Spinewire

[java] Interactive, Scalable (Vector) Graphics in Java

This topic is 2683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As a hobby, I'm trying to develop a portable 2.5D TBS-like game/editor in Java with an emphasis on scalable graphics for multiple zoom levels and screen sizes. I've explored SVG Salamander, SVG Tiny, and to a lesser extent Batik, but none seem to provide support for a game window with ~100 SVG graphics on the screen at once that can be clicked on with more sophisticated point detection than just a bounding rect for irregular shapes. Since this game will be from an isometric perspective, I'm concerned with click shape accuracy so that the user can easily select items that may overlap bounding rects, but not actual images.

Conversely, the default 2D vector graphics in Java allow more sophisticated point detection with the Shape object, but does not seem to easily allow drawn shapes to be imported/exported for editing in an external application without rasterizing. (The visual style will be minimalistic, but I still do not want to write every image in code.)

Finally, I've tried Slick, but the SVG support is closely tied with Inkscape (which I do not find to be very user-friendly) and does not seem wholly reliable. Ideally I'd like to be able to import graphics from Google Docs diagrams exported as SVGs, since that is the most accessible free SVG editor I've found.

Is there any solution that can import simple SVGs (or another vector format), display them on the screen, and give me a Shape object for their bounding polygons?

EDIT: I'm toying with the idea of loading each SVG image at startup and rasterizing each into a BufferedImage (using Batik or preferably SVG Salamander since it renders better IMO), then using those BufferedImages for actually displaying the graphics and doing the per-pixel point click detection. This will, however, require me to either a) limit zooming to one of k possible scale factors and pre-rasterize a copy of each image for each zoom level, b) re-rasterize each image on the screen and completely repaint every time the zoom level changes, or c) render the images straight from the SVG data, but rasterize on-demand if the user clicks within the image's rect to determine per-pixel click accuracy. Does this approach seem feasible, or horribly slow? (I'd rather do b or c since they won't lock my possible zoom scales). Edited by Spinewire

Share this post


Link to post
Share on other sites
Advertisement
Heres a cool trick you can program yourself, If you want perfect click detection, you can use one of these 2 algorithims

1. If they are regular polygons calculate the dot product of the point you clicked on with the vertexs of the polygon if they add to 360 then you clicked inside that polygon since every regular polygon will give you a value of 360degree or 2*pi whichever convention u prefer.

2. Another algorithim you can do is draw a ray from outside the polygon to the point you clicked on, if the ray hits the lines your vertexes created a ODD number of times then you clicked inside the polygon, other wise
you clicked outside that polygon (if it hits 0 walls then that counts as your outside the polygon)

the second method is really cool because it works with any closed polygon and does not have to be a regular sided one. Hope that information helps if, if you want me to elaborate please tell.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!