[SOLVED] Rotating a "tile map" where individual tiles rotate

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
illd
Prole
Posts: 4
Joined: Fri Aug 14, 2020 11:12 pm

[SOLVED] Rotating a "tile map" where individual tiles rotate

Post by illd »

Hi folks,

I'm fairly new to LOVE and graphics in general. I want to be able to design some "models" in MagicaVoxel or Goxel and use them for a pseudo-3d effect when the camera rotation changes. It works for single sprites, but a naive "tile set" implementation shows where my knowledge falls apart.

Basically, I:

- dumped the model files to an image (eg 32*8 x 32)
- load each as part of an arrayImage
- set quads to each section of individual images that are the stacks of each model (eg 32x32 8 times, stacking up)
- create a SpriteBatch from the arrayImage
- add layers that references the specified textures & quads so that the sections of each image are stacked

When I rotate the camera, the images properly 'rotate' in the sense that you can see the pseudo-3d effect, but in order to do that I have to pass the rotation of the camera to `:setLayer`. This causes the whole tile to be rotated (obviously).

The issue with this is that the tiles aren't rotated 'as a set'. So if I have a tile set [(x0,y0 1), (x0,y32 2)] and the camera is rotated, they are drawn independently instead of rotated as a group. If I remove the rotation factor and w2s and just use `gamera.draw` after rotating, they're drawn together but again, no rotation (so no "neat effect").

I'm not sure how to maintain this perspective trickery _and_ rotate the tiles as a group.

Does anyone have suggestions on how to do this properly? I feel like I'm just lacking some basic 3d-2d knowledge that would make this work.


Note: I will attach a .love file that demonstrates this. It's probably easier to see the details if you zoom in (mousewheel up), and rotating is done by holding down left mouse button and moving left<->right. It's a bad implementation right now so rotating too far draws the tiles out of view, but you can see the perspective change with just tiny rotations. I apologize if this is difficult to see!

(edit: s/psuedo/pseudo/g)
Attachments
rotate.love
example
(4.26 KiB) Downloaded 161 times
Last edited by illd on Sat Aug 15, 2020 8:32 pm, edited 2 times in total.
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: Rotating a "tile map" where individual tiles rotate

Post by sphyrth »

By any chance you mean Mode7?
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Rotating a "tile map" where individual tiles rotate

Post by pgimeno »

How about having one spritebatch per layer? Then you draw all layers from bottom to top, doing a translation for each before calling gamera:draw().

Edit: Proof of concept attached (replaces your main.lua).
Attachments
main.lua
(4.27 KiB) Downloaded 140 times
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Rotating a "tile map" where individual tiles rotate

Post by zorg »

Also, pseudo, not psuedo. ;)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
illd
Prole
Posts: 4
Joined: Fri Aug 14, 2020 11:12 pm

Re: Rotating a "tile map" where individual tiles rotate

Post by illd »

zorg wrote: Sat Aug 15, 2020 7:22 pm Also, pseudo, not psuedo. ;)
Wow, this is embarassing, lol. Thank you.
sphyrth wrote: Sat Aug 15, 2020 11:00 am By any chance you mean Mode7?
I haven't heard of this, actually. I'm new to a lot of the concepts here so I'm not exactly sure what I'm going for yet, just trying to understand some basics. But thank you - I will be watching this video closely.
pgimeno wrote: Sat Aug 15, 2020 11:30 am How about having one spritebatch per layer? Then you draw all layers from bottom to top, doing a translation for each before calling gamera:draw().

Edit: Proof of concept attached (replaces your main.lua).
pgimeno - THANK YOU. This is exactly what I was attempting to do. I sincerely appreciate you taking a look and writing this example, I will refactor my code to use this.

Future reader: this is what pgimeno's PoC does.
@pgimeno's PoC
@pgimeno's PoC
tLP5kL6Ou6.gif (2.9 MiB) Viewed 2877 times
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests