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

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
kamp0002
Posts: 2
Joined: Sat Mar 24, 2007 1:49 pm

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

Post 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
Last edited by kamp0002 on Wed Mar 28, 2007 1:30 pm, edited 1 time in total.
Enjoy,

Ryan
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

good now add in a fader so it doesn't look totally rediculas.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

what exactly is rediculas? :P
Image
Earl
Posts: 14
Joined: Tue Jan 23, 2007 10:33 pm
Location: San Angelo, Tx

Post 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. :|
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

Spintz wrote:what exactly is rediculas? :P
it's a misspelled word that means silly two ways.

don't be coy.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post 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.
Earl
Posts: 14
Joined: Tue Jan 23, 2007 10:33 pm
Location: San Angelo, Tx

Post 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.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post 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)
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

thank you kamp0002, but could you encapsulate your code in the post with

Code: Select all

 bb tags? :)
kamp0002
Posts: 2
Joined: Sat Mar 24, 2007 1:49 pm

graphics

Post 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.
Post Reply