Light doesn't work !!

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
troopa
Posts: 28
Joined: Thu Mar 23, 2006 11:00 am
Location: Toulouse (France)
Contact:

Light doesn't work !!

Post by troopa »

I have a problem with Light. I have a sphere which is red and I would like to light it. I have try many things but I don't manage to have Light effect on my sphere, it's desperatly red.

Did you have any remark on the code I wrote :

Code: Select all

	scene::ISceneNode* node = NULL ; 
	scene::IAnimatedMesh* sphere = device->getSceneManager()->getMesh("./ressources/sphere.obj"); 
	if (!sphere) 
	{
		printf("incorrect filename\n"); 
		return 1; 
	}
	
	// red sphere
	node = device->getSceneManager()->addAnimatedMeshSceneNode(sphere);
	node->setPosition(core::vector3df(0,0,200));
	node->setMaterialType(video::EMT_SOLID);
	node->getMaterial(0).AmbientColor = video::SColor( 255, 255, 0, 0 );
	node->getMaterial(0).DiffuseColor = video::SColor( 255, 255, 255, 255 );
	node->getMaterial(0).SpecularColor = video::SColor( 255, 255, 255, 255 );
	//node->getMaterial(0).EmissiveColor = video::SColor( 250, 250, 250, 250 );
	node->setMaterialFlag(video::EMF_LIGHTING, true);
	
	// light juste over the red sphere
	scene::ILightSceneNode * pLight = device->getSceneManager()->addLightSceneNode( node );
	pLight->setPosition(core::vector3df(0,50,0));
	pLight->getLightData().AmbientColor = video::SColorf( 1.f, 1.f, 1.f );
	pLight->getLightData().DiffuseColor = video::SColorf( 1.f, 1.f, 1.f );
	pLight->getLightData().Position = pLight->getPosition() ; 
	pLight->getLightData().SpecularColor = video::SColorf( 1.f, 1.f, 1.f );
	pLight->setDebugDataVisible( true );
	pLight->getLightData().Radius = 200 ;
Thanks for your answers !
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think it's diffuse color you want to set to red, ambient color is the color for no light. And when setting the position of the sphere to 0,0,200 and that one of the light to 0,50,0 with a radius of 200 your light won't reach the sphere unless it's pretty huge. The radius should be at least the square root of 200^2+50^2 (pythagoras).
Post Reply