you can see if I did anything wrong, but explaining what the function does will probably be easier, :) I'm not used to matrices with another row/column other than their orientation, explanation on how inverse() and transformPoint(), and getTransform() handle the position(and maybe they handle scale too, instead of just scaling the orientation?) coordinates would help alot :D
bool Window::FishyCollision(MainFish* Fishy, EnemyFish* Fish){
if (Fish->_Scale > Fishy->_Scale){
// code here works
}else{
// invert the transform, sp that when applied, world coordinates of EnemyFish
// become relative coordinates to MainFish
sf::Transform transform = Fishy->_Sprite.getTransform().getInverse();
// set up corners of the EnemyFish, hard-coded numbers are positions in the image
// where the bounding box is
sf::Vector2<float> Min = transform.transformPoint(sf::Vector2<float>(12,6)*Fish->_Scale+Fish->_MinCornerPos);
sf::Vector2<float> Max = transform.transformPoint(sf::Vector2<float>(240,94)*Fish->_Scale+Fish->_MinCornerPos);
sf::Vector2<float> C1 = transform.transformPoint(sf::Vector2<float>(12,94)*Fish->_Scale+Fish->_MinCornerPos);
sf::Vector2<float> C2 = transform.transformPoint(sf::Vector2<float>(240,6)*Fish->_Scale+Fish->_MinCornerPos);
// set up corners of the Main Fish
sf::Vector2<float> FishyMin = sf::Vector2<float>(12,6)*Fishy->_Scale;
sf::Vector2<float> FishyMax = sf::Vector2<float>(240,94)*Fishy->_Scale;
/* check corners against each other, in a simple smaller-lesser than check, this part was omitted
at this point, FishyMin, and FishyMax are as expected, but the corners of EnemyFish are
definitely way off, so maybe I did something wrong in applying the ransformation,
there is too much unexplained on how the matrix handles it's position coordinates,
so guessing what I did wrong is near impossible, I gave it expected numbers, but got weird
effects, MainFish corner coordinates are at origin of the upper left corner, EnemyFish corner
coordinates are at origin 0,0 being global
*/
}
return false;
}
Maybe you need to read more about matrices, there's nothing special in SFML, just the regular matrix operations that you can find in all other graphics libraries. Nothing fancy. And of course everything has widely been tested and works perfectly.
I asked for a complete and minimal code, in bold characters, because I can't help you with this small piece of code. It will take ages before we understand each other 100%. Please write a new simple code, that shows your problem and only it. No need to have fishes in it ;)
And while you do this, I'll try to guess what your problem is: your transform is the inverse transform of an entity, therefore it converts world coordinates to the local coordinate system of the entity. But what you transform doesn't look like world coordinates ((12, 6), (240, 94)), it rather looks like it is local to the other entity. Am I right?
And please explain what you're trying to do. I understand that you're checking collision but I don't understand how. Why don't you simply check the two AABB against each other?
sf::FloatRect FishBounds = Fish->_Sprite.getGlobalBounds();
sf::FloatRect FishyBounds = Fishy->_Sprite.getGlobalBounds();
bool intersects = FishBounds.intersects(FishyBounds);
specifically when I added a SetScale call, as my fishes have :-)
is this what you meant by minimal?
int main(){
sf::Sprite A;
A.setScale(0.5,0.5);
A.setPosition(640,640);
sf::Sprite B;
B.setPosition(320,320);
sf::Transform transform = A.getTransform().getInverse();
sf::Vector2<float> P = transform.transformPoint(B.getPosition());
std::cout << P.x << ", " << P.y <<"\n";//Outputs '-640,-640'
return 0;
}
Yes, thank you :)
Now we can work on a very simple base that we both understand, and which doesn't depend on a bigger project.
If A is scaled by x0.5 and translated by (640, 640), what is the inverse transformation? Obviously, without even calculating it, you can see that it will be a translation by (-640, -640) followed by a x2 scale:
P = (320, 320)
// add (-640, -640)
P = (-320, -320)
// multiply by 2
P = (-640, -640)
It's easy to understand, and we haven't talked about matrices or computed anything to demonstrate it.
What result did you expect from this code, and why?