Block rotation

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

Block rotation

Post 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;
}
Last edited by Moore on Wed May 26, 2010 3:15 pm, edited 1 time in total.
What?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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);
} 
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
kazymjir
Posts: 727
Joined: Sat Feb 20, 2010 4:05 pm
Location: Munich, Bayern

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

Post by Acki »

aek wrote:180 times
to be pedantic: it's 181 !!! :twisted:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
kazymjir
Posts: 727
Joined: Sat Feb 20, 2010 4:05 pm
Location: Munich, Bayern

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

Post by Moore »

Nie, nie o to mi chodziło :/

Aek give me your Gygy number i'll explain what i want :)
What?
kazymjir
Posts: 727
Joined: Sat Feb 20, 2010 4:05 pm
Location: Munich, Bayern

Post by kazymjir »

ok, 13303849
Post Reply