Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //the exception thrown if the object is not inside the cube
- class exceptie{
- const char* ce() const throw(){
- return "Camera in afara formei!";
- }
- }Afara;
- //this function checks if the camera's position is inside the cube
- void App::inDreptunghi(Leadwerks::Vec3 Obiect){
- int xMin = -90, xMax = 90, zMin = -90, zMax = 90;
- if (!(Obiect.x >= xMin && Obiect.x <= xMax))
- throw Afara;
- if (!(Obiect.z >= zMin && Obiect.z <= zMax))
- throw Afara;
- }
- //this function runs every frame and moves the camera
- void App::MiscareCamera(){
- if (window->KeyDown(Leadwerks::Key::W)){
- Leadwerks::Vec3 coordonate = camera->GetPosition();
- try{
- Leadwerks::Vec3 unghi = camera->GetRotation();
- camera->SetPosition(coordonate.x + Leadwerks::Math::Sin(unghi.y), coordonate.y, coordonate.z + Leadwerks::Math::Cos(unghi.y));
- inDreptunghi(camera->GetPosition());
- }
- catch (exceptie){
- camera->SetPosition(coordonate.x, coordonate.y, coordonate.z);
- }
- }
- if (window->KeyDown(Leadwerks::Key::S)){
- Leadwerks::Vec3 coordonate = camera->GetPosition();
- try{
- Leadwerks::Vec3 unghi = camera->GetRotation();
- camera->SetPosition(coordonate.x - Leadwerks::Math::Sin(unghi.y), coordonate.y, coordonate.z - Leadwerks::Math::Cos(unghi.y));
- inDreptunghi(camera->GetPosition());
- }
- catch (exceptie){
- camera->SetPosition(coordonate.x, coordonate.y, coordonate.z);
- }
- }
- if (window->KeyDown(Leadwerks::Key::D)){
- try{
- camera->Move(1, 0, 0);
- inDreptunghi(camera->GetPosition());
- }
- catch (exceptie){
- camera->Move(-1, 0, 0);
- }
- }
- if (window->KeyDown(Leadwerks::Key::A)){
- try{
- camera->Move(-1, 0, 0);
- inDreptunghi(camera->GetPosition());
- }
- catch (exceptie){
- camera->Move(1, 0, 0);
- }
- }
- if (window->KeyDown(Leadwerks::Key::R) && camera->GetPosition().y < 81){
- camera->Move(0, 1, 0);
- }
- if (window->KeyDown(Leadwerks::Key::F) && camera->GetPosition().y > 34){
- camera->Move(0, -1, 0);
- }
- if (window->KeyDown(Leadwerks::Key::E)){
- Leadwerks::Vec3 unghi = camera->GetRotation();
- camera->SetRotation(unghi.x, unghi.y + 2, 0);
- }
- if (window->KeyDown(Leadwerks::Key::Q)){
- Leadwerks::Vec3 unghi = camera->GetRotation();
- camera->SetRotation(unghi.x, unghi.y - 2, 0);
- }
- if (window->KeyDown(Leadwerks::Key::Z)){
- Leadwerks::Vec3 unghi = camera->GetRotation();
- if (unghi.x<30)
- camera->SetRotation(unghi.x + 1, unghi.y, 0);
- }
- if (window->KeyDown(Leadwerks::Key::C)){
- Leadwerks::Vec3 unghi = camera->GetRotation();
- if (unghi.x>0)
- camera->SetRotation(unghi.x - 1, unghi.y, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement