Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mini Universe?  (Read 2900 times)
0 Members and 1 Guest are viewing this topic.
Offline SwampChicken
« Posted 2013-07-01 08:52:20 »


Requirement:
I want to use pure Java (1.6) with no additional frameworks.

Idea:
Swing? frame, black background.

A universe of a 100 'stars' (to begin with) which can simply show as white pixels for now (ie: no art)

Zoom in and out using mousewheel.

Stars/pixels are selectable via mouse click (perhaps highlight them with some sort of halo/ring, or paint as different colour?)

What sort of structures should I use to:
Hold the spatial data for the stars? (Keeping in mind that I may require 'clipping' to represent P.O.V when zoomed in/out unless that can be done another way?)
Offline HeroesGraveDev

JGO Kernel


Medals: 215
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #1 - Posted 2013-07-01 08:58:31 »

We need more info than that. Smiley

Offline SwampChicken
« Reply #2 - Posted 2013-07-01 09:59:32 »

HeroesGraveDev,
I'm not sure if there's anymore that I can say really. Let's say I wanted to map my universe as 5 stars in random locations. A basic 2D, looking down kinda map...

When I'm zoomed out I can see 5 pixels in their corresponding locations, but if I click on one star/pixel and zoom in (using the mousewheel), the distance between my selected star and the others will increase to the point where they will slide out from view, leaving just one star in the panel.

This isn't a an image zoom, but I can understand why it sounds like one, in that star/pixel doesn't get bigger...also there is no image.
I guess all I am trying to do is manipulating the actual distances between stars/pixels but I have no idea on what sort of data structure I would use to enable me to do this.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nerb
« Reply #3 - Posted 2013-07-01 10:24:35 »

Give your panel a 'zoom factor' variable, where a factor of 1 is completely zoomed out, and factors >1 are zoomed in.

When it comes to rendering your stars, calculate their screen position using their x/y pos, the zoom factor, and the position of the centre of the screen. It would look something like this I think:

screenX = (starX - cameraX) * zoomFactor

Where:
screenX - the 'on screen' position of the star, in screen/panel coordinates.
starX - the x position of your star in universe coordinates.
cameraX - the x position of the centre of your screen/'camera', in universe coordinates.
zoomFactor - the zoom factor as described above.

In theory, as you increase the zoom factor, the screen distance between the stars should increase, but the stars themselves won't be resized (I think that's what you are trying to do?). I haven't tried this, but it should work.

EDIT: You'll need to somehow link camera panning with the zoom in/out function, so that your camera pans towards the selected star when zooming in, otherwise it too will disappear off-screen.

Hope it helps.
nerb.

Offline SwampChicken
« Reply #4 - Posted 2013-07-02 17:53:40 »

Nerb,
Any thoughts on what units I should use to represent distance bewteen stars?
Offline sproingie

JGO Kernel


Medals: 200



« Reply #5 - Posted 2013-07-02 23:30:23 »

either parsecs or light years seems like a reasonable unit.

Offline nerb
« Reply #6 - Posted 2013-07-03 03:16:24 »

I think it will really depend on what you are trying to accomplish.

If you're trying to create a seemingly realistic model of the universe, then as sproingie has mentioned, light years or parsecs could be a good choice. If you are dealing with very large or very small numbers you will have to be constantly aware of the limitations of computer/binary arithmetic; in particular overflow and floating point accuracy. It may be more pertinent if you are going to model any kind of motion, such as orbits or spacecraft.

If on the other hand it is a 'fictional' universe which will be used in a game, then I wouldn't get too caught up on units at all. Instead I'd be focusing on making it look good & play well, using arbitrary units that 'fit' the game and avoid the aforementioned arithmetic problems. For example, you could give the stars x & y positions between 0 - 1024, whatever units that may be. You could then find an appropriate velocity for any moving objects to give the effect you want, i.e. if you wanted fast-paced gameplay, or something more slow-paced.

So in summary, your choice of units should be influenced by the desired outcome.

nerb.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #7 - Posted 2013-07-03 03:46:02 »

ArrayList

position: x, y, z

Draw at a different radius depending on distance from the camera. To be cool, draw as a line based upon the change in the camera's position and the star's position. A la Star Wars.

That's how I did this:
http://otcsw.com/files/WarpField.swf

The main difference is that you need to do a little bit more geometry since my camera is on a one-dimensional rail.

See my work:
OTC Software
Offline relminator
« Reply #8 - Posted 2013-07-03 13:46:16 »

You could do this easily if you know how 3d projection works.

Data for the stars are in 3d(xyz)
Project to screen when drawing
Zooming would be a simple camera movement on the z-axis.
Offline relminator
« Reply #9 - Posted 2013-07-03 13:49:51 »

You could do this easily if you know how 3d projection works.

Data for the stars are in 3d(xyz)
Project to screen when drawing
Zooming would be a simple camera movement on the z-axis.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #10 - Posted 2013-07-03 18:57:32 »

You could do this easily if you know how 3d projection works.

Data for the stars are in 3d(xyz)
Project to screen when drawing
Zooming would be a simple camera movement on the z-axis.
Im pretty sure that zooming is when you lower the cameras FOV, not moving closer.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline sproingie

JGO Kernel


Medals: 200



« Reply #11 - Posted 2013-07-03 19:13:01 »

Im pretty sure that zooming is when you lower the cameras FOV, not moving closer.

Technically speaking, yes -- moving the camera closer or further is called "dollying".  We're not film directors, so around here "zooming" is just a vague term for filling the frame with the subject regardless of how.  

Besides, when it comes to stellar scales, you're not going to want to use the camera alone for changing the scope from star cluster to solar system to planetary system, you'll want to actually change the models themselves as the level of detail changes.  I presume given your scale of 100 stars that you're making a game, so fake the scales and proportions so they're actually fun.  Take a look at how games like Master Of Orion and Galactic Civilizations do it.


Offline relminator
« Reply #12 - Posted 2013-07-04 05:15:31 »

You could do this easily if you know how 3d projection works.

Data for the stars are in 3d(xyz)
Project to screen when drawing
Zooming would be a simple camera movement on the z-axis.
Im pretty sure that zooming is when you lower the cameras FOV, not moving closer.

I'm pretty sure it would almost give the same effect.

Sigh...

www.rel.phatcode.net/mytutes/3dtutes/chapter1/chapter1.htm
Offline wessles

JGO Ninja


Medals: 49
Projects: 4
Exp: 3 years


Loves games, loves coding; this is only logical.


« Reply #13 - Posted 2013-07-05 02:00:36 »

Yes, but with lowering the fov, you don't risk the camera getting inside an object.

You don't know nerdiness yet; you haven't even met me!
www.wessles.com
Offline sproingie

JGO Kernel


Medals: 200



« Reply #14 - Posted 2013-07-05 02:40:39 »

They're pretty similar until you start applying depth-of-field effects.  Lowering the FOV deepens the depth of field and blurs things outside of the focal plane, putting all the attention on the subject.  Dollying just moves you in closer, and objects in front simply move out of frame behind the camera.  They're not interchangeable.  While narrowing the FOV in a follow shot is pretty standard to convey a sense of speed, playing around with rapid FOV changes, e.g. "zoomers", is considered awesomely cheesy.

Again, not that it matters at all if you're making a galactic 4x type game since you're not going to want to use the camera to change scales.

Offline relminator
« Reply #15 - Posted 2013-07-05 04:57:48 »

Yes, but with lowering the fov, you don't risk the camera getting inside an object.

Yeah, only you get "fish-eye" in this case.
Offline lcass
« Reply #16 - Posted 2013-09-19 22:37:23 »

For this seeing as you may want to expand it in the future use an arraylist its more dynamic.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!