I read with interest the other thread on lighting … but I’m having trouble with using the LightAttrib class.
The Python code I’m trying to convert is:
lAttrib = LightAttrib.makeAllOff()
ambientLight = AmbientLight( "ambientLight" )
ambientLight.setColor( Vec4( .8, .8, .8, 1 ) )
lAttrib = lAttrib.addLight( ambientLight )
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setDirection( Vec3( 0, 45, -45 ) )
directionalLight.setColor( Vec4( 0.2, 0.2, 0.2, 1 ) )
lAttrib = lAttrib.addLight( directionalLight )
render.attachNewNode( directionalLight.upcastToPandaNode() )
render.attachNewNode( ambientLight.upcastToPandaNode() )
render.node().setAttrib( lAttrib )
Now, I can convert most of this into C++, but no matter what I try, I can’t create or use a LightAttrib type …
This is what I came up with …
{
NodePath render = window->get_render();
PT(LigthAttrib) lightAttrib = new LightAttrib( "lightAttrib" );
PT(AmbientLight) ambientLight = new AmbientLight( "ambientLight" );
ambientLight->set_color( LVecBase4f( .8, .8, .8, 1 ) );
lightAttrib->add_on_light( DCAST(PandaNode,ambientLight) );
PT(DirectionalLight) directionalLight = new DirectionalLight( "directionalLight" );
directionalLight->set_direction( LVecBase3f( 0, 45, -45 ) );
directionalLight->set_color( LVecBase4f( 0.2, 0.2, 0.2, 1 ) );
lightAttrib->add_on_light( DCAST(PandaNode,directionalLight) );
render.attach_new_node(DCAST(PandaNode, directionalLight));
render.attach_new_node(DCAST(PandaNode, ambientLight));
render.node().setAttrib(lightAttrib);
}
This code does not compile, but if I remove the references to lattrib it compiles, but does not work … I get a variety of errors no matter what I try for use of LightAttrib. There are comments in the lightattirb.h file about not using the old interface … but basically none of the public functions seem to be useable …
Any help would be greatly appreciated!
Any more C++ documenation or more importantly sample code would be MUCH appreciated. I have been coding C and C++ for over 20 years, but getting my head around these classes without sample code is very very difficult.
Thanks again,
Joseph