Jump to content
Sign in to follow this  
  • entries
    4
  • comments
    13
  • views
    806

Min collisions

lilington

718 views

 

Hey,
I have been busy lately, still learning more about OpenGL and of course my work. I should accelerate a little bit now.

Now I added a collision engine, very basic at the moment. it is about detecting if a point is inside a platform rotated or not. plus solve the deformation on rotations in the previous entry.  Also updated the math functions.

Collision:

Nothing very fancy, just check if the point is inside the bouncing box if the platform is not rotated it will return collision detected. if the platform has rotated then the point will be rotated opposite angle to go back to the previous situation and do the same check.

int bkp_physics_inPlatform2D(BKP_VEC3 point, BKP_Entity_Platform * p)
{
    float X = point.x;                                                                                                                                                                                                                                                          
    float Y = point.y;

    if(X > p->bbox.x && X < p->bbox.x + p->bbox.w && Y > p->bbox.y && Y < p->bbox.y + p->bbox.h)
    {   

        if( p->isrotated == BKP_TRUE)
        {   
            X = X - p->rotate.center.x;
            Y = Y - p->rotate.center.y;

            float x =  p->rotate.center.x + X * p->cos_a     - Y * (- p->sin_a);
            float y =  p->rotate.center.y + X * (- p->sin_a) + Y * p->cos_a;

            if(x > p->x && x < p->x + p->w && y > p->y && y < p->y + p->h)
                return BKP_TRUE;
        }   
        else
            return BKP_TRUE;
    }   

    return BKP_FALSE;
}

Notice that the cos and sin are precalculated each team the platform if it rotates only. avoiding to use too much expensive cos and sin.

You can see on the video the mouse cursor becoming red each time it is inside a platform.You can also see on the sprite 8 points that I will be used to make the collision detection.

Gravity:

on this other video, I activated gravity. but no collision. it is possible to jump in the air to test the effect of jump

 

Well, that's all done for now. I will unify collision detection and gravity, add some penetration resolution and we will see a first step done. next step will be more about game play.

 

 



4 Comments


Recommended Comments

Nice job! Glad to see you're progressing!

Share this comment


Link to comment
On 3/29/2018 at 5:34 PM, lilington said:

Thanks, the next entry will be sooner

How's everything going? :) 

Share this comment


Link to comment

Oops , I just noticed it. haha. been busy with my feeding me job and the game. I just posted something new. you can have a look at the next entry. thanks

 

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!