Although this is in AS3 not C++, the only member missing I believe in AS3's port is m_rotation. Anyhow, AS3 is a simple language, any C++ programmer should be able to apply the math to it.
My problem is, I'm trying to get my circle to rotate it's X axis to exactly where I click on the stage, any help would be appreciated 😀
My problem is, I'm trying to get my circle to rotate it's X axis to exactly where I click on the stage, any help would be appreciated 😀
Code:
// Add Mouse Stage Listener
stage.addEventListener( MouseEvent.CLICK, onMouseClick );
// Creat world AABB
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-100.0, -100.0);
worldAABB.upperBound.Set(100.0, 100.0);
// Define the gravity vector
var gravity:b2Vec2 = new b2Vec2(0.0, 0.0);
var bd:b2BodyDef;
var cd1 = new b2CircleDef( );
cd1.radius = 0.7;
cd1.density = 1.0;
cd1.friction = 0.5;
cd1.restitution = 0.1
var startX = 100;
var startY = 100;
bd = new b2BodyDef( );
bd.position.Set( startX / m_physScale, startY / m_physScale );
bd.linearDamping = 1.0;
bd.angularDamping = 1.0;
body1 = m_world.CreateBody( bd );
body1.CreateShape( cd1 );
body1.SetMassFromShapes();
private function onMouseClick( evt:MouseEvent ):void {
var dx:Number = (mouseX - body1.GetPosition().x) * m_physScale;
var dy:Number = (mouseY - body1.GetPosition().y) * m_physScale;
var radians:Number = Math.atan2( dx, dy );
body1.ApplyTorque( radians );
}
stage.addEventListener( MouseEvent.CLICK, onMouseClick );
// Creat world AABB
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-100.0, -100.0);
worldAABB.upperBound.Set(100.0, 100.0);
// Define the gravity vector
var gravity:b2Vec2 = new b2Vec2(0.0, 0.0);
var bd:b2BodyDef;
var cd1 = new b2CircleDef( );
cd1.radius = 0.7;
cd1.density = 1.0;
cd1.friction = 0.5;
cd1.restitution = 0.1
var startX = 100;
var startY = 100;
bd = new b2BodyDef( );
bd.position.Set( startX / m_physScale, startY / m_physScale );
bd.linearDamping = 1.0;
bd.angularDamping = 1.0;
body1 = m_world.CreateBody( bd );
body1.CreateShape( cd1 );
body1.SetMassFromShapes();
private function onMouseClick( evt:MouseEvent ):void {
var dx:Number = (mouseX - body1.GetPosition().x) * m_physScale;
var dy:Number = (mouseY - body1.GetPosition().y) * m_physScale;
var radians:Number = Math.atan2( dx, dy );
body1.ApplyTorque( radians );
}