Can somebody tell me how can to draw the force vectors(b2vec2) ?
drawing force vectors
Flashusing the standart flash drawing api i suppose. lineStyle, moveTo and lineTo. Just supply the lineTo func forcex+body.x for x value obviosly and force.y + body.y for y coordinate. these values also need to be multiplied by your pixels to physics engine values ratio.
are you sure thts all u got to do? cuz i tried it b4 posting. And the line drawn did not correspond to the direction the vector should have been pointing. actually i saw this function on the forums
And i want to draw the sidewaysAxis vector. so that i could understand what exatly is happening.
Code:
private function killOrthogonalVelocity(targetBody:b2Body):void {
var localPoint:b2Vec2 = new b2Vec2(0,0);
var velocity:b2Vec2 = targetBody.GetLinearVelocityFromLocalPoint(localPoint);
var sidewaysAxis:b2Vec2 = targetBody.GetTransform().R.col2.Copy();
sidewaysAxis.Multiply(b2Math.b2Dot(velocity,sidewaysAxis))
targetBody.SetLinearVelocity(sidewaysAxis);//targetBody.GetWorldPoint(localPoint));
//trace("setting velocity: " + velocity)
//targetBody.SetLinearVelocity(velocity);//targetBody.GetWorldPoint(localPoint));
}
var localPoint:b2Vec2 = new b2Vec2(0,0);
var velocity:b2Vec2 = targetBody.GetLinearVelocityFromLocalPoint(localPoint);
var sidewaysAxis:b2Vec2 = targetBody.GetTransform().R.col2.Copy();
sidewaysAxis.Multiply(b2Math.b2Dot(velocity,sidewaysAxis))
targetBody.SetLinearVelocity(sidewaysAxis);//targetBody.GetWorldPoint(localPoint));
//trace("setting velocity: " + velocity)
//targetBody.SetLinearVelocity(velocity);//targetBody.GetWorldPoint(localPoint));
}
And i want to draw the sidewaysAxis vector. so that i could understand what exatly is happening.
heres how i do it for simple velocity, sidewaysAxis should be similar:
Code:
graphics.lineStyle(1, 0xff0000, 1);
graphics.moveTo(_body.GetPosition().x* app.RATIO, _body.GetPosition().y* app.RATIO);
graphics.lineTo(_body.GetPosition().x* app.RATIO+_body.GetLinearVelocity().x, _body.GetPosition().y* app.RATIO+_body.GetLinearVelocity().y);
graphics.moveTo(_body.GetPosition().x* app.RATIO, _body.GetPosition().y* app.RATIO);
graphics.lineTo(_body.GetPosition().x* app.RATIO+_body.GetLinearVelocity().x, _body.GetPosition().y* app.RATIO+_body.GetLinearVelocity().y);
Yea the linear velocity vectors draw and point in the correct direction. but the sidewayaxis drawing is confusing me.
why do you need to draw sidewaysaxis? Velocity gets set by sidewaysaxis at the last line anyways, so you could just draw that maybe?
i wanted to draw sidewayaxis vector before it gets added.
well there is no magic here, by using the same drawing functions you will draw the sidewaysaxis vector, maybe it is not what you expect to look like like?
Original thread: https://box2d.org/forum/viewtopic.php?t=5592