Page 1 of 2

Rotating skybox

Posted: Sat Dec 04, 2004 11:28 am
by Rush
It's not a bug, but a missing feature. I can't find any reason why the skybox node can't be rotated (or scaled), so I'm posting here the code to fix it. It's just changing one line in CSkyBoxSceneNode.cpp:

Code: Select all

void CSkyBoxSceneNode::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();
	scene::ICameraSceneNode* camera = SceneManager->getActiveCamera();

	if (!camera || !driver)
		return;
        // this line. previous was simply core::matrix4 mat; 
	core::matrix4 mat = AbsoluteTransformation; 
	mat.setTranslation(camera->getAbsolutePosition());

	driver->setTransform(video::ETS_WORLD, mat);
	
	for (s32 i=0; i<6; ++i)
	{
		driver->setMaterial(Material[i]);
		driver->drawIndexedTriangleList(&Vertices[i*4], 4, Indices, 2);
	}
}
Of course you could achieve the same effect by rotating all the other nodes in the opposite direction, but rotating only the skybox seems simpler. I saw rotating skyboxes in many games (remember the space station level from Unreal Tournament?), so I think it should be implemented into the next version of Irrlicht.

Posted: Wed Dec 08, 2004 2:12 am
by etcaptor
:D Thanks,
I just playing this night with that. I got:
- rotating skybox /moving clouds/ with Irrlicht rotation animator
- changing of sizes of the skybox
- with appropriate size I got very good fog effect on the skybox.

Very useful! Just one line of code :lol

Posted: Wed Dec 08, 2004 4:09 pm
by bal
etcaptor, do you have screenshots/an example program of those effects? They seem to be really nice :).

Posted: Wed Dec 08, 2004 6:30 pm
by etcaptor
Hi bal,
I'll will post tonight, but cannot post rotation :lol:
When good options for fog and sizes for the skybox are used, you can get more realistic scene. I will post some options for example.
I use my visual editor at now for testing, because I,m so lazy to write example program, but can say that you can get this with only several lines of code.

OK, posted. You can see pictures here:

http://irrlicht.sourceforge.net/phpBB2/ ... php?t=4470

BUG IN CSkyboxSceneNode with fix

Posted: Wed Dec 08, 2004 10:51 pm
by etcaptor
There is a bug in ScyBoxSceneNode. Exactly tis is a displacement. Materials and textures are displace towar constructor parameters.

Code: Select all

addSkyBoxSceneNode  (  video::ITexture *    top,  
  video::ITexture *    bottom,  
  video::ITexture *    left,  
  video::ITexture *    right,  
  video::ITexture *    front,  
  video::ITexture *    back,  
  ISceneNode *    parent = 0,  
  s32    id = -1 
 ) 
But we get

Code: Select all

 video::ITexture *    front,  
  video::ITexture *    left,  
  video::ITexture *    back,  
  video::ITexture *    right,  
  video::ITexture *    top,  
  video::ITexture *    bottom,  
instead.

FIX:

Code: Select all

	// create top side

	Material[0] = mat;
	Material[0].Texture1 = top;

	Vertices[0] = video::S3DVertex( l, l, l, 0,-1,0, video::SColor(255,255,255,255), o, o);
	Vertices[1] = video::S3DVertex(-l, l, l, 0,-1,0, video::SColor(255,255,255,255), o, t);
	Vertices[2] = video::S3DVertex(-l, l,-l, 0,-1,0, video::SColor(255,255,255,255), t, t);
	Vertices[3] = video::S3DVertex( l, l,-l, 0,-1,0, video::SColor(255,255,255,255), t, o);

	// create bottom side

	Material[1] = mat;
	Material[1].Texture1 = bottom;

	Vertices[4] = video::S3DVertex(-l,-l, l, 0,1,0, video::SColor(255,255,255,255), o, o);
	Vertices[5] = video::S3DVertex( l,-l, l, 0,1,0, video::SColor(255,255,255,255), o, t);
	Vertices[6] = video::S3DVertex( l,-l,-l, 0,1,0, video::SColor(255,255,255,255), t, t);
	Vertices[7] = video::S3DVertex(-l,-l,-l, 0,1,0, video::SColor(255,255,255,255), t, o);

	// create left side

	Material[2] = mat;
	Material[2].Texture1 = left;

	Vertices[8] = video::S3DVertex( l,-l,-l, -1,0,0, video::SColor(255,255,255,255), o, t);
	Vertices[9] = video::S3DVertex( l,-l, l, -1,0,0, video::SColor(255,255,255,255), t, t);
	Vertices[10] = video::S3DVertex( l, l, l, -1,0,0, video::SColor(255,255,255,255), t, o);
	Vertices[11] = video::S3DVertex( l, l,-l, -1,0,0, video::SColor(255,255,255,255), o, o);


	// create right side


	Material[3] = mat;
	Material[3].Texture1 = right;

	Vertices[12] = video::S3DVertex(-l,-l, l, 1,0,0, video::SColor(255,255,255,255), o, t);
	Vertices[13] = video::S3DVertex(-l,-l,-l, 1,0,0, video::SColor(255,255,255,255), t, t);
	Vertices[14] = video::S3DVertex(-l, l,-l, 1,0,0, video::SColor(255,255,255,255), t, o);
	Vertices[15] = video::S3DVertex(-l, l, l, 1,0,0, video::SColor(255,255,255,255), o, o);

   // create front side

	Material[4] = mat;  
	Material[4].Texture1 = front;    

 	Vertices[16] = video::S3DVertex(-l,-l,-l, 0,0,1, video::SColor(255,255,255,255), o, t);
	Vertices[17] = video::S3DVertex( l,-l,-l, 0,0,1, video::SColor(255,255,255,255), t, t);
	Vertices[18] = video::S3DVertex( l, l,-l, 0,0,1, video::SColor(255,255,255,255), t, o);
	Vertices[19] = video::S3DVertex(-l, l,-l, 0,0,1, video::SColor(255,255,255,255), o, o);


	// create back side

	Material[5] = mat;               
 	Material[5].Texture1 = back;   

	Vertices[20]  = video::S3DVertex( l,-l, l, 0,0,-1, video::SColor(255,255,255,255), o, t);
	Vertices[21]  = video::S3DVertex(-l,-l, l, 0,0,-1, video::SColor(255,255,255,255), t, t);
	Vertices[22] = video::S3DVertex(-l, l, l, 0,0,-1, video::SColor(255,255,255,255), t, o);
	Vertices[23] = video::S3DVertex( l, l, l, 0,0,-1, video::SColor(255,255,255,255), o, o);

