Transformation Matrices

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.
Mikepicker
Prole
Posts: 6
Joined: Thu Aug 22, 2013 5:12 pm

Transformation Matrices

Post by Mikepicker »

Hi everyone,

firstly I wish to thank the LOVE creators, I'm learning to use this game engine but I feel already quite comfortable with it.

Here's my problem:
I'm developing a little fighting style game (a "street fighter" cartoon remake). Every player is composed of 5 separated images (I've used a spritesheet of course): body, two legs and two hands.
When a player goes to the right side of the screen (facing the enemy to his left) I have to reverse the player, so, in my love.draw() I have:

Code: Select all

love.graphics.push()
	
	if (self.reversed) then

		love.graphics.translate(pl.body.x + pl.body.width/2, pl.body.y + pl.body.height/2)
		love.graphics.scale(-1,1)
		love.graphics.translate(-(pl.body.x + pl.body.width/2), -(pl.body.y + pl.body.height/2))
	
	end

--Draw Body parts--

love.graphics.pop()
So I can see the player correctly reversed. But the problem is that the original hand coordinates are not modified! So I can't check the collisions properly (since a player is "hit" when the enemy hand hit his body)!

Could you suggest me a nice solution to this?

Thank you in advance
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Transformation Matrices

Post by Robin »

When reversing, can't you simply change the positions of the body parts?

Then you can leave push, pop, translate and scale out of it, and draw the body parts simply like this:

Code: Select all

love.graphics.draw(self.left_arm.img, self.left_arm.x, self.left_arm.y, 0, self.reversed and -1 or 1)
(The fifth argument to love.graphics.draw is the scale on the x-axis.)
Help us help you: attach a .love.
Mikepicker
Prole
Posts: 6
Joined: Thu Aug 22, 2013 5:12 pm

Re: Transformation Matrices

Post by Mikepicker »

Thank you for your answer!

Yes, I could do that, but since I am writing many animations I should write a "double" code: one for the normal animations, and one for the reversed one. I would like to write code once, then apply something (transformation matrix?) to automatically reverse it. Do you think is it possible?

Thanks
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Transformation Matrices

Post by Robin »

It really depends on what you mean and how you've implemented. We can't be more specific than that until you upload a .love of your game. (Which is, incidentally, one of the rules for asking for help here.)
Help us help you: attach a .love.
Mikepicker
Prole
Posts: 6
Joined: Thu Aug 22, 2013 5:12 pm

Re: Transformation Matrices

Post by Mikepicker »

I can't upload my love file due to this error: "Sorry, the board attachment quota has been reached."
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Transformation Matrices

Post by Robin »

In that case, you can upload it somewhere else and link it here.
Help us help you: attach a .love.
Mikepicker
Prole
Posts: 6
Joined: Thu Aug 22, 2013 5:12 pm

Re: Transformation Matrices

Post by Mikepicker »

https://www.dropbox.com/s/3hnlgrz7cp75i ... umble.love

Here it is :)
As you can see, there are two animations, which are totally equals, but only reversed.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Transformation Matrices

Post by Robin »

Okay... I have no suggestion right now. (Maybe someone else would like to jump in here?)
Help us help you: attach a .love.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Transformation Matrices

Post by vrld »

Mikepicker wrote:So I can see the player correctly reversed. But the problem is that the original hand coordinates are not modified! So I can't check the collisions properly (since a player is "hit" when the enemy hand hit his body)!
This is expected (and in fact wanted): love.graphics.translate and friends only change how things are drawn on the screen, but they don't dare to touch the underlying "world".
Mikepicker wrote:Could you suggest me a nice solution to this?
I guess you can go at least two routes:
  1. Don't flip in the animation, but the actual coordinates of the body parts. I.e. instead of doing (in player_states.lua)

    Code: Select all

    if self.player.lookAt == "left" then
        self.anim:setReverse(true)
    else
       self.anim:setReverse(false)
    end
    do something like this:

    Code: Select all

    if self.player.lookAt ~= self.player.lookAtLast then
        self:flip() -- flips all coordinates
        self.player.lookAtLast = self.player.lookAt
    end
  2. Have symmetric collision shapes, i.e. if one player punches, look for collisions to the left and to the right of the player. Of course you will run into problems when you want players to be able to punch each other in the back, so you should probably go with (1) in the long run.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Mikepicker
Prole
Posts: 6
Joined: Thu Aug 22, 2013 5:12 pm

Re: Transformation Matrices

Post by Mikepicker »

Perfect! Thank you so much for the suggestion! One last question:
is there something like Duff-Porter (http://ssp.impulsetrain.com/2013-03-17_ ... Modes.html) in order to handle image overlay? (This because legs have to stay behind the body, but at the same time when player kicks the opponent, they have to be in front of the opponent body)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests