Strange error

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Moore
Posts: 31
Joined: Sat Mar 06, 2010 6:23 pm
Location: Poland

Strange error

Post 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
What?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Strange error

Post 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... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Moore
Posts: 31
Joined: Sat Mar 06, 2010 6:23 pm
Location: Poland

Post 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]; 
        }
 
What?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Post 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
Moore
Posts: 31
Joined: Sat Mar 06, 2010 6:23 pm
Location: Poland

Post 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.
What?
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Post 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:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Moore wrote:why triangle is light from all sides?
maybe because you have ambiente light !?!?! :roll:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Moore
Posts: 31
Joined: Sat Mar 06, 2010 6:23 pm
Location: Poland

Post by Moore »

So what i have to do to get light from one side?
What?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

what do you think you can do !?!?! :roll:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post 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.
Moore
Posts: 31
Joined: Sat Mar 06, 2010 6:23 pm
Location: Poland

Post 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 :/
What?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post 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);
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Let us not forget the tutorials, a fair amount of your questions are answered by them
Moore
Posts: 31
Joined: Sat Mar 06, 2010 6:23 pm
Location: Poland

Post 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.
What?
Post Reply