Page 1 of 1

Block rotation

Posted: Tue May 25, 2010 5:23 pm
by Moore
I want to do a block rotation. I have model of triangle and i rotate it. But i don't get that i want. I want something like this:
Image
i get this:
Image

Why irrlicht rotate it that?

There is a code:

Code: Select all

#include <irrlicht.h>

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

int i=0;


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();
  	IGUIEnvironment* env = device->getGUIEnvironment();
   ISceneManager* smgr = device->getSceneManager();
   device ->getCursorControl()->setVisible(false);
  ICameraSceneNode *kam = smgr->addCameraSceneNodeFPS();  

 	kam->setFarValue(90000);
	kam->setPosition(core::vector3df(0,0,0));
	
env->addStaticText(L"Naciscnij ESC by wyjsc\nNaciscnij A by zmienic animacje\nNaciscnij S by rozpoczacz animacje\nNaciscnij D by zatrzymac animacje\nNaciscnij Z by wyzerowac animacje\n",
rect<s32>(700,510,840,580), true, true, 0);

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

pud = smgr->addAnimatedMeshSceneNode(pudlo);
pud -> setScale (core::vector3df(100,100,100));
pud -> setPosition(core::vector3df(0,0,0));
pud ->setMaterialFlag(video::EMF_LIGHTING, false); 
pud ->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); 
 
while(i<=180){
     i++;         
pud = smgr->addAnimatedMeshSceneNode(pudlo);
pud -> setScale (core::vector3df(100,100,100));
pud -> setPosition(core::vector3df(0,0,0));
pud -> setRotation(core::vector3df(0,i,0));
pud ->setMaterialFlag(video::EMF_LIGHTING, false); 
pud ->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); 
}


 


 int lastFPS = -1;  //dla fps

  while(device->run())

  {


                if(receiver.IsKeyDown(KEY_ESCAPE))break;
        

                
    video->beginScene(true, true, video::SColor(255,113,113,133));
   env->drawAll();
    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;
}

Posted: Tue May 25, 2010 5:57 pm
by Acki
with this loop you create 181 nodes, each rotated by 1° against the previous created one !!! :shock:

Code: Select all

while(i<=180){
     i++;         
pud = smgr->addAnimatedMeshSceneNode(pudlo);
pud -> setScale (core::vector3df(100,100,100));
pud -> setPosition(core::vector3df(0,0,0));
pud -> setRotation(core::vector3df(0,i,0));
pud ->setMaterialFlag(video::EMF_LIGHTING, false);
pud ->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
} 

Posted: Tue May 25, 2010 6:06 pm
by kazymjir
Cześć!

You doing many mistakes in your code!

Look at first loop ( while(i<=180) ),
you don't need to scale model 180 times, because you scalled it before.
Same is with setting position and material flags.

Now see at setRotation in same loop.
Model rotation is set, but it's not drawed. You are rotating 180 times model, but it's not drawed in loop, so when later in render you see 180 nodes, every rotated by 1 degree.
Move your code to main loop:

Code: Select all

    video->beginScene(true, true, video::SColor(255,113,113,133));
     i++;
    pud -> setRotation(core::vector3df(0,i,0));
   env->drawAll();
    smgr->drawAll();
    video->endScene();
Now you code will work propetly.
Node will be rotated, next drawed.

Posted: Tue May 25, 2010 6:34 pm
by Acki
aek wrote:180 times
to be pedantic: it's 181 !!! :twisted:

Posted: Tue May 25, 2010 6:57 pm
by kazymjir
Acki wrote:
aek wrote:180 times
to be pedantic: it's 181 !!! :twisted:
Ahhh, I missed that is <=, not < :D

Moore, and one tip: use timers in rotation, if you want to rotate node whole time
http://irrlicht.sourceforge.net/docu/example004.html

Posted: Wed May 26, 2010 2:49 pm
by Moore
Nie, nie o to mi chodziło :/

Aek give me your Gygy number i'll explain what i want :)

Posted: Wed May 26, 2010 2:52 pm
by kazymjir
ok, 13303849