Cleanup example 22.MaterialViewer

Using default light values which work a bit better with cube.
But really needs another cube-type (which Irrlicht has not yet, needs single material with 24 vertices)
as a cube with vertex normals which average connected sides is horrible with vertex-lighting
(the problem is that the light get's behind the plane formed by the vertex-normal this way which is super confusing).
Will probably add another cube-type soon.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6312 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2022-03-20 19:09:40 +00:00
parent 73247f4a21
commit f61b8614ab

@ -182,7 +182,7 @@ void CColorControl::setColor(const video::SColor& col)
setEditsFromColor(Color); setEditsFromColor(Color);
} }
// Add a staticbox for a description + an editbox so users can enter numbers // Add a statictext for a description + an editbox so users can enter numbers
gui::IGUIEditBox* CColorControl::addEditForNumbers(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text, s32 id, gui::IGUIElement * parent) gui::IGUIEditBox* CColorControl::addEditForNumbers(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text, s32 id, gui::IGUIElement * parent)
{ {
using namespace gui; using namespace gui;
@ -195,7 +195,7 @@ gui::IGUIEditBox* CColorControl::addEditForNumbers(gui::IGUIEnvironment* guiEnv,
return edit; return edit;
} }
// Get the color value from the editfields // Get the color value from the editboxes
video::SColor CColorControl::getColorFromEdits() const video::SColor CColorControl::getColorFromEdits() const
{ {
video::SColor col; video::SColor col;
@ -227,7 +227,7 @@ video::SColor CColorControl::getColorFromEdits() const
return col; return col;
} }
// Fill the editfields with the value for the given color // Fill the editboxes with a color value
void CColorControl::setEditsFromColor(video::SColor col) void CColorControl::setEditsFromColor(video::SColor col)
{ {
DirtyFlag = true; DirtyFlag = true;
@ -382,13 +382,15 @@ void CTextureControl::selectTextureByName(const irr::core::stringw& name)
void CTextureControl::updateTextures(video::IVideoDriver * driver) void CTextureControl::updateTextures(video::IVideoDriver * driver)
{ {
s32 oldSelected = ComboTexture->getSelected(); s32 oldSelected = ComboTexture->getSelected();
s32 selectNew = -1;
core::stringw oldTextureName; core::stringw oldTextureName;
if ( oldSelected >= 0 ) if ( oldSelected >= 0 )
{ {
oldTextureName = ComboTexture->getItem(oldSelected); oldTextureName = ComboTexture->getItem(oldSelected);
} }
ComboTexture->clear(); ComboTexture->clear();
s32 selectNew = -1;
for ( u32 i=0; i < driver->getTextureCount(); ++i ) for ( u32 i=0; i < driver->getTextureCount(); ++i )
{ {
video::ITexture * texture = driver->getTextureByIndex(i); video::ITexture * texture = driver->getTextureByIndex(i);
@ -579,9 +581,7 @@ void CLightNodeControl::update(scene::ILightSceneNode* node)
Main application class Main application class
*/ */
/* // Event handler
Event handler
*/
bool CApp::OnEvent(const SEvent &event) bool CApp::OnEvent(const SEvent &event)
{ {
if (event.EventType == EET_GUI_EVENT) if (event.EventType == EET_GUI_EVENT)
@ -609,7 +609,7 @@ bool CApp::OnEvent(const SEvent &event)
case gui::EGET_FILE_SELECTED: case gui::EGET_FILE_SELECTED:
{ {
// load the model file, selected in the file open dialog // load the texture file, selected in the file open dialog
gui::IGUIFileOpenDialog* dialog = gui::IGUIFileOpenDialog* dialog =
(gui::IGUIFileOpenDialog*)event.GUIEvent.Caller; (gui::IGUIFileOpenDialog*)event.GUIEvent.Caller;
loadTexture(io::path(dialog->getFileName()).c_str()); loadTexture(io::path(dialog->getFileName()).c_str());
@ -729,12 +729,19 @@ bool CApp::init(int argc, char *argv[])
// add one light // add one light
NodeLight = smgr->addLightSceneNode(0, core::vector3df(0, 0, -40), const f32 lightRadius = 80.f;
NodeLight = smgr->addLightSceneNode(0, core::vector3df(0, 0, -70),
video::SColorf(1.0f, 1.0f, 1.0f), video::SColorf(1.0f, 1.0f, 1.0f),
35.0f); lightRadius);
LightControl = new CLightNodeControl(); LightControl = new CLightNodeControl();
LightControl->init(NodeLight, guiEnv, core::position2d<s32>(550,controlsTop), L"Dynamic light" ); LightControl->init(NodeLight, guiEnv, core::position2d<s32>(550,controlsTop), L"Dynamic light" );
#if 0 // enable to have some visual feedback for the light size
scene::IMeshSceneNode* lightRadiusNode = smgr->addSphereSceneNode(lightRadius, 64, NodeLight);
lightRadiusNode->getMaterial(0).Lighting = false;
lightRadiusNode->getMaterial(0).Wireframe = true;
#endif
// one large cube around everything. That's mainly to make the light more obvious. // one large cube around everything. That's mainly to make the light more obvious.
scene::IMeshSceneNode* backgroundCube = smgr->addCubeSceneNode (200.0f, 0, -1, core::vector3df(0, 0, 0), scene::IMeshSceneNode* backgroundCube = smgr->addCubeSceneNode (200.0f, 0, -1, core::vector3df(0, 0, 0),
core::vector3df(45, 0, 0), core::vector3df(45, 0, 0),
@ -769,8 +776,7 @@ bool CApp::update()
return false; return false;
// Figure out delta time since last frame // Figure out delta time since last frame
ITimer * timer = Device->getTimer(); u32 newTick = Device->getTimer()->getRealTime();
u32 newTick = timer->getRealTime();
f32 deltaTime = RealTimeTick > 0 ? f32(newTick-RealTimeTick)/1000.f : 0.f; // in seconds f32 deltaTime = RealTimeTick > 0 ? f32(newTick-RealTimeTick)/1000.f : 0.f; // in seconds
RealTimeTick = newTick; RealTimeTick = newTick;
@ -958,7 +964,7 @@ void CApp::createDefaultTextures(video::IVideoDriver * driver)
imageA8R8G8B8->drop(); imageA8R8G8B8->drop();
} }
// Load a texture and make sure nodes know it when more textures are available. // Load a texture and make sure UI knows it when more textures are available.
void CApp::loadTexture(const io::path &name) void CApp::loadTexture(const io::path &name)
{ {
Device->getVideoDriver()->getTexture(name); Device->getVideoDriver()->getTexture(name);