Page 1 of 1

Strange error

Posted: Fri May 28, 2010 7:00 pm
by Moore

Code: Select all

#include <irrlicht.h>


using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

f32 i=0;
int model=1;
bool start=false;
bool zeruj=false;

class MyEventReceiver : public IEventReceiver
{
public:

        virtual bool OnEvent(const SEvent& event)
        {

                if (event.EventType == irr::EET_KEY_INPUT_EVENT)
                        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

                return false;
        }

 
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                return KeyIsDown[keyCode];
        }
        
        MyEventReceiver()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }

private:
  
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};





   
int main()                    
{    


  IrrlichtDevice* device = createDevice( EDT_OPENGL, dimension2d<u32>(840, 580),
  32, false, true, false, 0);
  
 MyEventReceiver receiver;
 device->setEventReceiver(&receiver);
  IVideoDriver* video = device->getVideoDriver();

   ISceneManager* smgr = device->getSceneManager();
   device ->getCursorControl()->setVisible(false);
  ICameraSceneNode *kam = smgr->addCameraSceneNodeFPS();  

 	kam->setFarValue(90000);
	kam->setPosition(core::vector3df(0,120,-300));
	


IAnimatedMeshSceneNode* tri = 0;
IAnimatedMesh* triangle = smgr->getMesh("triangle.b3d");


 


 int lastFPS = -1;  //dla fps

  while(device->run())

  {
              
                if(receiver.IsKeyDown(KEY_ESCAPE))break;
                if(receiver.IsKeyDown(KEY_NUMPAD1)||receiver.IsKeyDown(KEY_KEY_1)){
  
   tri=smgr->addAnimatedMeshSceneNode(triangle);
   tri->setScale (core::vector3df(100,100,100));
   tri->setPosition (core::vector3df(0,0,0));
   tri->setRotation(core::vector3df(0,0,0)); 
   tri->setMaterialFlag(video::EMF_LIGHTING, false);  
   tri->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);      
   }
                if(receiver.IsKeyDown(KEY_NUMPAD2)||receiver.IsKeyDown(KEY_KEY_2))smgr->clear();
                



                
    video->beginScene(true, true, video::SColor(255,113,113,133));


    smgr->drawAll();
    video->endScene();
    

   	
			
    
int fps = video->getFPS();          //oblicznie i wyƛwietlanie fps
if (lastFPS != fps)
{
core::stringw tmp(L"Animacje ");
tmp += L"fps: ";
tmp += fps;

device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
    
    
  }
  device->drop();
  return 0;
}

If i press 1 all's ok. Then i press 2 and screen is clear. Then i again press 1 and something strange happend. My triangle is very big and i can't move camera.

B3d model you can download here(if you want compile code):http://www.wrzucaj.com/169859

Re: Strange error

Posted: Fri May 28, 2010 7:21 pm
by Acki
Moore wrote:B3d model you can download here(if you want compile code):http://www.wrzucaj.com/169859
sorry, it's the .blend file, unfortunately I don't use Blender so I cant export it and so can't use it... :lol:

well, I tested it with the Ninja.b3d from the sdk...
and I had to make some changes:

Code: Select all

virtual bool IsKeyDown(EKEY_CODE keyCode){
  bool rrrr = KeyIsDown[keyCode];
  KeyIsDown[keyCode] = false;
  return rrrr;
}
.
.
.
if(receiver.IsKeyDown(KEY_NUMPAD1) || receiver.IsKeyDown(KEY_KEY_1)){
  if(!tri){
    tri=smgr->addAnimatedMeshSceneNode(triangle);
    tri->setScale (core::vector3df(100,100,100));
    tri->setPosition (core::vector3df(0,0,0));
    tri->setRotation(core::vector3df(0,0,0));
    tri->setMaterialFlag(video::EMF_LIGHTING, false);
    tri->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
  }
}
if(receiver.IsKeyDown(KEY_NUMPAD2) || receiver.IsKeyDown(KEY_KEY_2)){
  if(tri){
    tri->remove();
    tri = 0;
  }
}
I hope you see the changes... :lol:
at least with the Ninja model it works as expected... ;)

Posted: Sun May 30, 2010 8:49 am
by Moore
Yea, now is ok. But if i will do some copies (like in code on this site)i can delete only last one. So how i can delete ALL(now i have this)
Btw. Why:

Code: Select all

virtual bool IsKeyDown(EKEY_CODE keyCode){ 
  bool rrrr = KeyIsDown[keyCode]; 
  KeyIsDown[keyCode] = false; 
  return rrrr; 
} 
no:(that is in tutorial)

Code: Select all

virtual bool IsKeyDown(EKEY_CODE keyCode) const 
        { 
                return KeyIsDown[keyCode]; 
        }
 

Posted: Sun May 30, 2010 1:27 pm
by Acki
well, you can use the smgr->clear() function, too...
but remember this will remove all objects from the scene, also the camera, so you'll need to create a new camera then !!! ;)
better would ve to hold all nodes in an array or list and then walk through it for deleting the nodes...
or give each node an ID, then you can delete all nodes that have a certain ID... ;)

hmm, in this case the IsKeyDown function should also work in the old style...
I changed it because the original function was intended for use with movements and not for single key strokes...
so the old function will return true as long as the key is pressed and that's not what you want in this case... ;)

Posted: Sun May 30, 2010 1:41 pm
by ACE247
I just want to say that youre name 'Moore' and the topic 'Strange Error' coincide i a odd way. (Moore's Law) get it. :D

Posted: Sun May 30, 2010 4:34 pm
by Moore
I don't want to make new topic so:

I want to add some light in my app. There is a code. My question is: why triangle is light from all sides? I changed position of light, but nothing happen.

Posted: Sun May 30, 2010 7:50 pm
by ACE247
ACE247 wrote:I just want to say that youre name 'Moore' and the topic 'Strange Error' coincide i a odd way. (Moore's Law) get it. :D
Oops.. just pwned myself there i was thinking of Moore's law as Murphy's law. :roll:

Posted: Sun May 30, 2010 9:38 pm
by Acki
Moore wrote:why triangle is light from all sides?
maybe because you have ambiente light !?!?! :roll:

Posted: Mon May 31, 2010 1:14 pm
by Moore
So what i have to do to get light from one side?

Posted: Mon May 31, 2010 5:45 pm
by Acki
what do you think you can do !?!?! :roll:

Posted: Mon May 31, 2010 7:04 pm
by Virion
Moore wrote:So what i have to do to get light from one side?
use non-ambient lights :lol:
seriously, point light, directional light, spot light would do.

Posted: Tue Jun 01, 2010 4:15 pm
by Moore
I have this:

Code: Select all

 ILightSceneNode* light = smgr->addLightSceneNode(0);
    SLight sw;
    sw.CastShadows = true;
    sw.Position = vector3df(0, 0, 50);
    sw.Direction = vector3df(0, 0, -10);   
    sw.Radius = 700;
    sw.Type = ELT_DIRECTIONAL;
    light->setLightData(sw);
But it doesn't work :/

Posted: Tue Jun 01, 2010 6:11 pm
by greenya
Moore wrote:I have this:

Code: Select all

 ILightSceneNode* light = smgr->addLightSceneNode(0);
    SLight sw;
    sw.CastShadows = true;
    sw.Position = vector3df(0, 0, 50);
    sw.Direction = vector3df(0, 0, -10);   
    sw.Radius = 700;
    sw.Type = ELT_DIRECTIONAL;
    light->setLightData(sw);
But it doesn't work :/
If you add light to scene and want it to affect objects, this objects must have materials with lighting enabled; like: node->setMaterialFlag(EMF_LIGHTING, true);

Posted: Tue Jun 01, 2010 6:21 pm
by Lonesome Ducky
Let us not forget the tutorials, a fair amount of your questions are answered by them

Posted: Wed Jun 02, 2010 2:45 pm
by Moore
If you add light to scene and want it to affect objects, this objects must have materials with lighting enabled; like: node->setMaterialFlag(EMF_LIGHTING, true);
I know, i set it true.