Jump to content
  • Advertisement
Sign in to follow this  
wicked357

Help with mouse joints in Box2D C++

This topic is 3051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been working with Box2D for just a couple of days now, I got the basics down and understanding what I have learned, but instead of moving the objects with keyboard input using ApplyForce and Impulse, I want to use a mouse joint to move the object when I am over them and I click the left button, you don't need to tell me how to use the input device or how to locate when the mouse is over the object I have that figured out, I need to know how to create a mouse joint and attach it to the object when I press the left click then I can drag it around the screen (keeping the phyics intact of course, but just for learning I can settle for no physics if it is easier).
//Set the box's center
myBox.sprite.SetCenter(25, 25);

//Create the box shape (polygon) definition
myBox.polyDef.SetAsBox(myBox.sprite.GetCenter().x / RATIO, myBox.sprite.GetCenter().y / RATIO);
myBox.polyDef.friction      = 0.08f;
myBox.polyDef.restitution   = 0.2f;
myBox.polyDef.density      = 0.4f;

//Create the box body definition
myBox.bodyDef.position.Set(600.0f / RATIO, 50.0f / RATIO);
myBox.angle = 0.0f;

//Create the box body
myBox.body = myWorld.world->CreateBody(&myBox.bodyDef);

//Create the box shape
myBox.body->CreateShape(&myBox.polyDef);
myBox.body->SetMassFromShapes();

The myBox.sprite is API exclusive so don't pay attention to that if you are confused by that, I just put it there so you can see the objects center as it is relevant to my creating of the object myBox. Now how can I create a mouse joint to that, I have tried the example I saw on the homepage and what I've seen googled and to no luck. Also what should happen when I click the mouse button, if you need more code let me know, ill post more.

Share this post


Link to post
Share on other sites
Advertisement
I got it figured out a few days ago, after a lot of research, if you want to see how it is done, come over to my website when I get it done, until then happy coding.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!