Commit d262f108 authored by cutealien's avatar cutealien

Cleaning up example 22 MaterialViewer.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2970 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 0e21f80e
...@@ -6,8 +6,8 @@ Sources = main.cpp ...@@ -6,8 +6,8 @@ Sources = main.cpp
# general compiler settings # general compiler settings
CPPFLAGS = -I../../include -I/usr/X11R6/include CPPFLAGS = -I../../include -I/usr/X11R6/include
CXXFLAGS = -O3 -ffast-math #CXXFLAGS = -O3 -ffast-math
#CXXFLAGS = -g -Wall CXXFLAGS = -g -Wall
#default target is Linux #default target is Linux
all: all_linux all: all_linux
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
This example can be used to play around with material settings and watch the results. This example can be used to play around with material settings and watch the results.
Only the default non-shader materials are used in here. Only the default non-shader materials are used in here.
You have two nodes to make it easier to see which difference your settings will make.
Additionally you have one lightscenenode and you can set the global ambient values.
*/ */
#include <irrlicht.h> #include <irrlicht.h>
...@@ -13,7 +17,10 @@ using namespace irr; ...@@ -13,7 +17,10 @@ using namespace irr;
#pragma comment(lib, "Irrlicht.lib") #pragma comment(lib, "Irrlicht.lib")
#endif #endif
namespace // empty namespace makes sure all variables in here are only defined local in this file. /*
Variables within the empty namespace are globals which are restricted to this file.
*/
namespace
{ {
const wchar_t* const DriverTypeNames[] = const wchar_t* const DriverTypeNames[] =
{ {
...@@ -22,41 +29,45 @@ namespace // empty namespace makes sure all variables in here are only defined l ...@@ -22,41 +29,45 @@ namespace // empty namespace makes sure all variables in here are only defined l
L"BURNINGSVIDEO", L"BURNINGSVIDEO",
L"DIRECT3D8", L"DIRECT3D8",
L"DIRECT3D9", L"DIRECT3D9",
L"EDT_OPENGL", L"OPENGL",
0, 0,
}; };
// For the gui id's
enum EGUI_IDS enum EGUI_IDS
{ {
GUI_ID_OPEN_TEXTURE = 1, GUI_ID_OPEN_TEXTURE = 1,
GUI_ID_QUIT, GUI_ID_QUIT,
GUI_ID_MAX
}; };
// Name used in texture selection to clear the textures on the node
const core::stringw CLEAR_TEXTURE = "CLEAR texture"; const core::stringw CLEAR_TEXTURE = "CLEAR texture";
const irr::video::SColor SCOL_BLACK = irr::video::SColor(255, 0, 0, 0); // some useful color constants
const irr::video::SColor SCOL_BLUE = irr::video::SColor(255, 0, 0, 255); const video::SColor SCOL_BLACK = video::SColor(255, 0, 0, 0);
const irr::video::SColor SCOL_CYAN = irr::video::SColor(255, 0, 255, 255); const video::SColor SCOL_BLUE = video::SColor(255, 0, 0, 255);
const irr::video::SColor SCOL_GRAY = irr::video::SColor(255, 128,128, 128); const video::SColor SCOL_CYAN = video::SColor(255, 0, 255, 255);
const irr::video::SColor SCOL_GREEN = irr::video::SColor(255, 0, 255, 0); const video::SColor SCOL_GRAY = video::SColor(255, 128,128, 128);
const irr::video::SColor SCOL_MAGENTA = irr::video::SColor(255, 255, 0, 255); const video::SColor SCOL_GREEN = video::SColor(255, 0, 255, 0);
const irr::video::SColor SCOL_RED = irr::video::SColor(255, 255, 0, 0); const video::SColor SCOL_MAGENTA = video::SColor(255, 255, 0, 255);
const irr::video::SColor SCOL_YELLOW = irr::video::SColor(255, 255, 255, 0); const video::SColor SCOL_RED = video::SColor(255, 255, 0, 0);
const irr::video::SColor SCOL_WHITE = irr::video::SColor(255, 255, 255, 255); const video::SColor SCOL_YELLOW = video::SColor(255, 255, 255, 0);
const video::SColor SCOL_WHITE = video::SColor(255, 255, 255, 255);
}; // namespace }; // namespace
/* /*
Returns a new unique number on each call Returns a new unique number on each call.
*/ */
s32 makeUniqueId() s32 makeUniqueId()
{ {
static int unique = 10000; static int unique = GUI_ID_MAX;
++unique; ++unique;
return unique; return unique;
} }
/* /*
Find out which vertex-type is needed for the given material type Find out which vertex-type is needed for the given material type.
*/ */
video::E_VERTEX_TYPE getVertexTypeForMaterialType(video::E_MATERIAL_TYPE materialType) video::E_VERTEX_TYPE getVertexTypeForMaterialType(video::E_MATERIAL_TYPE materialType)
{ {
...@@ -121,24 +132,42 @@ video::E_VERTEX_TYPE getVertexTypeForMaterialType(video::E_MATERIAL_TYPE materia ...@@ -121,24 +132,42 @@ video::E_VERTEX_TYPE getVertexTypeForMaterialType(video::E_MATERIAL_TYPE materia
} }
/* /*
Control for setting colors Custom GUI-control to edit colorvalues.
NOTE: Like with other controls it might have been a good idea deriving this from IGUIElement and make real gui controls of those.
This also works, but using real gui-controls might be cleaner.
*/ */
class CColorControl : public IEventReceiver class CColorControl : public gui::IGUIElement
{ {
public: public:
CColorControl() // Constructor
: DirtyFlag(true) CColorControl(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text, IGUIElement* parent, s32 id=-1 )
: gui::IGUIElement(gui::EGUIET_ELEMENT, guiEnv, parent,id, core::rect< s32 >(pos, pos+core::dimension2d<s32>(80, 75)))
, DirtyFlag(true)
, ColorStatic(0) , ColorStatic(0)
, EditAlpha(0) , EditAlpha(0)
, EditRed(0) , EditRed(0)
, EditGreen(0) , EditGreen(0)
, EditBlue(0) , EditBlue(0)
{ {
using namespace gui;
ButtonSetId = makeUniqueId(); ButtonSetId = makeUniqueId();
const core::rect< s32 > rectControls(0,0,AbsoluteRect.getWidth(),AbsoluteRect.getHeight() );
IGUIStaticText * groupElement = guiEnv->addStaticText (L"", rectControls, true, false, this, -1, false);
groupElement->setNotClipped(true);
guiEnv->addStaticText (text, core::rect<s32>(0,0,80,15), false, false, groupElement, -1, false);
EditAlpha = addEditForNumbers(guiEnv, core::position2d<s32>(0,15), L"a", -1, groupElement );
EditRed = addEditForNumbers(guiEnv, core::position2d<s32>(0,30), L"r", -1, groupElement );
EditGreen = addEditForNumbers(guiEnv, core::position2d<s32>(0,45), L"g", -1, groupElement );
EditBlue = addEditForNumbers(guiEnv, core::position2d<s32>(0,60), L"b", -1, groupElement );
ColorStatic = guiEnv->addStaticText (L"", core::rect<s32>(60,15,80,75), true, false, groupElement, -1, true);
guiEnv->addButton (core::rect<s32>(60,35,80,50), groupElement, ButtonSetId, L"set");
SetEditsFromColor(Color);
} }
// event receiver
virtual bool OnEvent(const SEvent &event) virtual bool OnEvent(const SEvent &event)
{ {
if ( event.EventType != EET_GUI_EVENT ) if ( event.EventType != EET_GUI_EVENT )
...@@ -153,41 +182,24 @@ public: ...@@ -153,41 +182,24 @@ public:
return false; return false;
} }
void init( gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text ) // set the color values
{
using namespace gui;
const core::rect< s32 > rectControls(pos, core::dimension2d<s32>(80, 75));
IGUIStaticText * groupElement = guiEnv->addStaticText (L"", rectControls, true, false, 0, -1, false);
guiEnv->addStaticText (text, core::rect<s32>(0,0,80,15), false, false, groupElement, -1, false);
EditAlpha = addEditForNumbers(guiEnv, core::position2d<s32>(0,15), L"a", -1, groupElement );
EditRed = addEditForNumbers(guiEnv, core::position2d<s32>(0,30), L"r", -1, groupElement );
EditGreen = addEditForNumbers(guiEnv, core::position2d<s32>(0,45), L"g", -1, groupElement );
EditBlue = addEditForNumbers(guiEnv, core::position2d<s32>(0,60), L"b", -1, groupElement );
ColorStatic = guiEnv->addStaticText (L"", core::rect<s32>(60,15,80,75), true, false, groupElement, -1, true);
guiEnv->addButton (core::rect<s32>(60,35,80,50), groupElement, ButtonSetId, L"set");
SetEditsFromColor(Color);
}
void setColor(const video::SColor& col) void setColor(const video::SColor& col)
{ {
setDirty(true); DirtyFlag = true;
Color = col; Color = col;
SetEditsFromColor(Color); SetEditsFromColor(Color);
} }
// get the color values
const video::SColor& getColor() const const video::SColor& getColor() const
{ {
return Color; return Color;
} }
void setDirty(bool dirty) // To reset the dirty flag
void resetDirty()
{ {
DirtyFlag = dirty; DirtyFlag = false;
} }
// when the color was changed the dirty flag is set // when the color was changed the dirty flag is set
...@@ -198,11 +210,12 @@ public: ...@@ -198,11 +210,12 @@ public:
protected: protected:
// Add a staticbox for a description + an editbox so users can enter numbers
gui::IGUIEditBox* addEditForNumbers(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text, s32 id, gui::IGUIElement * parent) gui::IGUIEditBox* addEditForNumbers(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text, s32 id, gui::IGUIElement * parent)
{ {
using namespace gui; using namespace gui;
core::rect< s32 > rect(pos, core::dimension2d<s32>(10, 15)); core::rect< s32 > rect(pos, pos+core::dimension2d<s32>(10, 15));
guiEnv->addStaticText (text, rect, false, false, parent, -1, false); guiEnv->addStaticText (text, rect, false, false, parent, -1, false);
rect += core::position2d<s32>( 20, 0 ); rect += core::position2d<s32>( 20, 0 );
rect.LowerRightCorner.X += 20; rect.LowerRightCorner.X += 20;
...@@ -210,6 +223,7 @@ protected: ...@@ -210,6 +223,7 @@ protected:
return edit; return edit;
} }
// Get the color value from the editfields
video::SColor GetColorFromEdits() video::SColor GetColorFromEdits()
{ {
video::SColor col; video::SColor col;
...@@ -241,7 +255,6 @@ protected: ...@@ -241,7 +255,6 @@ protected:
} }
col.setGreen(green); col.setGreen(green);
u32 blue=col.getBlue(); u32 blue=col.getBlue();
if ( EditBlue ) if ( EditBlue )
{ {
...@@ -254,9 +267,10 @@ protected: ...@@ -254,9 +267,10 @@ protected:
return col; return col;
} }
// Fill the editfields with the value for the given color
void SetEditsFromColor(video::SColor col) void SetEditsFromColor(video::SColor col)
{ {
setDirty(true); DirtyFlag = true;
if ( EditAlpha ) if ( EditAlpha )
EditAlpha->setText( core::stringw(col.getAlpha()).c_str() ); EditAlpha->setText( core::stringw(col.getAlpha()).c_str() );
if ( EditRed ) if ( EditRed )
...@@ -282,64 +296,101 @@ private: ...@@ -282,64 +296,101 @@ private:
}; };
/* /*
Control for setting colors typically used in materials Custom GUI-control for to edit all colors typically used in materials and lights
*/ */
struct SAllColorsControl struct CAllColorsControl : public gui::IGUIElement
{ {
virtual bool OnEvent(const SEvent &event) // Constructor
CAllColorsControl(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description, bool hasEmissive, IGUIElement* parent, s32 id=-1)
: gui::IGUIElement(gui::EGUIET_ELEMENT, guiEnv, parent,id, core::rect<s32>(pos,pos+core::dimension2d<s32>(60,250)))
, ControlAmbientColor(0), ControlDiffuseColor(0), ControlSpecularColor(0), ControlEmissiveColor(0)
{ {
if ( ControlAmbientColor.OnEvent(event) ) core::rect<s32> rect(0, 0, 60, 15);
return true; guiEnv->addStaticText (description, rect, false, false, this, -1, false);
if ( ControlDiffuseColor.OnEvent(event) ) createColorControls(guiEnv, core::position2d<s32>(0, 15), hasEmissive);
return true;
if ( ControlEmissiveColor.OnEvent(event) )
return true;
if ( ControlSpecularColor.OnEvent(event) )
return true;
return false;
} }
void init(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description, bool hasEmissive) // Destructor
virtual ~CAllColorsControl()
{ {
core::rect<s32> rect(pos, core::dimension2d<s32>(60, 15)); ControlAmbientColor->drop();
guiEnv->addStaticText (description, rect, false, false, 0, -1, false); ControlDiffuseColor->drop();
createColorControls(guiEnv, pos + core::position2d<s32>(0, 15), hasEmissive); ControlEmissiveColor->drop();
ControlSpecularColor->drop();
} }
// any colors changed? // Set the color values to those within the material
bool isDirty() const void setColorsToMaterialColors(const video::SMaterial & material)
{
ControlAmbientColor->setColor(material.AmbientColor);
ControlDiffuseColor->setColor(material.DiffuseColor);
ControlEmissiveColor->setColor(material.EmissiveColor);
ControlSpecularColor->setColor(material.SpecularColor);
}
// Update all changed colors in the material
void updateMaterialColors(video::SMaterial & material)
{ {
return ControlAmbientColor.isDirty() || ControlDiffuseColor.isDirty() || ControlSpecularColor.isDirty() || ControlEmissiveColor.isDirty(); if ( ControlAmbientColor->isDirty() )
material.AmbientColor = ControlAmbientColor->getColor();
if ( ControlDiffuseColor->isDirty() )
material.DiffuseColor = ControlDiffuseColor->getColor();
if ( ControlEmissiveColor->isDirty() )
material.EmissiveColor = ControlEmissiveColor->getColor();
if ( ControlSpecularColor->isDirty() )
material.SpecularColor = ControlSpecularColor->getColor();
} }
void setDirty(bool dirty) // Set the color values to those from the light data
void setColorsToLightDataColors(const video::SLight & lightData)
{ {
ControlAmbientColor.setDirty(dirty); ControlAmbientColor->setColor(lightData.AmbientColor.toSColor());
ControlDiffuseColor.setDirty(dirty); ControlAmbientColor->setColor(lightData.DiffuseColor.toSColor());
ControlSpecularColor.setDirty(dirty); ControlAmbientColor->setColor(lightData.SpecularColor.toSColor());
ControlEmissiveColor.setDirty(dirty);
} }
CColorControl ControlAmbientColor; // Update all changed colors in the light data
CColorControl ControlDiffuseColor; void updateMaterialColors(video::SLight & lightData)
CColorControl ControlSpecularColor; {
CColorControl ControlEmissiveColor; if ( ControlAmbientColor->isDirty() )
lightData.AmbientColor = video::SColorf( ControlAmbientColor->getColor() );
if ( ControlDiffuseColor->isDirty() )
lightData.DiffuseColor = video::SColorf( ControlDiffuseColor->getColor() );
if ( ControlSpecularColor->isDirty() )
lightData.SpecularColor = video::SColorf(ControlSpecularColor->getColor() );
}
// To reset the dirty flags
void resetDirty()
{
ControlAmbientColor->resetDirty();
ControlDiffuseColor->resetDirty();
ControlSpecularColor->resetDirty();
ControlEmissiveColor->resetDirty();
}
protected: protected:
void createColorControls(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, bool hasEmissive) void createColorControls(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, bool hasEmissive)
{ {
ControlAmbientColor.init( guiEnv, pos, L"ambient" ); ControlAmbientColor = new CColorControl( guiEnv, pos, L"ambient", this);
ControlDiffuseColor.init( guiEnv, pos + core::position2d<s32>(0, 75), L"diffuse" ); ControlDiffuseColor = new CColorControl( guiEnv, pos + core::position2d<s32>(0, 75), L"diffuse", this );
ControlSpecularColor.init( guiEnv, pos + core::position2d<s32>(0, 150), L"specular" ); ControlSpecularColor = new CColorControl( guiEnv, pos + core::position2d<s32>(0, 150), L"specular", this );
if ( hasEmissive ) if ( hasEmissive )
{ {
ControlEmissiveColor.init( guiEnv, pos + core::position2d<s32>(0, 225), L"emissive" ); ControlEmissiveColor = new CColorControl( guiEnv, pos + core::position2d<s32>(0, 225), L"emissive", this );
} }
} }
private:
CColorControl* ControlAmbientColor;
CColorControl* ControlDiffuseColor;
CColorControl* ControlSpecularColor;
CColorControl* ControlEmissiveColor;
}; };
/* /*
Control to offer a selection of available textures Control to offer a selection of available textures.
NOTE: This control and also the following two controls could as well be implemented as IGUIElements.
*/ */
struct STextureControl struct STextureControl
{ {
...@@ -354,7 +405,7 @@ struct STextureControl ...@@ -354,7 +405,7 @@ struct STextureControl
if ( event.GUIEvent.Caller == ComboTexture && event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED ) if ( event.GUIEvent.Caller == ComboTexture && event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED )
{ {
setDirty(true); DirtyFlag = true;
} }
return false; return false;
...@@ -372,9 +423,10 @@ struct STextureControl ...@@ -372,9 +423,10 @@ struct STextureControl
return ComboTexture->getItem(selected); return ComboTexture->getItem(selected);
} }
void setDirty(bool dirty) // reset the dirty flag
void resetDirty()
{ {
DirtyFlag = dirty; DirtyFlag = false;
} }
// when the texture was changed the dirty flag is set // when the texture was changed the dirty flag is set
...@@ -423,7 +475,7 @@ struct STextureControl ...@@ -423,7 +475,7 @@ struct STextureControl
if ( selectNew >= 0 ) if ( selectNew >= 0 )
ComboTexture->setSelected(selectNew); ComboTexture->setSelected(selectNew);
setDirty(true); DirtyFlag = true;
} }
private: private:
...@@ -433,22 +485,29 @@ private: ...@@ -433,22 +485,29 @@ private:
}; };
/* /*
Control which allows setting typical material values for a meshscenenode Control which allows setting some of the material values for a meshscenenode
*/ */
struct SMeshNodeControl struct SMeshNodeControl
{ {
SMeshNodeControl() : Initialized(false), Driver(0), MeshManipulator(0), SceneNode(0), SceneNode2T(0), SceneNodeTangents(0), ButtonLighting(0), ComboMaterial(0) {} // constructor
SMeshNodeControl()
: Initialized(false), Driver(0), MeshManipulator(0), SceneNode(0), SceneNode2T(0), SceneNodeTangents(0)
, AllColorsControl(0), ButtonLighting(0), ComboMaterial(0), ControlVertexColors(0)
{
}
// Destructor
virtual ~SMeshNodeControl()
{
delete ControlVertexColors;
}
virtual bool OnEvent(const SEvent &event) virtual bool OnEvent(const SEvent &event)
{ {
if ( AllColorsControl.OnEvent(event) )
return true;
if ( Texture1.OnEvent(event) ) if ( Texture1.OnEvent(event) )
return true; return true;
if ( Texture2.OnEvent(event) ) if ( Texture2.OnEvent(event) )
return true; return true;
if ( ControlVertexColors.OnEvent(event) )
return true;
return false; return false;
} }
...@@ -476,11 +535,8 @@ struct SMeshNodeControl ...@@ -476,11 +535,8 @@ struct SMeshNodeControl
video::SMaterial & material = SceneNode->getMaterial(0); video::SMaterial & material = SceneNode->getMaterial(0);
material.Lighting = true; material.Lighting = true;
AllColorsControl.init(guiEnv, pos, description, true); AllColorsControl = new CAllColorsControl(guiEnv, pos, description, true, guiEnv->getRootGUIElement());
AllColorsControl.ControlAmbientColor.setColor(material.AmbientColor); AllColorsControl->setColorsToMaterialColors(material);
AllColorsControl.ControlDiffuseColor.setColor(material.DiffuseColor);
AllColorsControl.ControlEmissiveColor.setColor(material.EmissiveColor);
AllColorsControl.ControlSpecularColor.setColor(material.SpecularColor);
core::rect<s32> rectBtn(pos + core::position2d<s32>(0, 320), core::dimension2d<s32>(100, 15)); core::rect<s32> rectBtn(pos + core::position2d<s32>(0, 320), core::dimension2d<s32>(100, 15));
ButtonLighting = guiEnv->addButton (rectBtn, 0, -1, L"Lighting"); ButtonLighting = guiEnv->addButton (rectBtn, 0, -1, L"Lighting");
...@@ -501,12 +557,12 @@ struct SMeshNodeControl ...@@ -501,12 +557,12 @@ struct SMeshNodeControl
Texture2.init(guiEnv, Driver, posTex); Texture2.init(guiEnv, Driver, posTex);
core::position2d<s32> posVertexColors( posTex.X, posTex.Y + 15); core::position2d<s32> posVertexColors( posTex.X, posTex.Y + 15);
ControlVertexColors.init( guiEnv, posVertexColors, L"Vertex colors"); ControlVertexColors = new CColorControl( guiEnv, posVertexColors, L"Vertex colors", guiEnv->getRootGUIElement());
video::S3DVertex * vertices = (video::S3DVertex *)node->getMesh()->getMeshBuffer(0)->getVertices(); video::S3DVertex * vertices = (video::S3DVertex *)node->getMesh()->getMeshBuffer(0)->getVertices();
if ( vertices ) if ( vertices )
{ {
ControlVertexColors.setColor(vertices[0].Color); ControlVertexColors->setColor(vertices[0].Color);
} }
Initialized = true; Initialized = true;
...@@ -552,10 +608,10 @@ struct SMeshNodeControl ...@@ -552,10 +608,10 @@ struct SMeshNodeControl
updateMaterial(material2T); updateMaterial(material2T);
updateMaterial(materialTangents); updateMaterial(materialTangents);
AllColorsControl.setDirty(false); AllColorsControl->resetDirty();
Texture1.setDirty(false); Texture1.resetDirty();
Texture2.setDirty(false); Texture2.resetDirty();
ControlVertexColors.setDirty(false); ControlVertexColors->resetDirty();
} }
void updateTextures() void updateTextures()
...@@ -568,13 +624,7 @@ protected: ...@@ -568,13 +624,7 @@ protected:
void updateMaterial(video::SMaterial & material) void updateMaterial(video::SMaterial & material)
{ {
if ( AllColorsControl.isDirty() ) AllColorsControl->updateMaterialColors(material);
{
material.AmbientColor = AllColorsControl.ControlAmbientColor.getColor();
material.DiffuseColor = AllColorsControl.ControlDiffuseColor.getColor();
material.EmissiveColor = AllColorsControl.ControlEmissiveColor.getColor();
material.SpecularColor = AllColorsControl.ControlSpecularColor.getColor();
}
material.Lighting = ButtonLighting->isPressed(); material.Lighting = ButtonLighting->isPressed();
if ( Texture1.isDirty() ) if ( Texture1.isDirty() )
{ {
...@@ -584,11 +634,11 @@ protected: ...@@ -584,11 +634,11 @@ protected:
{ {
material.TextureLayer[1].Texture = Driver->getTexture( io::path(Texture2.getSelectedTextureName()) ); material.TextureLayer[1].Texture = Driver->getTexture( io::path(Texture2.getSelectedTextureName()) );
} }
if ( ControlVertexColors.isDirty() ) if ( ControlVertexColors->isDirty() )
{ {
MeshManipulator->setVertexColors (SceneNode->getMesh(), ControlVertexColors.getColor()); MeshManipulator->setVertexColors (SceneNode->getMesh(), ControlVertexColors->getColor());
MeshManipulator->setVertexColors (SceneNode2T->getMesh(), ControlVertexColors.getColor()); MeshManipulator->setVertexColors (SceneNode2T->getMesh(), ControlVertexColors->getColor());
MeshManipulator->setVertexColors (SceneNodeTangents->getMesh(), ControlVertexColors.getColor()); MeshManipulator->setVertexColors (SceneNodeTangents->getMesh(), ControlVertexColors->getColor());
} }
} }
...@@ -598,26 +648,22 @@ protected: ...@@ -598,26 +648,22 @@ protected:
scene::IMeshSceneNode* SceneNode; scene::IMeshSceneNode* SceneNode;
scene::IMeshSceneNode* SceneNode2T; scene::IMeshSceneNode* SceneNode2T;
scene::IMeshSceneNode* SceneNodeTangents; scene::IMeshSceneNode* SceneNodeTangents;
SAllColorsControl AllColorsControl; CAllColorsControl* AllColorsControl;
gui::IGUIButton * ButtonLighting; gui::IGUIButton * ButtonLighting;
gui::IGUIComboBox * ComboMaterial; gui::IGUIComboBox * ComboMaterial;
STextureControl Texture1; STextureControl Texture1;
STextureControl Texture2; STextureControl Texture2;
CColorControl ControlVertexColors; CColorControl* ControlVertexColors;
}; };
/* /*
Control to allow setting the color values of a lightscenenode. Control to allow setting the color values of a lightscenenode.
*/ */
struct SLightNodeControl struct SLightNodeControl
{ {
SLightNodeControl() : Initialized(false), SceneNode(0) {} // constructor
SLightNodeControl() : Initialized(false), SceneNode(0), AllColorsControl(0)
virtual bool OnEvent(const SEvent &event)
{ {
if ( AllColorsControl.OnEvent(event) )
return true;
return false;
} }
void init(scene::ILightSceneNode* node, gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description) void init(scene::ILightSceneNode* node, gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description)
...@@ -625,15 +671,9 @@ struct SLightNodeControl ...@@ -625,15 +671,9 @@ struct SLightNodeControl
if ( Initialized || !node || !guiEnv) // initializing twice or with invalid data not allowed if ( Initialized || !node || !guiEnv) // initializing twice or with invalid data not allowed
return; return;
SceneNode = node; SceneNode = node;
AllColorsControl.init(guiEnv, pos, description, false); AllColorsControl = new CAllColorsControl(guiEnv, pos, description, false, guiEnv->getRootGUIElement());
const video::SLight & lightData = SceneNode->getLightData(); const video::SLight & lightData = SceneNode->getLightData();
if ( AllColorsControl.isDirty() ) AllColorsControl->setColorsToLightDataColors(lightData);
{
AllColorsControl.ControlAmbientColor.setColor(lightData.AmbientColor.toSColor());
AllColorsControl.ControlDiffuseColor.setColor(lightData.DiffuseColor.toSColor());
AllColorsControl.ControlSpecularColor.setColor(lightData.SpecularColor.toSColor());
AllColorsControl.setDirty(false);
}
Initialized = true; Initialized = true;
} }
...@@ -643,19 +683,17 @@ struct SLightNodeControl ...@@ -643,19 +683,17 @@ struct SLightNodeControl
return; return;
video::SLight & lightData = SceneNode->getLightData(); video::SLight & lightData = SceneNode->getLightData();
lightData.AmbientColor = video::SColorf( AllColorsControl.ControlAmbientColor.getColor() ); AllColorsControl->updateMaterialColors(lightData);
lightData.DiffuseColor = video::SColorf( AllColorsControl.ControlDiffuseColor.getColor() );
lightData.SpecularColor = video::SColorf( AllColorsControl.ControlSpecularColor.getColor() );
} }
protected: protected:
bool Initialized; bool Initialized;
scene::ILightSceneNode* SceneNode; scene::ILightSceneNode* SceneNode;
SAllColorsControl AllColorsControl; CAllColorsControl* AllColorsControl;
}; };
/* /*
Application configuration Application configuration
*/ */
struct SConfig struct SConfig
{ {
...@@ -672,20 +710,23 @@ struct SConfig ...@@ -672,20 +710,23 @@ struct SConfig
}; };
/* /*
Main application class Main application class
*/ */
class CApp : public IEventReceiver class CApp : public IEventReceiver
{ {
friend int main(int argc, char *argv[]); friend int main(int argc, char *argv[]);
public: public:
// constructor
CApp() CApp()
: IsRunning(false) : IsRunning(false)
, Device(0) , Device(0)
, Camera(0) , Camera(0)
, GlobalAmbient(0)
{ {
} }
// destructor
~CApp() ~CApp()
{ {
} }
...@@ -696,20 +737,16 @@ public: ...@@ -696,20 +737,16 @@ public:
IsRunning = false; IsRunning = false;
} }
// Event handler
virtual bool OnEvent(const SEvent &event) virtual bool OnEvent(const SEvent &event)
{ {
if ( NodeLeft.OnEvent(event) ) if ( NodeLeft.OnEvent(event) )
return true; return true;
if ( NodeRight.OnEvent(event) ) if ( NodeRight.OnEvent(event) )
return true; return true;
if ( LightControl.OnEvent(event) )
return true;
if ( GlobalAmbient.OnEvent(event) )
return true;
if (event.EventType == EET_GUI_EVENT) if (event.EventType == EET_GUI_EVENT)
{ {
//s32 id = event.GUIEvent.Caller->getID();
gui::IGUIEnvironment* env = Device->getGUIEnvironment(); gui::IGUIEnvironment* env = Device->getGUIEnvironment();
switch(event.GUIEvent.EventType) switch(event.GUIEvent.EventType)
...@@ -750,6 +787,8 @@ public: ...@@ -750,6 +787,8 @@ public:
protected: protected:
// Application initialization
// returns true when it was succesful initialized, otherwise false.
bool init(int argc, char *argv[]) bool init(int argc, char *argv[])
{ {
Config.DriverType = getDriverTypeFromConsole(); Config.DriverType = getDriverTypeFromConsole();
...@@ -803,12 +842,13 @@ protected: ...@@ -803,12 +842,13 @@ protected:
100.0f); 100.0f);
LightControl.init(nodeLight, guiEnv, core::position2d<s32>(270,20), L"light" ); LightControl.init(nodeLight, guiEnv, core::position2d<s32>(270,20), L"light" );
GlobalAmbient.init( guiEnv, core::position2d<s32>(270, 300), L"global ambient" ); GlobalAmbient = new CColorControl( guiEnv, core::position2d<s32>(270, 300), L"global ambient", guiEnv->getRootGUIElement());
GlobalAmbient.setColor( smgr->getAmbientLight().toSColor() ); GlobalAmbient->setColor( smgr->getAmbientLight().toSColor() );
return true; return true;
} }
// Ask the user which driver to use
video::E_DRIVER_TYPE getDriverTypeFromConsole() video::E_DRIVER_TYPE getDriverTypeFromConsole()
{ {
printf("Please select the driver you want for this example:\n"\ printf("Please select the driver you want for this example:\n"\
...@@ -832,6 +872,7 @@ protected: ...@@ -832,6 +872,7 @@ protected:
} }
} }
// Update one frame
bool update() bool update()
{ {
using namespace irr; using namespace irr;
...@@ -857,10 +898,10 @@ protected: ...@@ -857,10 +898,10 @@ protected:
NodeRight.update(); NodeRight.update();
LightControl.update(); LightControl.update();
if ( GlobalAmbient.isDirty() ) if ( GlobalAmbient->isDirty() )
{ {
smgr->setAmbientLight( GlobalAmbient.getColor() ); smgr->setAmbientLight( GlobalAmbient->getColor() );
GlobalAmbient.setDirty(false); GlobalAmbient->resetDirty();
} }
video::SColor bkColor( skin->getColor(gui::EGDC_APP_WORKSPACE) ); video::SColor bkColor( skin->getColor(gui::EGDC_APP_WORKSPACE) );
...@@ -875,6 +916,7 @@ protected: ...@@ -875,6 +916,7 @@ protected:
return true; return true;
} }
// Run the application. Our main loop.
void run() void run()
{ {
IsRunning = true; IsRunning = true;
...@@ -892,9 +934,12 @@ protected: ...@@ -892,9 +934,12 @@ protected:
} }
} }
// Close down the application
void quit() void quit()
{ {
IsRunning = false; IsRunning = false;
GlobalAmbient->drop();
GlobalAmbient = NULL;
if ( Device ) if ( Device )
{ {
Device->closeDevice(); Device->closeDevice();
...@@ -967,6 +1012,7 @@ protected: ...@@ -967,6 +1012,7 @@ protected:
driver->addTexture (io::path("GRAYSCALE_A8R8G8B8"), imageA8R8G8B8); driver->addTexture (io::path("GRAYSCALE_A8R8G8B8"), imageA8R8G8B8);
} }
// Load a texture and make sure nodes know it when more textures are available.
void loadTexture(const io::path &name) void loadTexture(const io::path &name)
{ {
Device->getVideoDriver()->getTexture(name); Device->getVideoDriver()->getTexture(name);
...@@ -982,9 +1028,12 @@ private: ...@@ -982,9 +1028,12 @@ private:
SMeshNodeControl NodeLeft; SMeshNodeControl NodeLeft;
SMeshNodeControl NodeRight; SMeshNodeControl NodeRight;
SLightNodeControl LightControl; SLightNodeControl LightControl;
CColorControl GlobalAmbient; CColorControl * GlobalAmbient;
}; };
/*
A very short main as we do everything else in classes.
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
CApp APP; CApp APP;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment