Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

I’ve a field object , which I created with box2d, I set it is angular velocity and angle to 0, in order that it would not rotate for now.

I am checking each body to see if the field is hitting the highest display and whether it is, I clamp it and make it bounce in the wrong way.

(additionally I do know I ought to in all probability use the dot product right here, however that is only a easy instance with a linear velocity set to 0 within the x, and seven within the y, in order that the field solely goes up or down).

Anyhow, I do it like so:

void Sport::ClampScreenY( Field* pBox)
{
    bool isColliding = false;
    auto pos = static_cast<b2Vec2>( pBox->GetPosition() );
    auto aabb = pBox->GetAABB();
    
    if( pos.y + boxSize >= boundarySize )
    {
        pos.y = boundarySize - boxSize;
        isColliding = true;
    }
    else if( pos.y - boxSize <= -boundarySize )
    {
        pos.y = -boundarySize + boxSize;
        isColliding = true;
    }

    if( isColliding )
    {
        auto vel = static_cast< b2Vec2 >( pBox->GetVelocity() );
        vel.y *= -1;
        pBox->SetVelocity( vel );
        pBox->SetPosition( pos );
    } 

now this works if the field angle is 0 like within the following picture:
enter image description here

that is wonderful, it really works as anticipated.

But when I modify the angle of the field to be totally different than 0 like so:

enter image description here

my program crashes. How can I repair this, and why precisely is that this taking place? I believed abound utilizing the Axis Aligned Bounding Field and someway work this by means of, i am simply undecided the best way to use the aabb to assist me repair this problem.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *