#1 

12-03-2007 20:01:35

katsankat
Membres
Date d'inscription:
Messages: 43
IP: 82.122.67.77
Courriel

Salut,
Voici une petite fenêtre avec plein de paramètres pour modifier et tester des paramètres affectant l'atmosphère.
Ca peut permettre de comprendre comment ils interagisent entre eux.

Pour tester, créez un répertoire dans le dossier examples, et copiez-y

main.cpp dont le code ci-dessous (commentaires en anglais dsl),
le makefile
heightmap
texture

Ca donne ça (avec des ombres très marquées et, ... Sous linux):


// main.cpp
#include <irrlicht.h>
#include <iostream>

using namespace irr;
using namespace core;
using namespace gui;

 // Contains all environnment settings
 typedef struct {
	scene::ISceneNode* LIGHTENV;
	vector3df Pos;
	f32 Radius;

	video::SColorf Ambient;
	video::SColor  Diffuse;

	video::SColor Fog;
	f32 FogStart;
	f32 FogEnd;	// fog not activated if 0
        f32 FogStrength;
 } ENV;
   ENV *env;


  // Main window dimensions
  u32 WIDTH = 600;
  u32 HEIGHT = 500;

  IrrlichtDevice *device;
  scene::ITerrainSceneNode* terrain;




/*------------------------------------------------------------------------------
  Apply Env settings.
  1) Obtain values from GUI controls, store them in the structure
  2) Apply these values onto irrlicht objects.
------------------------------------------------------------------------------*/
void apply_env_settings()
{
  f32 r,g,b;
  u32 ur,ug,ub;
  stringc s;

  IGUIEnvironment* guienv = device->getGUIEnvironment();
  IGUIElement* root = guienv->getRootGUIElement();

  // Pos.X
       s = root->getElementFromId(111, true)->getText();
       env->Pos.X = (f32)atof(s.c_str());
  // Pos.Y
       s = root->getElementFromId(121, true)->getText();
       env->Pos.Y = (f32)atof(s.c_str());
  // Pos.Z
       s = root->getElementFromId(131, true)->getText();
       env->Pos.Z = (f32)atof(s.c_str());

  // Radius
       s = root->getElementFromId(141, true)->getText();
       env->Radius = (f32)atof(s.c_str());

  // Ambient.R
       s = root->getElementFromId(162, true)->getText();
       r = (f32)atof(s.c_str());
  // Ambient.G
       s = root->getElementFromId(163, true)->getText();
       g = (f32)atof(s.c_str());
  // Ambient.B
       s = root->getElementFromId(164, true)->getText();
       b = (f32)atof(s.c_str());
       env->Ambient = video::SColorf(10, r,g,b);

  // Diffuse.R
       s = root->getElementFromId(172, true)->getText();
       ur = (u32)atoi(s.c_str());
  // Diffuse.G
       s = root->getElementFromId(173, true)->getText();
       ug = (u32)atoi(s.c_str());
  // Diffuse.B
       s = root->getElementFromId(174, true)->getText();
       ub = (u32)atoi(s.c_str());
       env->Diffuse = video::SColor(0, ur,ug,ub);

  // Fog Start
       s = root->getElementFromId(211, true)->getText();
       env->FogStart = (f32)atof(s.c_str());
  // Fog End
       s = root->getElementFromId(216, true)->getText();
       env->FogEnd = (f32)atof(s.c_str());

  // Fog.R
       s = root->getElementFromId(222, true)->getText();
       ur = (u32)atoi(s.c_str());
  // Fog.G
       s = root->getElementFromId(232, true)->getText();
       ug = (u32)atoi(s.c_str());
  // Fog.B
       s = root->getElementFromId(242, true)->getText();
       ub = (u32)atoi(s.c_str());
       env->Fog = video::SColor(1, ur,ug,ub);

  // Fog Strength
       s = root->getElementFromId(219, true)->getText();
       env->FogStrength = (f32)atof(s.c_str());


  // now apply values
     scene::ISceneManager* smgr = device->getSceneManager();

     // Light environment
     if (env->LIGHTENV) env->LIGHTENV->remove();
     env->LIGHTENV = smgr->addLightSceneNode(0,
					env->Pos,
					env->Ambient,
					env->Radius); 
     // terrain
     video::SMaterial *mat= &terrain->getMaterial(0);
                     mat->FogEnable=(env->FogEnd > 0);
                     mat->Lighting=true;
                     mat->EmissiveColor= env->Diffuse;

     // fog
     video::IVideoDriver* driver = device->getVideoDriver();
     driver->setFog(env->Fog, true, env->FogStart, env->FogEnd,
                  env->FogStrength, false, true);
}

/*------------------------------------------------------------------------------
  Handle Events
------------------------------------------------------------------------------*/
class MyEventReceiver : public IEventReceiver
{
 public:
  virtual bool OnEvent(SEvent event)
  {

    if (event.EventType == EET_GUI_EVENT)
    {
      if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
      {
         apply_env_settings();
         return true;
      }
    }
    return false;
  }
};

/*------------------------------------------------------------------------------
  Create Tool Window. Takes screen size as parameter.
  Here are set hard-coded default values for env settings.
------------------------------------------------------------------------------*/
void createToolsWindow(IrrlichtDevice *device, u32 HEIGHT, u32 WIDTH)
{
  IGUIEnvironment* guienv = device->getGUIEnvironment();

  // create window
  IGUIWindow* wnd = guienv->addWindow(rect<s32>(100,HEIGHT-200, 400,HEIGHT-10),
                                   false, L"Env Settings", 0, 5000);

  // add tab control
  IGUITabControl* tabs = guienv->addTabControl( rect<s32>(2,20,297,186),
						wnd, true, true);

  IGUIElement* root = guienv->getRootGUIElement();

  /* Tab1: LIGHT
	+---------------+ --------------
	|      Light	|	Fog	|
	---------------------------------------------------------
	|	X: 95584.222	Y: 6523.2	Z: 232.2	|
	|	Radius: 2000					|
	|			R	G	B		|
	|	Ambient:	200	210	10		|
	|	Diffuse		10	10	230	APPLY	|
	|							|
	--------------------------------------------------------- */

  IGUITab* t1 = tabs->addTab(L"Light");

    // X: 0000.000
    guienv->addStaticText (L"X:",rect<s32>(10,10,30,30),false,true,t1,110,false);
    guienv->addEditBox    (L"0000.0",rect<s32>(30,10,90,30),true,t1,111);

    // Y: 0000.000
    guienv->addStaticText (L"Y:",rect<s32>(100,10,130,30),false,true,t1,120,false);
    guienv->addEditBox    (L"1000.0",rect<s32>(130,10,190,30),true,t1,121);

    // Z: 0000.000
    guienv->addStaticText (L"Z:",rect<s32>(200,10,230,30),false,true,t1,130,false);
    guienv->addEditBox    (L"0000.0",rect<s32>(220,10,280,30),true,t1,131);

    // Radius: 0000.000
    guienv->addStaticText (L"Radius",rect<s32>(10,40,70,60),false,true,t1,140,false);
    guienv->addEditBox    (L"1000",  rect<s32>(70,40,140,60),true,t1,141);

    //		R,G,B
    guienv->addStaticText (L"R",rect<s32>(70 ,70,100,86),true,true,t1,151,false);
    guienv->addStaticText (L"G",rect<s32>(100,70,130,86),true,true,t1,152,false);
    guienv->addStaticText (L"B",rect<s32>(130,70,160,86),true,true,t1,153,false);

    //Ambient
    guienv->addStaticText (L"Ambient",rect<s32>(10,86,70,102),true,true,t1,161,false);
    guienv->addEditBox    (L"255",rect<s32>(70 ,86,100,102),true,t1,162);
    guienv->addEditBox    (L"10" ,rect<s32>(100,86,130,102),true,t1,163);
    guienv->addEditBox    (L"1"  ,rect<s32>(130,86,160,102),true,t1,164);

    //Diffuse
    guienv->addStaticText (L"Diffuse",rect<s32>(10,102,70,118),true,true,t1,171,false);
    guienv->addEditBox    (L"100",rect<s32>(70 ,102,100,118),true,t1,172);
    guienv->addEditBox    (L"200",rect<s32>(100,102,130,118),true,t1,173);
    guienv->addEditBox    (L"100",rect<s32>(130,102,160,118),true,t1,174);

    //Apply Button
    guienv->addButton(rect<s32>(190,80,280,118),t1,1101,L"Apply");

  /* Tab2: FOG
	 -------------- +---------------+
	|      Light	|	Fog	|
	---------------------------------------------------------
	|	Start: 		1000	End: 6000		|
	|	Strength:	2000				|
	|							|
	|		R	G	B			|
	|		10	211	255			|
	|							|
	---------------------------------------------------------	*/
  IGUITab* t2 = tabs->addTab(L"Fog");

    // Fog Start
    guienv->addStaticText (L"Start:",rect<s32>(10,10,70,30),false,true,t2,210,false);
    guienv->addEditBox    (L"1000",rect<s32>(70,10,140,30),true,t2,211);

    // Fog End
    guienv->addStaticText (L"End:",rect<s32>(150,10,210,60),false,true,t2,215,false);
    guienv->addEditBox    (L"3000",rect<s32>(200,10,270,30),true,t2,216);

    // Fog Strength
    guienv->addStaticText (L"Strength:",rect<s32>(10,40,70,60),false,true,t2,218,false);
    guienv->addEditBox    (L"0.001",rect<s32>(70,40,140,60),true,t2,219);

    // Fog R
    guienv->addStaticText (L"R",rect<s32>(70,70,140,90),true,true,t2,221,false);
    guienv->addEditBox    (L"255",rect<s32>(70,90,140,110),true,t2,222);
    // Fog G
    guienv->addStaticText (L"G",rect<s32>(140,70,200,90),true,true,t2,231,false);
    guienv->addEditBox    (L"222",rect<s32>(140,90,200,110),true,t2,232);
    // Fog B
    guienv->addStaticText (L"B",rect<s32>(200,70,270,90),true,true,t2,241,false);
    guienv->addEditBox    (L"166",rect<s32>(200,90,270,110),true,t2,242);
}

/*------------------------------------------------------------------------------
  Create env window with tabs
------------------------------------------------------------------------------*/
void create_env_window()
{
  video::IVideoDriver*  driver = device->getVideoDriver();

  // create window for Env settings
  createToolsWindow (device, HEIGHT, WIDTH);

  // set a nicer font
  IGUIEnvironment* guienv = device->getGUIEnvironment();
  IGUISkin* skin = guienv->getSkin();
  IGUIFont* font = guienv->getFont("../../media/fonthaettenschweiler.bmp");
  if (font) skin->setFont(font);
}


/*------------------------------------------------------------------------------
  Load Terrain
------------------------------------------------------------------------------*/
video::ITexture* load_scene()
{
  // [Load heightmap]
     video::IVideoDriver* driver = device->getVideoDriver();
     scene::ISceneManager* smgr  = device->getSceneManager();

     terrain = smgr->addTerrainSceneNode("0003.png");
     terrain->setScale(vector3df(256, 12, 256));
     terrain->setMaterialTexture(0, driver->getTexture("texture.png"));
     terrain->scaleTexture(64, 64);

  // [Skybox]
     smgr->addSkyBoxSceneNode(
		driver->getTexture("../../media/irrlicht2_up.jpg"),
		driver->getTexture("../../media/irrlicht2_dn.jpg"),
		driver->getTexture("../../media/irrlicht2_lf.jpg"),
		driver->getTexture("../../media/irrlicht2_rt.jpg"),
		driver->getTexture("../../media/irrlicht2_ft.jpg"),
		driver->getTexture("../../media/irrlicht2_bk.jpg"));

  // [Cam]
     scene::ICameraSceneNode* camera;
               camera = smgr->addCameraSceneNodeMaya();
               camera->setPosition(vector3df(1000,1500,1000));
               camera->setTarget  (vector3df(2000,1000,2000));

  // [Irrlicht logo]
     video::ITexture* irrLogo =
                      driver->getTexture("../../media/irrlichtlogoaligned.jpg");

  return irrLogo;
}


/*------------------------------------------------------------------------------
  Entry point
------------------------------------------------------------------------------*/
int main()
{
  // create irrlicht device
     MyEventReceiver receiver;
     device = createDevice(video::EDT_OPENGL,
                           dimension2d<s32>(WIDTH, HEIGHT),
                           16, false, false, false, &receiver);
     if (!device) return 1;

     video::IVideoDriver*  driver = device->getVideoDriver();
     scene::ISceneManager* smgr   = device->getSceneManager();
     IGUIEnvironment*      guienv = device->getGUIEnvironment();

     device->setResizeAble(true);
     driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

  // Init stuff
  device->setWindowCaption(L"Irrlicht Engine - Loading...");

    // Create GUI tool window, tabs and controls, fill controls with
    // hard-coded default values for env settings
       create_env_window();

    // Load terrain
       video::ITexture* irrLogo = load_scene();
                   if (!irrLogo) return 1;

    // now that terrain is created, get env values from controls to pass them
    // into the structure, to apply them
       env = new ENV;
       apply_env_settings();

  device->setWindowCaption(L"ENV settings");


  // Main loop
  while(device->run())
  {
    if (device->isWindowActive())
    {
      driver->beginScene(true, true,0);
      smgr->drawAll();
      guienv->drawAll();
      driver->draw2DImage(irrLogo, position2d<s32>(10, 10),rect<s32>(0,0,88,31));
      driver->endScene();
    }
  }

  device->drop();
  delete env;
  return 0;
}


Hors ligne


#2 

13-03-2007 18:05:05

Jerry Kan
Membres
Date d'inscription:
Messages: 265
IP: 82.243.77.149
Courriel

merci, j'y jetterrai un oueil interressé dans quelques temps smile


Hors ligne


#3 

14-03-2007 03:31:02

maitrelame12545
Membres
Avatar de maitrelame12545
Date d'inscription:
Messages: 51
IP: 76.80.53.159
Courriel

Chez moi je compile. Je lance ca charge la skybox et dessuite apres ca quitte. Ca n'affiche meme pas l'interrieur de la fenetre. Je vois juste les bordure puis ca quitte....


Codeur elewendyl

Hors ligne


#4 

14-03-2007 19:29:17

katsankat
Membres
Date d'inscription:
Messages: 43
IP: 82.122.78.162
Courriel

Quel est le dernier message de la console, "can't find heightmap" ?


Hors ligne


#5 

18-03-2007 06:54:43

maitrelame12545
Membres
Avatar de maitrelame12545
Date d'inscription:
Messages: 51
IP: 76.80.53.159
Courriel

je ne sais pas ca va trop vite...


Codeur elewendyl

Hors ligne


#6 

18-03-2007 09:05:42

Jerry Kan
Membres
Date d'inscription:
Messages: 265
IP: 82.243.77.149
Courriel

lance ton prog a la main, :

demarrer / executer / "cmd" /
navigue avec cd .. et cd Nom_dossier jusqu'au répertoire de ton exe, et de la lance le avec "nom_prog.exe"

la console persitera, puisqu'elle n'aura pas été lancée spécifiquement pour une execution

(n'empeche que linux c'est mieux tongue)


Hors ligne


#7 

19-03-2007 00:03:18

kedu
Modérateurs
Avatar de kedu
Date d'inscription:
Messages: 155
IP: 89.86.125.126
Courriel

C'est une propriété de compilation ça, je pense ;-) (mode appli console)


Hors ligne


#8 

04-04-2007 17:49:39

katsankat
Membres
Date d'inscription:
Messages: 43
IP: 82.122.82.143
Courriel

Bon effectivement je viens de tester avec Irrlicht 1.3 ça produit une erreur de segmentation.
Faut dire que j'ai posté ce code moins d'une semaine avant la sortie de la 1.3.
Il va falloir se plonger dans le changelog je pressent que le bug provient du GUI qui a été amplement modifié entre la 1.2 et la 1.3.


Hors ligne


Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
190 invités en ligne
membre en ligne: -
RSS Feed