Advertisement
Guest User

camera

a guest
Feb 1st, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. //the exception thrown if the object is not inside the cube
  2. class exceptie{
  3.     const char* ce() const throw(){
  4.         return "Camera in afara formei!";
  5.     }
  6. }Afara;
  7.  
  8. //this function checks if the camera's position is inside the cube
  9. void App::inDreptunghi(Leadwerks::Vec3 Obiect){
  10.     int xMin = -90, xMax = 90, zMin = -90, zMax = 90;
  11.     if (!(Obiect.x >= xMin && Obiect.x <= xMax))
  12.         throw Afara;
  13.     if (!(Obiect.z >= zMin && Obiect.z <= zMax))
  14.         throw Afara;
  15. }
  16.  
  17. //this function runs every frame and moves the camera
  18. void App::MiscareCamera(){
  19.     if (window->KeyDown(Leadwerks::Key::W)){
  20.         Leadwerks::Vec3 coordonate = camera->GetPosition();
  21.         try{
  22.             Leadwerks::Vec3 unghi = camera->GetRotation();
  23.             camera->SetPosition(coordonate.x + Leadwerks::Math::Sin(unghi.y), coordonate.y, coordonate.z + Leadwerks::Math::Cos(unghi.y));
  24.             inDreptunghi(camera->GetPosition());
  25.         }
  26.         catch (exceptie){
  27.             camera->SetPosition(coordonate.x, coordonate.y, coordonate.z);
  28.         }
  29.     }
  30.  
  31.     if (window->KeyDown(Leadwerks::Key::S)){
  32.         Leadwerks::Vec3 coordonate = camera->GetPosition();
  33.         try{
  34.             Leadwerks::Vec3 unghi = camera->GetRotation();
  35.             camera->SetPosition(coordonate.x - Leadwerks::Math::Sin(unghi.y), coordonate.y, coordonate.z - Leadwerks::Math::Cos(unghi.y));
  36.             inDreptunghi(camera->GetPosition());
  37.         }
  38.         catch (exceptie){
  39.             camera->SetPosition(coordonate.x, coordonate.y, coordonate.z);
  40.         }
  41.     }
  42.  
  43.     if (window->KeyDown(Leadwerks::Key::D)){
  44.         try{
  45.             camera->Move(1, 0, 0);
  46.             inDreptunghi(camera->GetPosition());
  47.         }
  48.         catch (exceptie){
  49.             camera->Move(-1, 0, 0);
  50.         }
  51.     }
  52.  
  53.     if (window->KeyDown(Leadwerks::Key::A)){
  54.         try{
  55.             camera->Move(-1, 0, 0);
  56.             inDreptunghi(camera->GetPosition());
  57.         }
  58.         catch (exceptie){
  59.             camera->Move(1, 0, 0);
  60.         }
  61.     }
  62.  
  63.     if (window->KeyDown(Leadwerks::Key::R) && camera->GetPosition().y < 81){
  64.         camera->Move(0, 1, 0);
  65.     }
  66.  
  67.     if (window->KeyDown(Leadwerks::Key::F) && camera->GetPosition().y > 34){
  68.         camera->Move(0, -1, 0);
  69.     }
  70.  
  71.     if (window->KeyDown(Leadwerks::Key::E)){
  72.         Leadwerks::Vec3 unghi = camera->GetRotation();
  73.         camera->SetRotation(unghi.x, unghi.y + 2, 0);
  74.     }
  75.  
  76.     if (window->KeyDown(Leadwerks::Key::Q)){
  77.         Leadwerks::Vec3 unghi = camera->GetRotation();
  78.         camera->SetRotation(unghi.x, unghi.y - 2, 0);
  79.     }
  80.  
  81.     if (window->KeyDown(Leadwerks::Key::Z)){
  82.         Leadwerks::Vec3 unghi = camera->GetRotation();
  83.         if (unghi.x<30)
  84.             camera->SetRotation(unghi.x + 1, unghi.y, 0);
  85.     }
  86.  
  87.     if (window->KeyDown(Leadwerks::Key::C)){
  88.         Leadwerks::Vec3 unghi = camera->GetRotation();
  89.         if (unghi.x>0)
  90.             camera->SetRotation(unghi.x - 1, unghi.y, 0);
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement