Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Fake 3d with only Java 2d  (Read 3300 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Posted 2012-08-25 06:50:32 »

I'm trying to make an applet using only Java 2d
There's this one tiny pseudo-element I want to implement
I want to be able to "stretch" a rectangle image in such a way that I can acheive an effect similar to this:



Now, the math of where the corners of the rectangle go is trivial. I know how to do that. But how can I acheive an effect like this with Java 2D, where I can manipulate each corner?
Is there even a way to do it? I couldn't find one, but maybe I'm not searching for the right keywords.

Thanks
Offline ctomni231

JGO Wizard


Medals: 98
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #1 - Posted 2012-08-25 06:54:08 »

Couldn't you just use lines to achieve the effect you are looking for, or is there a real reason it has to be rectangles?

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #2 - Posted 2012-08-25 07:05:36 »

Well, I have pretty floor tile images that I'd like to use
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Man
« Reply #3 - Posted 2012-08-25 07:13:51 »

You could try this Graphics.drawPolygon(int[]. int[]. int)
Never mind I read "stretch a rectangle" instead of "stretch a rectangle image". What about this instead drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #4 - Posted 2012-08-25 07:23:35 »

That's a useful function, but I'm not just trying to draw a polygon, I'm trying to draw a polygon with an image. Like the tiles on the floor in the SNES Mario Kart



The tiles on the ground are stretched images in the manner I'm trying to achieve
Offline Z-Man
« Reply #5 - Posted 2012-08-25 07:24:52 »

Ya, I misread your OP persecutioncomplex I edited my post when I saw that.
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #6 - Posted 2012-08-25 07:33:13 »

That method does allow me to stretch an image, but only as a rectangle with 90 degree angles, not a quadrilateral that can be used to obtain a 3d effect. It's the difference between this
http://i1.allaboutvision.com/i/amsler-grid.gif
and this
Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2012-08-25 07:55:52 »

What you're looking for is a perspective transformation, and java2d is not going to give you one of those -- it only has affine transforms.  So you're looking at doing it by hand, which I suspect is what they did for that SNES game there.

See this thread: http://www.java-gaming.org/index.php/topic,8803.  It mentions JAI having perspective transforms, but JAI is nothing close to real time.

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #8 - Posted 2012-08-25 08:39:52 »

What you're looking for is a perspective transformation, and java2d is not going to give you one of those -- it only has affine transforms.  So you're looking at doing it by hand, which I suspect is what they did for that SNES game there.

See this thread: http://www.java-gaming.org/index.php/topic,8803.  It mentions JAI having perspective transforms, but JAI is nothing close to real time.



Ah well, I guess I'll just stick with the solid color polygons. It'll look good enough.
Offline oByhring

Senior Newbie


Medals: 1



« Reply #9 - Posted 2012-08-25 11:29:42 »

I haven't used java2d alot, but would something like this be possible?

Create an Image object 'ground' and draw all the ground tiles on this Image.

Create a new Image object 'groundOnScreen' and individually map each pixel on 'groundOnScreen' to a pixel (or some value based on nearby pixels) on 'ground'.

I made a quick illustration is paint:



Just mindstorming here, I don't know if you could actually do this with java2d :x
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #10 - Posted 2012-08-25 12:29:32 »

ah yes "mode 7"

would be really interested to see what you come up with

Offline keldon85

Senior Member


Medals: 1



« Reply #11 - Posted 2012-08-25 13:33:13 »

Oh cool ... I also created exactly this many years ago (like 2006).

I pretty much gave it Nintendo GBA registers and a scanline "interrupt" so that you could quite easily put Mode 7 code into it with the same arithmetic as the GBA hardware, it's tile mode too so if you'd like the code give me a shout and I'll github it. here it is: https://github.com/keldon85-avasopht/stroll

Edit: Hmm, give me a minute, I'm just creating the repositories, etc. It comes with a demonstration of Tetris, which rotates the background mode 7 style.

p.s. it's all software rendered.

Offline DrZoidberg

Senior Member


Medals: 15



« Reply #12 - Posted 2012-08-25 19:34:44 »

By using the matrix described on this page
http://chrisjones.id.au/Ellipses/ellipse.html
you can project any image onto any rectangle in 3D space.
I used that technique once in a software renderer that I mentioned in this thread
http://www.java-gaming.org/topics/2d-rendering-but-with-a-3d-coordinate-system/26733/msg/237578/view.html#msg237578
Offline Roquen
« Reply #13 - Posted 2012-08-25 20:45:35 »

I'd be easy just to do it in software.  Each scanline is constant du & dv.
Offline keldon85

Senior Member


Medals: 1



« Reply #14 - Posted 2012-08-25 22:56:14 »

I'd be easy just to do it in software.  Each scanline is constant du & dv.

That's exactly what my code above is. It's a scanline renderer that imitates the GBA/SNES's gfx hardware registers so that you can use mode7 code/calculations. The graphics API provides a HBL and VBL callback so that you can do all the types of tricks used for mode7 Smiley Plus it comes with example code that demonstrates mode7 x-axis rotations.

Check it out. And if you want more info in the maths, check out this awesome Mode 7 tutorial.

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.

CogWheelz (12 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!