Vector rotation! Center?

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
TyWuNon
Posts: 8
Joined: Sun Dec 10, 2006 11:51 am
Location: Germany
Contact:

Vector rotation! Center?

Post by TyWuNon »

Hello,
i have an question about the rotate"XYZ"By() methods in the vector3d<T> class.
I don't really get the function the center parameter.
I just asking to understand how this method works.

Excsuse my english i'm german. :lol:
Das Chaos hält Einzug!
Und ist Unaufhaltsam!
Image
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

well, the API says that the center indicates the center of the rotation.
i think for most rotations the center would be 0,0,0...but if you choose another center you will get another result...;)
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Vector in this case specify point in space. You need center around which you want your point to be rotated.
TyWuNon
Posts: 8
Joined: Sun Dec 10, 2006 11:51 am
Location: Germany
Contact:

Post by TyWuNon »

thanks for this really fast reply :)
Das Chaos hält Einzug!
Und ist Unaufhaltsam!
Image
TyWuNon
Posts: 8
Joined: Sun Dec 10, 2006 11:51 am
Location: Germany
Contact:

Post by TyWuNon »

hmm i've tried to rotate a vector but i don't reeally get why i get this weird solutions

Code: Select all

vector3df vec(1,0,0);
cout<<"X: "<<vec.X<<" Y: "<<vec.Y<<" Z: "<<vec.Z<<endl;
vec.rotateXZBy(90,vector3df(0,0,0));
cout<<"X: "<<vec.X<<" Y: "<<vec.Y<<" Z: "<<vec.Z<<endl;
the vecor before has the coordinates (1/0/0)
after rotating it i thought it would be something like (0/0/1)
but it was (6.12303e-017/0/1)
i don't get why
Das Chaos hält Einzug!
Und ist Unaufhaltsam!
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, 6.12303e-017 is pretty much 0, at least for my usuall approximations. If something of any importance fits into the space between your result and the correct result you should post it here :wink:
So, as a general rule of thumb, try to use the equal methods instead of exact == operator for float based objects.
TyWuNon
Posts: 8
Joined: Sun Dec 10, 2006 11:51 am
Location: Germany
Contact:

Post by TyWuNon »

my real problem is i want to rotate a vector and set the rotation and position of my camera with it so i read the old use the rotate methods and the i set the vector as rotation or position
so the problem is when i do it that way nothing happens
when i create a new vector with manipulated values it work but why should i calculate everytime new values when i just be able to rotate the vector but somehow it don't work

if you like i post my hole eventReceiver class i don't know whats wrong with it i think the 6.12303e-017 causes the problem but how and why i don't know
Das Chaos hält Einzug!
Und ist Unaufhaltsam!
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, as hybrid said 6.12303e-017 is pretty close to 0...
if you write this value out you'll have 0.0000000000000000612303 !!! ;)
this is probably caused by rounding errors of the CPU/MPU...
and it could cause problems when comparing the value (like hybrid also mentioned)...

maybe it's realy a good idea to post your event receiver... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
TyWuNon
Posts: 8
Joined: Sun Dec 10, 2006 11:51 am
Location: Germany
Contact:

Post by TyWuNon »

Here my EventReceiver:

Code: Select all

#ifndef EventReceiver
#define EventReceiver

#include <Irrlicht.h>

#include <iostream>

#include "resources.h"

using namespace irr;

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

using namespace std;

extern IrrlichtDevice* device;
extern ICameraSceneNode* camera;
extern int auflsungV;
extern int auflsungH;

float movmentSpeed = 1.0;
float strafeSpeed = 0.5;

class EvRecvr : public IEventReceiver{
   private:
      int mouseX;
      int mouseY;
   public:
      //Konstruktor-------------------------------
      EvRecvr(){
         mouseX = auflsungH/2;
         mouseY = auflsungV/2;
      }
      //------------------------------------------
      
      bool OnEvent(const SEvent& event){
         //Tastaur händler
         if(event.EventType == EET_KEY_INPUT_EVENT){
            //Händler für gedrückte Tasten
            if(event.KeyInput.PressedDown){
               //Allgemeine Events----------------
               cout<<"your're pressing a button: "<<event.KeyInput.Key<<endl;
               //---------------------------------
               
               //W-Taste--------------------------
               if (event.KeyInput.Key== KEY_KEY_W){
                  vector3df rotVec = camera->getRotation();
                  vector3df posVec = camera->getPosition();
                  rotVec.setLength(movmentSpeed);
                  rotVec.rotateXZBy(0, rotVec);
                  vector3df newVec(posVec.X+rotVec.X, posVec.Y, posVec.Z+rotVec.Z);
                  camera->setPosition(newVec);
               }
               //---------------------------------
               
               //A-Taste--------------------------
               if (event.KeyInput.Key== KEY_KEY_A){
                  vector3df rotVec = camera->getRotation();
                  vector3df posVec = camera->getPosition();
                  rotVec.setLength(strafeSpeed);
                  rotVec.rotateXZBy(270, rotVec);
                  vector3df newVec(posVec.X+rotVec.X, posVec.Y, posVec.Z+rotVec.Z);
                  camera->setPosition(newVec);
               }
               //---------------------------------
               
               //S-Taste--------------------------
               if (event.KeyInput.Key== KEY_KEY_S){
                  vector3df rotVec = camera->getRotation();
                  vector3df posVec = camera->getPosition();
                  rotVec.setLength(movmentSpeed);
                  rotVec.rotateXZBy(180, rotVec);
                  vector3df newVec(posVec.X+rotVec.X, posVec.Y, posVec.Z+rotVec.Z);
                  camera->setPosition(newVec);
               }
               //---------------------------------
               
               //D-Taste--------------------------
               if (event.KeyInput.Key== KEY_KEY_D){
                  vector3df rotVec = camera->getRotation();
                  vector3df posVec = camera->getPosition();
                  rotVec.setLength(strafeSpeed);
                  rotVec.rotateXZBy(90, rotVec);
                  vector3df newVec(posVec.X+rotVec.X, posVec.Y, posVec.Z+rotVec.Z);
                  camera->setPosition(newVec);
               }
               //---------------------------------
               
               if(event.KeyInput.Key == KEY_KEY_M){
                  vector3df vec(1,0,0);
                  cout<<"X: "<<vec.X<<" Y: "<<vec.Y<<" Z: "<<vec.Z<<endl;
                  vec.rotateXZBy(90,vector3df(0,0,0));
                  cout<<"X: "<<vec.X<<" Y: "<<vec.Y<<" Z: "<<vec.Z<<endl;
               }
            }
            //Händler für losgelassene Tasten
            else{
               //Allgemeine Events----------------
               cout<<"your're releasing a button: "<<event.KeyInput.Key<<endl;
               //---------------------------------
               
               //ESC-Taste------------------------
               if(event.KeyInput.Key == KEY_ESCAPE){
                  device->closeDevice();
               }
               //---------------------------------
            }
            return true;
         }
         //Maus händler
         else if(event.EventType == EET_MOUSE_INPUT_EVENT){
            //Allgemeine Events-------------------
            cout<<"your're moving the mouse: "<<"X: "<<event.MouseInput.X<<" Y: "<<event.MouseInput.Y<<endl;
            //------------------------------------
            
            //Maus XY-Achse-----------------------
            //------------------------------------
            return true;
         }
         else{
            return false;
         }
      }
};

#endif
Sorry but like i said i'm geman so the comments are in german^^
If you want to try it use the M button to rotate the vector its just a console output
Das Chaos hält Einzug!
Und ist Unaufhaltsam!
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you mean that your camera doesn't rotate its view, then it might be because you just rotate the node, but not the view (the target). Please check the ICameraSceneNode API for the proper usage of cameras.
TyWuNon
Posts: 8
Joined: Sun Dec 10, 2006 11:51 am
Location: Germany
Contact:

Post by TyWuNon »

okey i solved the problem -.-
stupid mistake by me my camera has the start rotation vector (0/0/0) so when i rotate it it will be also (0/0/0) so thats why the camera doesn't move or rotate
and i used as center the vector itself and so the point rotates around itself so no change -.-
Das Chaos hält Einzug!
Und ist Unaufhaltsam!
Image
Post Reply