Dynamic World

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
AlexisBlaze
Posts: 3
Joined: Thu Oct 23, 2008 2:08 pm

Dynamic World

Post by AlexisBlaze »

Hi.. I'm rather new to 3d games development.. On my latest rpg project.. i'm trying to design a 3d world that is keep changing base on the character movement.. something like the grimm..

it will be like this.. in it initial state.. the world will look dark and gloomy.. and then.. when the character moved.. part of the world that is visited by the character will lighten.. it would be great if this trantition can be animated..

for sprite like plantation.. or building.. i think i can just create an animatedmesh that goes from gloomy to light.. and play the animation when the character get close enough.. but how do we do this for the terrain/world?

on a 2d games.. i think i can achive something like this using tile set.. and just change the image rendered for each tile that has been visited.. but how can we achive this in 3d world?

can we do something like.. create a plane that has 2 material.. in initial state.. only the default material will be shown.. but when the character moved.. part of this default material will be transparent and the other material will be shown.. or maybe 2 plane.. one with the gloomy material.. and the other with the lighten material..

anyone got an idea?? thx.. :)
- Learn Something About Everything And Everything About Something -
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Why not just use lighting and increase the strength of the light as necessary?
Image Image Image
AlexisBlaze
Posts: 3
Joined: Thu Oct 23, 2008 2:08 pm

Post by AlexisBlaze »

coz the material for the gloomy mood and the lighten mood will be different.. hmm.. for an example.. on a rocky terrain.. the gloomy mood will have a rock that crack.. but on the lighten mood.. the rock will be solid and shiny.. for a flower.. on the gloomy mood.. it will look dead and grey.. on the other hand.. it will look fresh and collorfull..

thx for the quick reply.. :)
- Learn Something About Everything And Everything About Something -
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

ok, ok, i thought it was just a lighting issue rather than different textures all together.

so yeah... you could use a double layered material on the objects and alter the weight of which texture comes through most... that would probably require you to write your own shader for it, i don't know if you know how to do shaders thought...

alternatively you could double up everything so there's two of each nodes... imagine a rock.. you have the same rock twice; one with the dull material, one with the bright. The bright one is invisible to start with When you want to trigger the change you make the bright one visible but completely transparent and then fade it in and fade out the dull one. Not sure if it's actually possible to fade objects that easily though...
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

EMT_SOLID_2_LAYER will do the trick if you're using the D3D driver. It's not implemented on OGL though. :(

This example uses a general purpose method to get the nearest vertex to a line through the cursor. You should be able to find a smarter method of finding the vertex / vertices in your game world that need manipulated.

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

#pragma comment(lib, "Irrlicht.lib")

S3DVertex * findNearestVertex(IAnimatedMeshSceneNode * node,
							  const line3df & line)
{
	IMeshBuffer * buffer = node->getMesh()->getMeshBuffer(0);
	const u32 vertexCount = buffer->getVertexCount();
	S3DVertex * vertices = (S3DVertex*)buffer->getVertices();

	line3df localLine(line);
	matrix4 inverseTransform;
	if(!node->getAbsoluteTransformation().getInverse(inverseTransform))
		return 0; 

	inverseTransform.transformVect(localLine.start);
	inverseTransform.transformVect(localLine.end); 

	S3DVertex * closestVertex = 0;
	f32 closestDistanceSq = 0.f;

	for(u32 i = 0; i < vertexCount; ++i)
	{
		S3DVertex * vertex = vertices + i;
		const f32 distanceSq = (localLine.getClosestPoint(vertex->Pos) - vertex->Pos).getLengthSQ();

		if(!closestVertex || distanceSq < closestDistanceSq)
		{
			closestDistanceSq = distanceSq;
			closestVertex = vertex;
		}
	}

	return closestVertex;
}


int main()
{
	// Normally I'd use EDT_OPENGL, but EMT_SOLID_2_LAYER isn't implemented
	IrrlichtDevice *device =
		createDevice(EDT_DIRECT3D9, core::dimension2d<s32>(640, 480), 32);

	if (device == 0)
		return 1; // could not create selected driver.

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

        // This example uses a hill plane mesh for simplicity, but it
        // should work with any mesh.
	IAnimatedMesh * mesh = smgr->addHillPlaneMesh("myHills",
		core::dimension2d<f32>(10.f, 10.f),
		core::dimension2d<u32>(10, 10),
		0,
		10.f,
		core::dimension2d<f32>(3.f, 3.f),
		core::dimension2d<f32>(10.f, 10.f));

	IAnimatedMeshSceneNode * node = smgr->addAnimatedMeshSceneNode(mesh);

	node->setMaterialTexture(0, driver->getTexture("../../media/stones.jpg"));
	node->setMaterialTexture(1, driver->getTexture("../../media/wall.bmp"));

	node->setMaterialType(video::EMT_SOLID_2_LAYER);

	ICameraSceneNode* camera = smgr->addCameraSceneNode();
	camera->setPosition(vector3df(0,50,-50));
	camera->setTarget(vector3df(0,0,-20));


	while(device->run())
	if (device->isWindowActive())
	{
		const line3df cursorRay = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(device->getCursorControl()->getPosition(), camera);

		S3DVertex * closestVertex = findNearestVertex(node, cursorRay);

                // Reducing the alpha of the vertex will blend in the 0th texture.
		if(closestVertex && closestVertex->Color.getAlpha() > 0)
			closestVertex->Color.setAlpha(closestVertex->Color.getAlpha() - 1);

		driver->beginScene(true, true, 0);
		smgr->drawAll();
		driver->endScene();
	}

	device->drop();

	return 0;
}

Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
AlexisBlaze
Posts: 3
Joined: Thu Oct 23, 2008 2:08 pm

Post by AlexisBlaze »

This is exactly what i've been looking for.. been searching for a way to manipulate the alpha value.. thx a lot.. :)
- Learn Something About Everything And Everything About Something -
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It was my pleasure. That was a fun little app to write.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply