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 - natchos

Pages: 1 ... 5 6 [7]
91
General / Determing top/bottom and side collision
« on: April 16, 2012, 10:57:50 am »
Hello I'm currently working on a program in which I have a ball which moves and collides with a square. What I need to determine is whether to flip the Xvelocity or the Yvelocity. The function looks like this

bool ADVBoxCollision(sf::gEntity* sprite1, sf::gEntity* sprite2, bool* pTop, bool* pSide)
{
        sf::Rect<float> FirstRect = sf::Rect<float>(sprite1->GetPosition().x - sprite1->GetCenter().x ,sprite1->GetPosition().y - sprite1->GetCenter().y,sprite1->GetPosition().x+sprite1->GetSize().x - sprite1->GetCenter().x,sprite1->GetPosition().y+sprite1->GetSize().y - sprite1->GetCenter().y);
        sf::Rect<float> SecondRect = sf::Rect<float>(sprite2->GetPosition().x - sprite2->GetCenter().x ,sprite2->GetPosition().y - sprite2->GetCenter().y,sprite2->GetPosition().x+sprite2->GetSize().x - sprite2->GetCenter().x,sprite2->GetPosition().y+sprite2->GetSize().y - sprite2->GetCenter().y);
        //ToS stands for Top or side. It tells whether the sprite collided with the top/bottom part or the side part. 0 = top/bottom, 1 = sides
        if(BoxCollision(FirstRect, SecondRect))
        {
                if((FirstRect.Left <= SecondRect.Right) && (FirstRect.Right >= SecondRect.Left))
                {
                        if(!*pSide) *pSide = 1;
                        else *pSide = 0;                        //If RECT1 is to the left of RECT2
                }
                        if((FirstRect.Top <= SecondRect.Bottom) && (FirstRect.Bottom >= SecondRect.Top))
                {
                        if (*pTop) *pTop = 0;                   //If RECT1 is over RECT2
                        else *pTop = 1;
                }
                return BoxCollision(FirstRect, SecondRect);
        }
        else return false;
}

The pTop and the pSide variables points to a bool value which is use to conditionally reverse the Y or Xvelocity at a detected collision.

The problem is that the side collision always flips, no matter on what side the ball collides with the square and the top bool never flips at all.

Any help?

Also sorry for posting this here, wasn't sure if this fitted anywhere at all.

92
System / Re: Yet another clock thread
« on: April 14, 2012, 06:50:43 pm »
H: Thanky you!

N: Ah ok, well good to know atleast :)

93
System / Re: Yet another clock thread
« on: April 13, 2012, 02:58:46 pm »
Ah, nice then I will try to recompile my code with thors clock. Much obliged for your help.

94
System / Re: Yet another clock thread
« on: April 13, 2012, 02:55:49 pm »
Dang, meant 2008 ^^

95
System / Re: Yet another clock thread
« on: April 13, 2012, 02:52:19 pm »
VC++2007

96
System / Re: Yet another clock thread
« on: April 13, 2012, 02:40:44 pm »
Ya, I suppose I'll have to make a stopwatch in my own code :P.
Also when I went to Thors website it said that I had to have C++ TR1, which I do not(I think).

The reason I wanted to use sfmls class instead was simply convenience.

97
System / Yet another clock thread
« on: April 13, 2012, 02:16:37 pm »
Hey, I'm using SFML 1.6 on a win 7 machine.

My problem is that my program needs a stopable watch, so I am trying to modify the sf::clock class to include a stopwatch function. The function looks like this.

bool Clock::stopwatch(int ms)
{
        if (GetTime() > stopwatch_start + ms ) {
        stopwatch_start = GetTime();
        return true;}
        else return false;
}
 
GetTime() is just: return static_cast<double>sf::priv::Platform::GetSystemTime();
Anyhow, the problem isn't with the function itself. The problem is the stopwatch_start.
Apparently declaring a extra int/float/double/dword variable in the clock.hpp file causes the Renderwindow function Clear(); to malfunction and give me an access violation reading error on the next line.

The program runs fine(with the exclusion of the stopwatch function) if I remove declaration of the stopwatch_start. (for the reference it is declared as double stopwatch_start; as a private member of clock).

Could anyone post me any tips?

Pages: 1 ... 5 6 [7]
anything