Posted: Thu Dec 09, 2004 2:25 pm
by Spintz
Well, I was going to post all my code for how I implemented a SkyDome ( actually a sphere ), completely in irrlicht, with the option of either loading a texture on it, or shading the sphere based on times of day with plain colors. Also with the ability to add a rotating cloud "layer" as well as automatic rotation of the SkyDome based on time, however since these shitty forums keep timing out on me, I lost the post and I'm not going to re-type it. If anyone's interested in the code, email me and I can show it to you.

Better yet, I'll get the code posted on my website and I'll link to it. I'll post here when I get the code up..

Posted: Thu Dec 09, 2004 6:24 pm
by Guest
Sounds very interesting. I'll be waiting for the link to your site.

Posted: Thu Dec 09, 2004 6:26 pm
by etcaptor
:oops: Sorry forgot to login.

Posted: Fri Dec 10, 2004 1:04 am
by Spintz
Here's the link to the page -

My code here at home is not as up to date as the code I have at work for my engine. This code doesn't yet have the rotation in or the option to fade colors of the sky by a day/nite ratio.

http://www.spintz.com/irrlicht/irrlichtskydome.php

Email me or PM me to report bugs, request features, or curse me out for it just plain not working!

Hope it helps you all! Looks a million times better than a SkyBox!

Posted: Fri Dec 10, 2004 1:46 am
by etcaptor
Thanks, looking promising. I will test it this weekend. And of course we will waiting for any changes if you update your code.

Posted: Fri Dec 10, 2004 2:44 am
by Spintz
I added a screenshot to that page ( and changed the location or it, put it all in an irrlicht directoy on my webpage ) so that you can see how it looks, with a very quickly generated texture.

It looks really, really nice with the clouds and rotation added to it! I'll try and get that updated tomorrow!

Posted: Sun Dec 12, 2004 10:56 am
by Rush
I took a look at your code. Wouldn't it be faster to write a single drawIndexedTriangleList call in the render() method, instead of calling it for each single quad?

Posted: Sun Dec 12, 2004 2:02 pm
by Spintz
Yes, however, in the future versions, you will be allowed to change the resolution of the skybox, and then you cannot have static indices. As they will change based on the resolution of the skybox.

About Skydome

Posted: Mon Feb 07, 2005 1:42 pm
by angel80
Hi,
I'm an irrlicht begginer user. I'd like to make a outdoor scene, to do I'd like to make a skydome instead of skybox. Can u post your code of skydome because I can't reach your link..
Thank a lot

Posted: Tue Feb 08, 2005 7:23 pm
by cartoonit
This might be just the version of the engine that I am using 0.7, but where's this wrong construction of the skybox??

Code: Select all

virtual ISceneNode* addSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom,
video::ITexture* left, video::ITexture* right, video::ITexture* front,
video::ITexture* back, ISceneNode* parent = 0, s32 id=-1);
Then in the call I have the following sent over to the constructor

Code: Select all

CSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom, video::ITexture* left,
video::ITexture* right, video::ITexture* front, video::ITexture* back, ISceneNode* parent, ISceneManager* mgr, s32 id)
What I don't understand is:

Code: Select all

But we get

    code:  video::ITexture *    front, 
      video::ITexture *    left, 
      video::ITexture *    back, 
      video::ITexture *    right, 
      video::ITexture *    top, 
      video::ITexture *    bottom,