Well it was pretty confusing because the files weren't in the places where the Code::Blocks project expected them to be, but I eventually figured it out.
Here's a testbed example. The button continually rises no matter what, completely ignoring all constraints.
Code:
/*
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef PRISMATIC2_H
#define PRISMATIC2_H
class Prismatic2 : public Test
{
public:
Prismatic2()
{
b2Body* base = NULL;
{
b2BodyDef def;
def.type = b2_staticBody;
def.position.Set(0,0);
def.fixedRotation = true;
base = m_world->CreateBody(&def);
b2PolygonShape poly;
poly.SetAsBox( 1.625, 0.1875 );
base->CreateFixture(&poly);
}
b2Body* button = NULL;
{
b2BodyDef def;
def.type = b2_dynamicBody;
def.position.Set(0,.5);
def.fixedRotation = true;
button = m_world->CreateBody(&def);
b2PolygonShape poly;
poly.SetAsBox( 1.125, 0.125 );
button->CreateFixture(&poly);
}
{
b2PrismaticJointDef pjd;
// Bouncy limit
pjd.Initialize(base, button, b2Vec2(0.0f, 0.0f), b2Vec2(0.0f, -1.0f));
// Non-bouncy limit
//pjd.Initialize(ground, body, b2Vec2(-10.0f, 10.0f), b2Vec2(1.0f, 0.0f));
pjd.motorSpeed = -0.5f;
pjd.maxMotorForce = 100.0f;
pjd.enableMotor = true;
pjd.lowerTranslation = 0.0f;
pjd.upperTranslation = 0.25f;
pjd.enableLimit = true;
m_joint = (b2PrismaticJoint*) m_world->CreateJoint(&pjd);
}
}
void Keyboard(unsigned char key)
{
switch (key)
{
case 'l':
m_joint->EnableLimit(!m_joint->IsLimitEnabled());
break;
case 'm':
m_joint->EnableMotor(!m_joint->IsMotorEnabled());
break;
case 'p':
m_joint->SetMotorSpeed(-m_joint->GetMotorSpeed());
break;
}
}
void Step(Settings* settings)
{
Test::Step(settings);
m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motors, (p) speed");
m_textLine += 15;
float32 force = m_joint->GetMotorForce();
m_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", (float) force);
m_textLine += 15;
}
static Test* Create()
{
return new Prismatic2;
}
b2PrismaticJoint* m_joint;
};
#endif