Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - martinw30

Pages: [1]
1
Graphics / Re: Error with collisioncheck against a vector
« on: August 14, 2012, 12:21:19 pm »
again many thanks Laurent :D

I am using VS10 and found a tutorial which will help. Ive linked it below for anyone else using visual studio

http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn

EDIT:

OK after stepping through my code carefully, I have assigned both the shape and the element of the vector to a local floatrect and I am finding that when I call the getGlobalBounds() of the shape I receive values for left, top, width and height but my vector only gives me width and height, the left and top values from the sprites of my vector are 0.

Should this be so?

2
Graphics / Re: Error with collisioncheck against a vector
« on: August 14, 2012, 10:18:35 am »
Hi Laurent,

I'm afraid I do, it isnt something Im comfortable doing neither is it something I was taught at University :/

Are there any helpful tutorials or links to help me understand it further?

3
Graphics / Re: Error with collisioncheck against a vector
« on: August 14, 2012, 10:02:07 am »
Thanks for the reply Laurent :D

The sprites that are in my vector are part of my main screen and menu, so i have a shape bouncing around the screen colliding off those individual sprites. But before that happens I move the sprites from my Vector into position. So I've animated the logo of my game (Just to add some flair) which is broken up into 8 parts (hence the vector).

Maybe I should position them first then check for collision?

4
Graphics / Re: Error with collisioncheck against a vector
« on: August 13, 2012, 05:13:20 pm »
thanks for the reply Laurent.
 ;D
What do you mean by missing Consts? :o

edit : I have also stepped through my code. The function only returns true when the shape collides with the first element of my vector. And whilst it is colliding it rapidly iterates through the vector. So when it collides with sprite 1 in my vector it collides with them all.

Man I'm stumped....

5
Graphics / Re: Error with collisioncheck against a vector
« on: August 13, 2012, 05:00:14 pm »
Can anybody reply to this query?  :-\

6
Graphics / Error with collisioncheck against a vector
« on: August 10, 2012, 02:46:06 pm »
I have added my sprites into a vector and am passing this vector and a shape object into a collision function. I need the function to check every element of the vector to see if the shape has collided with it, yet it only returns true if it collides with the first element of the vector. How can I get this function to return true if the shape collides with ANY element of the vector, not just the first:

bool CollisionCheck(const sf::CircleShape& shape, vector<sf::Sprite>& sprite){
                // return true if a shape collides with an element of the vector
                for (vector<sf::Sprite>::iterator it = sprite.begin(); it != sprite.end(); it++)
                {
                        // get the current position of the sprite
                        if (shape.getGlobalBounds().intersects(it->getGlobalBounds()))
                        {
                                return true;
                        }
                }
                return false;
        }

Any help will be greatly appreciated  :)

7
Graphics / Re: Collision checking with an object and a map
« on: August 02, 2012, 05:48:00 pm »
OK using a vector is fine, I can make that change.

What I need to now is how I check that the shape has collided with an object that is in the vector as the iterator starts at vector.begin() so the loop wont start checking until the first element has been checked.

How can I do a check that the shape has collided with an element from the vector and report back back which one it has without iterating?

8
Graphics / Collision checking with an object and a map
« on: August 02, 2012, 04:46:03 pm »
I am attempting to check collision between two objects. First is the shape passed to my function, second is the map containing one of the many sprites I've loaded into them. The problem I am having is the function only ever checks against the first element. I need to function to check if the ball has collided with a valid item of the map, which one it has collided with, report true then move onto direction change. Here is the function so far:

bool bounceCheck(const sf::CircleShape& object1, map<int, sf::Sprite>& sprite){
                // returns true if a ball collides with an element of the map
                for (map<int, sf::Sprite>::iterator it = sprite.begin(); it != sprite.end(); it++){
                        search.push_back(it->second.getGlobalBounds());
                        if (object1.getGlobalBounds().intersects(search[it->first])){
                                cout << "Collided with " << it->first << endl;
                                return true;
                        }
                }
                return false;
        }

I am assinging integers to the sprites I have loaded into my map for easy referal. Search is a vector I created to add each sprites bounds. Im guessing my logic isnt quite right somehow. Any help?

9
OK so Ive been playing with this function and changed it to accept a map instead.

I want the function to check if the shape collides with ANY element that lives within the map I send it, yet it only returns true if the shape collides with the first element of my map and none other so I'm guessing my logic is out:

static bool bounceCheck(const sf::CircleShape& shape, std::map<string, sf::Sprite>& Sprite){
                // returns true if a ball collides with any element of the map
                for (map<string, sf::Sprite>::iterator it = Sprite.begin(); it!=Sprite.end();it++)
                {
                        return (it->second.getGlobalBounds().intersects(shape.getGlobalBounds()));
                }
                return false;
        }

how do i get it to say "Well yes you are part of the map so return true" :D

Thanks again

Martin

p.s Also having just tested my code and outputting the it->first element at collision point the console is informing me that when the shape collides with an element of the map (sprite) it returns more than one file it collides with. As it waits until it collides with the first element then passes true that it collides with the others for as long as the shape collides with the first. Do I need to also check for a match with filename, map key etc?

10
Ok I understand now....but how do I add several global bounds to one rect item? It's only supposed to hold the position of one sprite at a time. My code is just overwriting the rect or cumalatively adding to it.

void AddSprite(const sf::Sprite& sprite){
                // add the current sprites bounds to the rect then ann that sprite to the vector
                bounds = sprite.getGlobalBounds();
                sprites.push_back(sprite);
                cout << sprites.size() << " " << bounds.width << endl;
        }

Thanks again for your help.

I just finished a 3 year Games Development degree and Im amazed still at how much I dont fully understand :/

Martin

p.s Ive added a screenshot. Its my main menu (NF) that the balls will bounce around bouncing off the menu items (Logo, menu choices etc). The ball isnt in the vector but every other item is.


[attachment deleted by admin]

11
Hey again,

So I ended up adding my vector of sprites to another vector and attempting to check if it collided. Im guessing thats what you meant by a container for my vector....

otherwise I completely misinterpreted you :/

Martin

12
Wow thanks for the diagram, its helped to visualise it at least :D

I'll try and get my head around a "collision domain" and how to create that from the vector im using

Thanks again!

Martin

13
Thank you for your hasty replies.

I'm gathering from the global domain you mean iterating thorugh the array/vector/etc and creating a new IntRect/FloatRect or calling the member's getGlobalBound() function?

Maybe if you can give me an example of this to make it clearer :D

Thanks again

Martin

14
Hey all,

I am attempting to write a function that will return true if the sprite I pass in the first argument collides with any sprite that may reside with the vector that is passed to the second argument yet I am having some trouble deciding:

a) If a vector is the best way to store my sprites once that are bound to a texture
b) how to check the vector if ANY element collides with the sprite without having to iterate through the entire vector each time a collision check is called.

bool windowInit::bounceCheck(const sf::Sprite &Sprite, vector<sf::Sprite> vect)
{      
        for (int i=0; i<vect.size(); i++)
                return (Sprite.getGlobalBounds().intersects(vect[i].getGlobalBounds()));

        return false;
}

I think my logic isnt quite right and also I have seperated the sprite in the first argument from the vector in the second so I dont need to check if there is a match.

Thanks in advance

Martin

Pages: [1]
anything