Page 1 of 1

[C++] skyBox class, used to quickly update skybox

Posted: Sat Mar 24, 2007 2:35 pm
by kamp0002
Here is a sample class I am using to quickly make a skybox and update it (ie night to day). Initializing a new skyBox obj and running the start function will update the skybox.

to initialize in main() requires ISceneManager and IVideoDriver objects:

Code: Select all

skyBox SB(smgr, driver, "/pathtoSkyboxes/", "desert3");


function call:

Code: Select all

SB.start();
here is the class; you need to atleast include <cstring> and <irrlicht.h>:

Code: Select all

class skyBox{
private:
        ISceneManager* sc; //scene
        IVideoDriver* dr; //driver
        char* name; //skybox name
        char path[50];
        
public:
       //constructor
       skyBox( ISceneManager* s, IVideoDriver* d, char p[50], char* n )
       { 
               sc=s; 
               dr=d; 
               name=n; 
               strcpy(path,p); //path to all skyBox textures
               /* skyboxes should all be named in the format *up.bmp, *dn.bmp,
               *rt.bmp, *lt.bmp, *ft.bmp, *bk.bmp where * is all the same name
               ie blue2
               */
       }
       void start(){ //create skybox
dr->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
    
         char fileup[50]="";
         strcat ( fileup, path );
         strcat ( fileup, name ); 
         strcat ( fileup, "up.bmp" );
         
         char filedn[50]="";
         strcat ( filedn, path );
         strcat ( filedn, name ); 
         strcat ( filedn, "dn.bmp" );
         
         char filert[50]="";
         strcat ( filert, path );
         strcat ( filert, name ); 
         strcat ( filert, "rt.bmp" );
         
         char filelt[50]="";
         strcat ( filelt, path );
         strcat ( filelt, name ); 
         strcat ( filelt, "lt.bmp" );
         
         char fileft[50]="";
         strcat ( fileft, path );
         strcat ( fileft, name ); 
         strcat ( fileft, "ft.bmp" );
         
         char filebk[50]="";
         strcat ( filebk, path );
         strcat ( filebk, name ); 
         strcat ( filebk, "bk.bmp" );

	sc->addSkyBoxSceneNode(
                                 dr->getTexture(fileup),
		 dr->getTexture(filedn),
		 dr->getTexture(filert),
		 dr->getTexture(filelt),
		 dr->getTexture(fileft),
		 dr->getTexture(filebk));
dr->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
	   }
};
//I find that this class has made it quicker and easier to implement skyboxes in general

Posted: Sun Mar 25, 2007 1:59 am
by Midnight
good now add in a fader so it doesn't look totally rediculas.

Posted: Sun Mar 25, 2007 9:50 am
by Spintz
what exactly is rediculas? :P

Posted: Mon Mar 26, 2007 8:51 pm
by Earl
PRetty cool!
I've been trying to do something like this myself with little luck :D
So this just creates one "frame" of the skybox? To move to the next you just repeat the process, correct?

Actually I think a fader would look much more ridiculous, seeing as it's never an even fade from all directions from day to night :D It would have to be animated.
I'll definitely try this class :D After midterms. :|

Posted: Tue Mar 27, 2007 6:05 am
by Midnight
Spintz wrote:what exactly is rediculas? :P
it's a misspelled word that means silly two ways.

don't be coy.

Posted: Tue Mar 27, 2007 6:08 am
by Midnight
Actually I think a fader would look much more ridiculous, seeing as it's never an even fade from all directions from day to night It would have to be animated.
which is why if anything you should try atmosphere. search the forum.

you think fading in looks worse then blinking day and night in existence like your god or something?

and yes the sky does sort of fade to night and back again because it's a refraction of the layers of atmosphere in the sky. it's actually spot on realistic in terms of look.

whats with all the crabby people i don't get it.

Posted: Tue Mar 27, 2007 8:57 pm
by Earl
Me, crabby? No way :D
So it takes more frames than 2 to make a day/night sequence, go figure.
The sun travels east to west, my friend, I don't need refraction to explain that :D
Plus quality-wise drawing out your own frames would look SO MUCH better than just letter a computer do it, I think.

Posted: Tue Mar 27, 2007 9:21 pm
by Midnight
Earl wrote:So it takes more frames than 2 to make a day/night sequence, go figure.
The sun travels east to west, my friend, I don't need refraction to explain that :D
Plus quality-wise drawing out your own frames would look SO MUCH better than just letter a computer do it, I think.
that was kinda my point... use acki's lens flare scene node for the sun.

and a billboard maybe.

I didn't realise you could do several skybox frames efficiently with this though.. that makes it totally useful. 8)

Posted: Wed Mar 28, 2007 5:33 am
by roxaz
thank you kamp0002, but could you encapsulate your code in the post with

Code: Select all

 bb tags? :)

graphics

Posted: Wed Mar 28, 2007 1:49 pm
by kamp0002
I use this class to change my scenes from level to level atm. A lazy terrain texturing method I've picked up is to use the *dn.bmp as the texture for the main piece of terrain; I find that it makes the terrain match the skybox very nicely. One way to animate would be to load an array of skyBoxes and loop through them each object as one frame. I haven't done this myself yet, it would be nice to know if on a good graphics card if it renders smoothly or if it would cause flashing.