Isometric Engine (RCT style) - Major update 14.Sep

This a small sample of an isometric game engine.

http://www.jonask.com/pro/img/iso.png

Download: www.jonask.com/pro/iso.zip
I’ve been working and improving on different iso-engines over the last year, and this is small but a very apt
sample of the isometric effect.

It is a work in progress, and in this sample i have disabled all other tiles than the flat.
I havn’t written in any UI to change the tilt of the tiles (like you can in rollercoaster tycoon),
but the engine supports it. If you want any other tiles you have to hardcode them in. for now.
Im working on it.

Anyhow, this is basiclly just to show off what i’ve done, and to see if anyone is interested in the code for their own projects.
Any kind of criticism or suggestions are allways welcome too =)

Download: www.jonask.com/pro/iso.zip

It works nicely, good job :slight_smile:

I get the following error when attempting to run it. I’ll try recompiling the classes, just thought you’d be interested.

This is with java -version:

java version “1.4.0”
Java™ 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot™ Client VM (build 1.4.0-b92, mixed mode)

Exception in thread “main” java.lang.UnsupportedClassVersionError: misc/MainClass (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)

same exception here, I hope it’s not 1.5 only

I’m sorry guys, it IS 1.5. But why not upgrade?

Because then I’d have to expect any players of a game that I wrote with your engine to upgrade.

(Incidently, I have both installed and its your isometric engine is very nice :))

Kev

Doesn’t find the tiles.gif file on Linux for some strange reason…

Thanks for the kind words guys, I’d glady send the code if anyone is interested.
Regarding the linux issue it is probably related to my image loading algorythm.
It’s not well written. doesn’t work in jar files, and i suspect that is why it’s not working
on your platform as well

… and the easy way would be fiddling with the OpenGL Projection Matrix! :wink: (me == lazy)

The projection matrix would be like:
(this one zapped a few of my brainscells while creating)


1.0,   0.0,  -1.0,   0.0   // x
0.5,   1.0,   0.5,   0.0   // y
0.0,  -0.05,  0.0,   0.0   // depth
0.0,   0.0,   0.0,   1.0   // [nothing]

Scale a bit (in model-space), transpose and upload to gfx-card!

~~

Pros:

  • any shape of any object is supported
  • hardware accelerated gfx
  • depth-buffer to reduce fills

Cons:

  • less 1337!

~~

http://home.hccnet.nl/s.balk/static/isometric.png

~~

… ;D

I really like your engine better. Rendering that in software is much harder than my ‘quick’ hack. Well done!

That is really interesting. I never got around to toying with hardware accelerators.
Would you mind sharing your code?

but i gotta add, the pixel method I use can handle any shape too :wink:

This is the Projection Matrix:


1.0,   0.0,  -1.0,   0.0   // x
0.5,   1.0,   0.5,   0.0   // y
0.0,  -0.05,  0.0,   0.0   // depth
0.0,   0.0,   0.0,   1.0   // [nothing]

This is the transposed Matrix:
(OpenGL works with transposed matrices)


// x    y   depth  [nothing]
 1.0,   0.5,  0.0,   0.0
 0.0,   1.0, -0.05,  0.0
-1.0,  0.5,  0.0,   0.0
 0.0,   0.0,  0.0,   1.0

Store that in a FloatBuffer:


FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(4*4); // LWJGLs way
<or do>
FloatBuffer matrixBuffer = ByteBuffer.allocateDirect(4*4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer().; // own way

matrixBuffer.put(new float[]{1.0F, 0.5F, 0.0F, 0.0F, 0.0F, 1.0F, -0.05F, 0.0F, -1.0F, 0.5F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F});
matrixBuffer.flip();

Send to gfx-card:


glMatrixMode(GL_PROJECTION);
glLoadMatrix(matrixBuffer);


// scale down projection a bit, like factor 10
// otherwise a flat 1x1 quad kinda fills the screen
float s = 0.1F;
glScalef(s, s, s);


// switch to model-view matrix for further transformations
glMatrixMode(GL_MODELVIEW);

Well, for everything else you need to know your OpenGL :wink:

To be honest I’ve never heard of Isometric stuff done in the Projection Matrix, but I thought it would be worth the adventure of figuring out how matrix-calculations are actually performed and trying to create my own matrix after I figured out the formulas of real->iso. It’s always fun to share such stuff :slight_smile:

Yeah, i havnt done any openGL in java yet. I guess i’ve allways been charmed by software rendering :wink:

I’ll upload the formulas i use for transforming real to isometric coordinates and back…
I never thought of expressing them on matrix form, but that might be a good way to go.
Id imagine its more optimized.

Anyways, its on my laptop so i cant access it right now. stay tuned

Well, it’s only more optimized when using hardware-acceleration.

As there are quite a few occurences of 0.0 in that matrix, you are constantly multiplying values by 0.0, which can be skipped if you use your own formulas. (Edit: same for 1.0 ofocurse)

Thanks for the GL isometric mode stuff, seem very useful!

Kev

Correction:

This is the Projection Matrix:


1.0,   0.0,  -1.0,   0.0   // x
0.5,   2.0,   0.5,   0.0   // y
0.0,  -0.05,  0.0,   0.0   // depth
0.0,   0.0,   0.0,   1.0   // [nothing]

This is the transposed Matrix:
(OpenGL works with transposed matrices)


// x    y   depth  [nothing]
 1.0,   0.5,  0.0,   0.0
 0.0,   2.0, -0.05,  0.0
-1.0,   0.5,  0.0,   0.0
 0.0,   0.0,  0.0,   1.0

I changed the 1.0 @ [1][1] to 2.0. Otherwise everything is squeezed on the y-axis.

Note that that -0.05 (for depth) is pretty randomly chosen, it works for me, if it doesn’t for you - when your near/far planes are off - adjust it a bit.

Ah, that explain why my chaps look a little stocky :slight_smile:

http://www.cokeandcode.com/asd/screenshots/isoasd.png

I’ll adjust tonight, thanks for the update.

Only thing I had to change was to flip round the axis since I’m use Z as up/down not Y (just because I’m working in 2D really, honest).

Kev

I’ve done some real improvment on the engine.
alot of it is under the hood, like GUI-mouse handling, but one thing
i just know youre gonna like is the lanscapting tool.

This is really getting somewhere =)

Err…could u explain how it works?Maybe send some code.
I want to start coding something like this myself, but i dont know how to detect mouse entering over a tile…Plz help dude

Sure i’ll help.

But my current GUI system i rather complex. I’ll try to explain the flow…

The game runs in a seperate thread from the frame window.

Whenever a key is pressed or released or mouse moved or clikced functions are called in the frame class.
These functions store mouse and keyboard info in local variables.

Then when ever its time to update the GUI the mainloop sends these mouse states into a GUI class.
the GUI class now determins what so called GUIElement the mouse is over.

All objects you see drawn inherit from this GUIelement class, so that every object can get mouse focus and stuff.
All the elements are stored in an ArrayList and drawn in order.
When determining what object the mouse is over you go backwards (so that the upper object is checked first) through this list,
and if the mouse IS over the element you’re at now, stop reversing.
All GUIElements are square, so determining if the mouse is over it is easy. check if the mousex and mousey are within its (x,y) and (x+w,y+h)

Checking the objects in the world(buildings, tiles, people, whatever) is slightly more complicated since they are not rectangular.
But if that is what you wanna do i can show you how.

Need any code too?

Yeah, it would be great ! ::slight_smile: