hello again,
i have two points, which are connected with a joint. to visualize the joint i place the graphic of a chain between the two objects. the calculation of the point between the two points is pretty easy and works, but i'm somehow to dumb to calculate the correct rotation...
any help would be awesome! 🙂
here's the code:
i have two points, which are connected with a joint. to visualize the joint i place the graphic of a chain between the two objects. the calculation of the point between the two points is pretty easy and works, but i'm somehow to dumb to calculate the correct rotation...
any help would be awesome! 🙂
here's the code:
Code:
// getting the positions of the two bodies
Vector2DF posBody1 = Vector2DF(m_joint->GetBody1()->GetCenterPosition().x, m_joint->GetBody1()->GetCenterPosition().y);
Vector2DF posBody2 = Vector2DF(m_joint->GetBody2()->GetCenterPosition().x, m_joint->GetBody2()->GetCenterPosition().y);
float posX = posBody1.x - posBody2.x;
float posY = posBody1.y - posBody2.y;
float absPos = sqrt(posX * posX + posY * posY);
float angle = sin(posX / absPos);
// position is the point between the two bodies
Vector2DF position = Vector2DF(posBody1.x - posX / 2, posBody1.y - posY / 2);
SetPosition(position); // works!
SetRotation(angle); // does not work... :(
Vector2DF posBody1 = Vector2DF(m_joint->GetBody1()->GetCenterPosition().x, m_joint->GetBody1()->GetCenterPosition().y);
Vector2DF posBody2 = Vector2DF(m_joint->GetBody2()->GetCenterPosition().x, m_joint->GetBody2()->GetCenterPosition().y);
float posX = posBody1.x - posBody2.x;
float posY = posBody1.y - posBody2.y;
float absPos = sqrt(posX * posX + posY * posY);
float angle = sin(posX / absPos);
// position is the point between the two bodies
Vector2DF position = Vector2DF(posBody1.x - posX / 2, posBody1.y - posY / 2);
SetPosition(position); // works!
SetRotation(angle); // does not work... :(