Box2D Forums

It is currently Thu May 23, 2013 3:34 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Dec 23, 2011 2:40 pm 
Offline

Joined: Tue Dec 06, 2011 6:25 am
Posts: 3
Are greeted dear Box2Dler!
I have a problem with the RevoluteJoints. Besides, I have read the documentation several times, asked in another, German forum (Yes, I am from Germany '^-^) and was expelled from there to here. My basic idea with my C ++ practise in addition was to be provided, admittedly, to create a static body and a dynamic one. The dynamic one then will fix with a RevoluteJoint to the static. However, it does not want to turn anyhow. I use, in addition, still the SFML.
Here my definition of the joint and the updating of the Box2D world:
Code:
   b2RevoluteJointDef RevJointDef;
   RevJointDef.Initialize(MiniRectBody, RectBody, MiniRectBody->GetWorldCenter()); //MiniRectBody is the static one!
   RevJointDef.enableLimit = false;
    RevJointDef.maxMotorTorque = 100000.0f;
    RevJointDef.motorSpeed = 30.0f;
    RevJointDef.enableMotor = true;
   b2RevoluteJoint *RevJoint      = (b2RevoluteJoint*)world->CreateJoint(&RevJointDef);

Code:
      if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))
      {
         RevJoint->SetMotorSpeed( 50.f);
         RevJoint->GetBodyB()->SetAwake(true);
      }
      if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))
      {
         RevJoint->SetMotorSpeed(-50.f);
         RevJoint->GetBodyB()->SetAwake(true);
      }

      world->Step(1.f/960.f, 6, 2);
      world->ClearForces();

      rec.SetPosition(RectBody->GetPosition().x, RectBody->GetPosition().y);
      rec.SetRotation((3/2*b2_pi)*(RectBody->GetAngle()*b2_pi));



Yours sincerely,
Check

HP: Sorry about possible English. :[


Top
 Profile  
 
PostPosted: Fri Dec 23, 2011 10:24 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
Make sure the dynamic body is not a fixed rotation body, and make sure it has a non-zero density (give the fixture some density before doing CreateFixture).

Just wondering what the last line is for... SetRotation?


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 6:28 am 
Offline

Joined: Tue Dec 06, 2011 6:25 am
Posts: 3
The last line is for the calculating/converting the radians in degrees.
It´s easier to use this: Box1Rect.SetRotation(box1Body->GetAngle()*b2_pi/180.f);
The static body is a fixedRotation-one, the dynamic isn´t it.
The dynamic body have a density of 2,34, the static one 6,973. But for the static body I think, the density doesn´t matter. :mrgreen:

MfG
Check


Top
 Profile  
 
PostPosted: Sun Dec 25, 2011 3:11 pm 
Offline

Joined: Tue Dec 06, 2011 6:25 am
Posts: 3
If nobody can help me, nevertheless, give me a classic example. Then, nevertheless, with this I can better work than up to the end of the world year who understands the joke that may also laugh (*grins*), to discuss this real grounding knowledge with Box2D, with yours I think, that to continue nervous feed as well as frustration, because of the urge with it to me and you for my part, is saved. Please, do not take up this anyhow wrong, I hope also that my translation help uses here no wrong words. x]

Yours sincerely,
Checkmateing


Top
 Profile  
 
PostPosted: Sun Dec 25, 2011 10:55 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
Your translation software is fine - actually I'm quite enjoying it :D

The testbed has some standard uses of revolute joints you could check. This may also be useful: http://www.iforce2d.net/b2dtut/joints-revolute
I was looking at your code again and I noticed:
Code:
RevJointDef.Initialize(MiniRectBody, RectBody, MiniRectBody->GetWorldCenter()); //MiniRectBody is the static one!

Is the dynamic body supposed to rotate around the static body's position, or the dynamic body's position? Maybe the last parameter should be RectBody->GetWorldCenter()?
If it still doesn't work out, try making the simplest possible reproduction in the testbed, then it will be easier for other people to try out.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group