本文整理汇总了C++中b2Vec2::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ b2Vec2::Set方法的具体用法?C++ b2Vec2::Set怎么用?C++ b2Vec2::Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b2Vec2
的用法示例。
在下文中一共展示了b2Vec2::Set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_length
void set_length(float l)
{
length = l;
self.Set(l * std::cos(angle), -l * std::sin(angle));
}
示例2: if
// Algorithm:
// 1. Classify v1 and v2
// 2. Classify polygon centroid as front or back
// 3. Flip normal if necessary
// 4. Initialize normal range to [-pi, pi] about face normal
// 5. Adjust normal range according to adjacent edges
// 6. Visit each separating axes, only accept axes within the range
// 7. Return if _any_ axis indicates separation
// 8. Clip
void b2EPCollider::Collide(b2Manifold* manifold, const b2EdgeShape* edgeA, const b2Transform& xfA,
const b2PolygonShape* polygonB, const b2Transform& xfB)
{
m_xf = b2MulT(xfA, xfB);
m_centroidB = b2Mul(m_xf, polygonB->m_centroid);
m_v0 = edgeA->m_vertex0;
m_v1 = edgeA->m_vertex1;
m_v2 = edgeA->m_vertex2;
m_v3 = edgeA->m_vertex3;
bool hasVertex0 = edgeA->m_hasVertex0;
bool hasVertex3 = edgeA->m_hasVertex3;
b2Vec2 edge1 = m_v2 - m_v1;
edge1.Normalize();
m_normal1.Set(edge1.y, -edge1.x);
float32 offset1 = b2Dot(m_normal1, m_centroidB - m_v1);
float32 offset0 = 0.0f, offset2 = 0.0f;
bool convex1 = false, convex2 = false;
// Is there a preceding edge?
if (hasVertex0)
{
b2Vec2 edge0 = m_v1 - m_v0;
edge0.Normalize();
m_normal0.Set(edge0.y, -edge0.x);
convex1 = b2Cross(edge0, edge1) >= 0.0f;
offset0 = b2Dot(m_normal0, m_centroidB - m_v0);
}
// Is there a following edge?
if (hasVertex3)
{
b2Vec2 edge2 = m_v3 - m_v2;
edge2.Normalize();
m_normal2.Set(edge2.y, -edge2.x);
convex2 = b2Cross(edge1, edge2) > 0.0f;
offset2 = b2Dot(m_normal2, m_centroidB - m_v2);
}
// Determine front or back collision. Determine collision normal limits.
if (hasVertex0 && hasVertex3)
{
if (convex1 && convex2)
{
m_front = offset0 >= 0.0f || offset1 >= 0.0f || offset2 >= 0.0f;
if (m_front)
{
m_normal = m_normal1;
m_lowerLimit = m_normal0;
m_upperLimit = m_normal2;
}
else
{
m_normal = -m_normal1;
m_lowerLimit = -m_normal1;
m_upperLimit = -m_normal1;
}
}
else if (convex1)
{
m_front = offset0 >= 0.0f || (offset1 >= 0.0f && offset2 >= 0.0f);
if (m_front)
{
m_normal = m_normal1;
m_lowerLimit = m_normal0;
m_upperLimit = m_normal1;
}
else
{
m_normal = -m_normal1;
m_lowerLimit = -m_normal2;
m_upperLimit = -m_normal1;
}
}
else if (convex2)
{
m_front = offset2 >= 0.0f || (offset0 >= 0.0f && offset1 >= 0.0f);
if (m_front)
{
m_normal = m_normal1;
m_lowerLimit = m_normal1;
m_upperLimit = m_normal2;
}
else
{
m_normal = -m_normal1;
m_lowerLimit = -m_normal1;
m_upperLimit = -m_normal0;
//.........这里部分代码省略.........
示例3: Init
void Init()
{
GameWin.create(sf::VideoMode(800, 600, 32), "Physics Test - [SFML & Box2D]");
if (!font.loadFromFile("arial.ttf"))
{
exit(0);
}
PauseText.setFont(font);
pauseText = to_string(Paused);
PauseText.setCharacterSize(10);
PauseText.setString("PAUSED:" + pauseText);
PauseText.setPosition(sf::Vector2f(700, 10));
PauseText.setFillColor(sf::Color::Yellow);
box.setPosition(sf::Vector2f(15, 5));
box.setSize(sf::Vector2f(10, 10));
box.setFillColor(sf::Color(255, 0, 0));
box2.setPosition(sf::Vector2f(50, 5));
box2.setSize(sf::Vector2f(15, 15));
box2.setFillColor(sf::Color(0, 255, 0));
ground.setPosition(sf::Vector2f(0, 540));
ground.setSize(sf::Vector2f(800, 560));
ground.setFillColor(sf::Color(0, 0,255));
wall.setPosition(sf::Vector2f(1, 1));
wall.setSize(sf::Vector2f(10, 580));
wall.setFillColor(sf::Color(0, 0, 255));
wall2.setPosition(sf::Vector2f(790, 1));
wall2.setSize(sf::Vector2f(10, 580));
wall2.setFillColor(sf::Color(0, 0, 255));
World = new b2World(gravity);
World->SetGravity(gravity);
groundBodyDef.type = b2_staticBody;
groundBodyDef.position.Set(0, 540);
groundBody = World->CreateBody(&groundBodyDef);
wallBodyDef.type = b2_staticBody;
wallBodyDef.position.Set(10, 580);
wallBody = World->CreateBody(&wallBodyDef);
wallBodyDef2.type = b2_staticBody;
wallBodyDef2.position.Set(790, 1);
wallBody2 = World->CreateBody(&wallBodyDef2);
ballBodyDef.type = b2_dynamicBody;
ballVector.Set(10, 10);
ballBodyDef.angularVelocity = 0.0f;
ballBodyDef.linearVelocity = ballVector;
ballBodyDef2.type = b2_dynamicBody;
ballVector2.Set(15, 15);
ballBodyDef2.angularVelocity = 0.0f;
ballBodyDef2.linearVelocity = ballVector2;
ballBodyDef.position.Set(15, 0);
ballBodyDef.awake = true;
Body = World->CreateBody(&ballBodyDef);
ballBodyDef2.position.Set(30, 0);
ballBodyDef2.awake = true;
Body2 = World->CreateBody(&ballBodyDef2);
boxShapeDef.shape = &groundBox;
boxShapeDef.density = 2.0f;
boxShapeDef.restitution = 0.5f;
groundBox.SetAsBox(800, 0);
groundBody->CreateFixture(&groundBox, 0);
wallBoxDef.shape = &wallBox;
wallBoxDef.density = 2.0f;
wallBoxDef.restitution = 0.5f;
wallBox.SetAsBox(1, 600);
wallBody->CreateFixture(&wallBox, 0);
wallBoxDef2.shape = &wallBox2;
wallBoxDef2.density = 2.0f;
wallBoxDef2.restitution = 0.5f;
wallBox2.SetAsBox(1, 600);
wallBody2->CreateFixture(&wallBox2, 0);
dynamicBox.SetAsBox(10.0f, 10.0f);
dynamicBox2.SetAsBox(10.0f, 10.0f);
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 2.0f;
fixtureDef.friction = 1.5f;
fixtureDef.restitution = 0.9f;
//.........这里部分代码省略.........