Game Scope

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
digoxy
Posts: 51
Joined: Wed Feb 17, 2010 3:55 pm
Location: Currently Germany.

Game Scope

Post by digoxy »

If I wanted to do something like this, what would be the best way to do it?

Code: Select all

void RenderGameLoop() 
{
   if(gamelooploaded == false) 
   {
    ICameraSceneNode* cam = SceneManager->addCameraSceneNode
    (cPivot1, sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance),cPivot1-
    >getPosition(),0); 
    gamelooploaded = true;
    }
cam->getPosition(); 
}

void Loop() 
{
   while( Device->run() ) 
   {
    case GAMELOOP : 
      {
       RenderGameLoop();
      }
     break;
    }
}
As it is, the cam designation is out of the scope. I have several of these I want to do this way, is there anything anyone can think of that would make this work without having to designate everything I need in a pointer and a call?
Last edited by digoxy on Tue Mar 23, 2010 4:10 pm, edited 1 time in total.
Grandma-- / Grandpa --
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

If you want to show code, its better if you use "Code" tag (one next to "Quote" above edit window).

Now to your code:
You need to declare your camera somewhere out of RenderGameLoop() so it should look something like this:

Code: Select all

ICameraSceneNode* cam;

void RenderGameLoop()
{
   if(gamelooploaded == false)
   {
      cam = SceneManager->addCameraSceneNode(cPivot1, sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance),cPivot1-
>getPosition(),0);
      gamelooploaded = true;
   }
   cam->getPosition();
}
Or you can pass camera pointer as argument:

Code: Select all

void RenderGameLoop(ICameraSceneNode* cam)
{
   if(gamelooploaded == false)
   {
      cam = SceneManager->addCameraSceneNode(cPivot1, sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance),cPivot1-
>getPosition(),0);
      gamelooploaded = true;
   }
   cam->getPosition();
}
Bye the way, what last line should do? (cam->getPosition(); ) It does nothing since you do not store camera position and you do nothing with it.
digoxy
Posts: 51
Joined: Wed Feb 17, 2010 3:55 pm
Location: Currently Germany.

Post by digoxy »

Ooops, Yes, your right, I forgot the code tag, I did correct it.

The example above is not really a working example, it was only to show that I want to access the cam out of the scope of the if statement. So, the getAPosition is just a random call for the example. :)

Arras, I appreciate you answering my questions here, I surely do. However, I am looking for something a bit more high level. The problem is that I have several items that need to be carried over, this cam is one of several. Is there not a way to maybe load all the Iscene (objects) ? This would also include your terrain as well! :) Right now, I count as many as 17 different things I need to access that are inside the if statement. Maybe there is another way to do this, as it is, this all about learning and if there is another idea on how to do this, it would be great.

When I declare cam outside of the loop as you describe then go through the run while, it crashes with (what I think is an empty declaration) the x0005 something or another. As if it cant utilize the cam info or something. I did try this just experimenting early on but never was able to make that work either.

Any feedback would be appreciated.
Grandma-- / Grandpa --
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Well, only way apart of either declaring something global or passing it as function argument is to use some kind of class which would hold all the declarations, including function. Can be some kind of "gamemanager".
Post Reply