Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (727)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (796)
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  
  Axonometric Projection?  (Read 2295 times)
0 Members and 1 Guest are viewing this topic.
Offline Coldstream24

JGO Ninja


Medals: 73
Projects: 1
Exp: 4 years


You can fill that void inside with programming, but you'll never return a value.


« Posted 2017-03-07 06:01:23 »

Hi all
I've been on and off trying to figure out a simple system to draw textures on top of axonometric tiles (I think that's the right term)?
The intended view is tiles of 64 pixels width and 31 height (on the top face). I have managed to get a view working that's comprised of filled polygon faces:

The gaps between faces is something I'll try to work out (I was following a page that suggested this view requires the height to be 1 pixel less than half of the width), but it gives that as a result.
Anyway, here's what happens when I try to draw a texture on top of it:

This is using the following code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
                 if (!wireframe) {
                    g2.setColor(colors[Math.min(colors.length -1, tileID)]);
                    g2.fillPolygon(tFace);
                    g2.rotate(Math.atan(0.5));
                    //g2.translate(-projHalfWidth / 2, 0);
                    g2.drawImage(Game.getTileset().getDefinition(t.chunks[cX][cY].tiles[tX][tY][z].tileID).tex, 0, 0, projWidth / 2, projHeight, null);
                } else {
                    g2.setColor(Color.red);
                    g2.drawPolygon(tFace);
                }

I read somewhere that using Math.atan(0.5) would yield the correct angle for rendering, and while it does partially seem to be the case, I'm left scratching my head over how I can fill the top face with this image correctly? Mostly, I've experimented with translation, shearing, and different angles, but to no effect. I really can't figure this out.

I would appreciate any help Smiley

My website: http://www.onedropgames.com/
My soundcloud: http://www.soundcloud.com/coldstream24
Creator of the Morningside Engine, co-founder of Onedrop Games.
Offline LiquidNitrogen
« Reply #1 - Posted 2017-03-07 10:01:27 »

I was doing something similar to that recently. First I rotated a square by 45 degrees, then scaled its vertical size by 0.5, then translated it to the correct position. I don't think you need atan in there, its just a 45 degree angle.
Offline Coldstream24

JGO Ninja


Medals: 73
Projects: 1
Exp: 4 years


You can fill that void inside with programming, but you'll never return a value.


« Reply #2 - Posted 2017-03-07 10:56:31 »

Thanks for that, I'll give it a try as soon as I can Smiley
Would that give a correct result for 1:2 projection?

edit: I'm guessing it would, that's a silly question. It's late Tongue

My website: http://www.onedropgames.com/
My soundcloud: http://www.soundcloud.com/coldstream24
Creator of the Morningside Engine, co-founder of Onedrop Games.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2017-03-07 14:30:19 »

LiquidNitrogen has the right idea; what were you even thinking with `Math.atan(0.5)`?

Note that the order of the transforms matter (scaling, rotating, translating); May vary between implementations/engines.

Demo I made out of boredom: https://jsbin.com/gadevexuwi/1/edit?html,output

Offline Coldstream24

JGO Ninja


Medals: 73
Projects: 1
Exp: 4 years


You can fill that void inside with programming, but you'll never return a value.


« Reply #4 - Posted 2017-03-07 19:20:51 »

I was following the advice of a document I found online that suggested it as some sort of golden number. I must have misinterpreted it, or it may have been wrong.

My website: http://www.onedropgames.com/
My soundcloud: http://www.soundcloud.com/coldstream24
Creator of the Morningside Engine, co-founder of Onedrop Games.
Offline KaiHH

JGO Kernel


Medals: 409



« Reply #5 - Posted 2017-03-07 19:29:11 »

Well, that article may have been correct, and atan(0.5) does make sense if we think about how it was derived and what the author wanted to compute with it:
If we assume the length of the projected tile along the X axis to be twice as large compared to the projected height of the tile along the Y axis, then the perceived angle of the tile (when seen in the axonometric projection) can be derived just like that:
tan(angle) = (opposite leg / adjacent leg)
where opposite leg is the length of the projected tile along the Y axis and adjacent leg is the length along the X axis.
Since we assume the length along the X axis to be twice as long as the length along the Y axis, this ratio is 0.5.
So, tan(angle) = 0.5
Since the author may have wanted to compute the actual angle between the X axis and the side of projected tile, we would have to use the inverse of tan, which is atan: atan(tan(angle)) = atan(0.5) ≈ 26.6 degrees.
Offline LiquidNitrogen
« Reply #6 - Posted 2017-03-08 02:26:30 »

It's also interesting to note that you don't have to stick to 45 degrees, although it does look most correct.. you can use whatever rotation angle you want, which gives you the ability to view the scene from any angle and smoothly rotate the camera. It can be difficult to make objects on top of the map fit in properly with rotation however, but the option is there.
Offline cygnus

Senior Newbie


Exp: 1 year



« Reply #7 - Posted 2017-04-09 15:55:42 »

I may be totally wrong here, but shear seems like the option to use. Maybe something like g2d.shear(texture.width, 0)?
Pages: [1]
  ignore  |  Print  
 
 

 
Archive (294 views)
2017-04-27 17:45:51

buddyBro (483 views)
2017-04-05 03:38:00

CopyableCougar4 (927 views)
2017-03-24 15:39:42

theagentd (941 views)
2017-03-24 15:32:08

Rule (952 views)
2017-03-19 12:43:22

Rule (921 views)
2017-03-19 12:42:17

Rule (922 views)
2017-03-19 12:36:21

theagentd (984 views)
2017-03-16 05:07:07

theagentd (897 views)
2017-03-15 22:37:06

theagentd (693 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!