Jump to content
george68

Camera deletion

Recommended Posts

Please consider this piece of code:

#include "App.h"

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL)
{
}

App::~App()
{
   delete world;
   delete window;
}

Leadwerks::Model *model = NULL;

bool App::Start()
{
   window = Leadwerks::Window::Create();
   context = Leadwerks::Context::Create(window);
   world = Leadwerks::World::Create();
   camera = Leadwerks::Camera::Create();
   camera->Move(0, 0, -3);

   Leadwerks::Light *light = Leadwerks::DirectionalLight::Create();

   light->SetRotation(35, 35, 0);
   model = Leadwerks::Model::Box();
   model->SetColor(0.0, 0.0, 1.0);
   return true;
}

bool App::Loop()
{
   if (window->Closed() || window->KeyDown(Leadwerks::Key::Escape))
       return false;
   if (camera)
       if (window->KeyDown(Leadwerks::Key::Space))
       {
           camera->Release(); // or camera->Hide()
           camera = NULL;
       }
   model->Turn(0, Leadwerks::Time::GetSpeed(), 0);
   Leadwerks::Time::Update();
   world->Update();
   world->Render();
   context->Sync();
   return true;
}

After pressing the space key, only a blank black screen should be visible. But strangely the cube is still visible, without rotating.

How I can have the 3D world invisible when the camera is deleted?

Share this post


Link to post

When the camera is released, the last frame gets stuck. You can draw a black rectangle whenever there is no active camera being used.

Share this post


Link to post

hmmm... strange

I call the Clear() method:

bool App::Loop()
{
   if (window->Closed() || window->KeyDown(Leadwerks::Key::Escape))
       return false;
   if (camera)
   {
       if (window->KeyDown(Leadwerks::Key::Space))
       {
           camera->Release();
           camera = NULL;
           context->Clear();
       }
   }
   model->Turn(0, Leadwerks::Time::GetSpeed(), 0);
   Leadwerks::Time::Update();
   world->Update();
   world->Render();
   context->Sync();
   return true;
}

but the screen is flashing

Share this post


Link to post
bool App::Loop()
{
       if (window->Closed() || window->KeyDown(Leadwerks::Key::Escape))
               return false;
       if (camera)
       {
               if (window->KeyDown(Leadwerks::Key::Space))
               {
                       camera->Release();
                       camera = NULL;
               }
       }
       model->Turn(0, Leadwerks::Time::GetSpeed(), 0);
       Leadwerks::Time::Update();
       world->Update();
       if (camera)
       {
               world->Render();
       }
       else
       {
               context->Clear();
       }
       context->Sync();
       return true;
}

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...