day and night world map [solved]

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
milkshakeman
Posts: 27
Joined: Mon Aug 14, 2006 12:36 pm

day and night world map [solved]

Post by milkshakeman »

Hi,

I'm trying to create a day/night world map effect, like on this site:
http://www.timeanddate.com/worldclock/sunearth.html

So there is one day texture in the background, and a night texture on top with a transparency mask that offsets horizontally depending on the time of the day.

Anybody an idea what the best approach would be to achieve this using irrLicht?


Thanks
Last edited by milkshakeman on Fri Jan 15, 2010 10:58 pm, edited 1 time in total.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: day and night world map

Post by randomMesh »

This has been discussed before, using the search function might help.
e.g. http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=28931

Additionally, there's a RTTSkyBoxSceneNode in the irrExt repository.
"Whoops..."
milkshakeman
Posts: 27
Joined: Mon Aug 14, 2006 12:36 pm

Post by milkshakeman »

While the solution with the directional light simulating the sun is nice, but first of all it only works good in 3D when rendering the world as a sphere, and I'm working in 2D, rendering the world as a flat plane.
And the real earth night texture with all the city-lights looks nicer than just creating a shadow.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Either use two planes one over the other, or use the solid_2texture material. Then you need to change the vertex alpha to blend between the two textures.
milkshakeman
Posts: 27
Joined: Mon Aug 14, 2006 12:36 pm

Post by milkshakeman »

Thanks hybrid, I got it to work with that second method you suggested.
I even used a sphere, which was a bit tricky.

Anyway, below is my code, not cleaned up or optimised but if anyone ever wanted to update one half of a sphere's vertices alpha, it may help to have a look.

Code: Select all

	polycount=512;
	// add the node
	globe = smgr->addSphereSceneNode(10,polycount);
	// add the textures
	globe->setMaterialTexture(0, graphics->driver->getTexture("media/Earth.png"));
	globe->setMaterialTexture(1, graphics->driver->getTexture("media/EarthNight.png"));
	//globe->setMaterialFlag( video::EMF_WIREFRAME, true );
	globe->setMaterialFlag( video::EMF_LIGHTING, false );
	globe->setMaterialType( video::EMT_SOLID_2_LAYER );
	setGlobeDayNightOffset(0);

Code: Select all

void setGlobeDayNightOffset(int degrees)
{
	int oS,oE;
	if (degrees>180){
		oS=(degrees*(polycount+1))/360;
		oE=oS-((polycount+1)/2);
	}else{
		oS=(degrees*(polycount+1))/360;
		oE=oS+((polycount+1)/2);
	}

	// set all vertices to 0 alpha
	smgr->getMeshManipulator()->setVertexColorAlpha(globe->getMesh(),0);
	// run through the vertices and update the alpha
	// on one half of the sphere
	int meshBufferCount = globe->getMesh()->getMeshBufferCount();
	for (int mb=0;mb<meshBufferCount;mb++)
	{
		S3DVertex* v = (S3DVertex*)globe->getMesh()->getMeshBuffer(mb)->getVertices();
		int cnt = globe->getMesh()->getMeshBuffer(mb)->getVertexCount();
		int slice=0;
		for (int i=0;i<globe->getMesh()->getMeshBuffer(mb)->getVertexCount();i++)
		{
			if (oE<oS){
				if ((slice>=0 && slice <oE) || (slice>=oS && slice <(polycount+1)))
					v[i].Color.setAlpha(255);
			}else{
				if (slice>=oS && slice <oE)
					v[i].Color.setAlpha(255);
			}
			slice++;
			if (slice==polycount){
				slice=0;
				i++;
				v[i].Color.setAlpha(v[i-1].Color.getAlpha());
			}
		}
	}
}
Post Reply