本文整理汇总了C++中Plane::SetRotation方法的典型用法代码示例。如果您正苦于以下问题:C++ Plane::SetRotation方法的具体用法?C++ Plane::SetRotation怎么用?C++ Plane::SetRotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plane
的用法示例。
在下文中一共展示了Plane::SetRotation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessControls
void PlayerController::ProcessControls()
{
if(Game->GetCurrentMode() == GM_PLAY)
{
Ship *ship = (Ship *)SM->GetSceneByName("Main")->GetEntityByName("Player")->GetMeshByName("Player Ship");
Plane *lengine = (Plane *)SM->GetSceneByName("Main")->GetEntityByName("Player")->GetMeshByName("LEngine");
Plane *rengine = (Plane *)SM->GetSceneByName("Main")->GetEntityByName("Player")->GetMeshByName("REngine");
float magnitude = sqrtf(pow(GetMouseX()-ship->GetPosition().x,2)+pow(GetMouseY()-ship->GetPosition().y,2));
glm::vec3 dir = glm::vec3((GetMouseX()-ship->GetPosition().x),(GetMouseY()-ship->GetPosition().y),0)/magnitude;
float rotSpeed=10.0f;
float maxspeed = 12.0f;
float acceleration = 0.5f;
glm::vec3 vel = ship->GetThrottle();
float accelerating = lengine->GetScale().x;
if(keys[SDLK_RIGHT]) // If the right arrow key is pressed
{
ship->Rotate(glm::vec3(0.0f,0.0f,+rotSpeed)); // Rotate the ship clockwise
}
if(keys[SDLK_LEFT]) // If the right arrow key is pressed
{
ship->Rotate(glm::vec3(0.0f,0.0f,-rotSpeed)); // Rotate the ship clockwise
}
if(keys['w'])
{
if(magnitude > -maxspeed) // If the throttle is less than max
{
vel += 0.5f*dir*acceleration;
}
else
{
vel -= maxspeed;
}
if(accelerating < 1.0f)
accelerating += .05f;
else
accelerating = 1.0f;
}
else
{
if(accelerating > 0)
accelerating -= .05f;
else
accelerating = 0.0f;
}
if(vel.x > 0 && vel.x < 0.1f) // If the throttle is close to zero
{
vel.x=0; // Go ahead and set it to zero (no need to waste fuel)
}
if(vel.y > 0 && vel.y < 0.1f) // If the throttle is close to zero
{
vel.y=0; // Go ahead and set it to zero (no need to waste fuel)
}
if(vel.x < 0 && vel.x > -0.1f) // If the throttle is close to zero
{
vel.x=0; // Go ahead and set it to zero (no need to waste fuel)
}
if(vel.y < 0 && vel.y > -0.1f) // If the throttle is close to zero
{
vel.y=0; // Go ahead and set it to zero (no need to waste fuel)
}
glm::vec3 pos = ship->GetPosition();
if(pos.x > WM->GetWindowWidth()+16.0f)
{
pos.x = -16.0f;
ship->SetPosition(pos);
}
else if(pos.x < -16.0f)
{
pos.x = WM->GetWindowWidth()+16.0f;
ship->SetPosition(pos);
}
if(pos.y > WM->GetWindowHeight()+16.0f)
{
pos.y = -16.0f;
ship->SetPosition(pos);
}
else if(pos.y < -16.0f)
{
pos.y = WM->GetWindowHeight()+16.0f;
ship->SetPosition(pos);
}
ship->SetThrottle(vel);
ship->Translate(vel);
pos = ship->GetPosition();
glm::vec3 rot = glm::vec3(0,0,-(atan2(mouse_x-pos.x,mouse_y-pos.y)+3.14159)*180/3.14159);
ship->SetRotation(rot);
if(!lengine || !rengine)
return;
//.........这里部分代码省略.........