I've come into a bit of a problem, I'm trying to make my game move a Motion Simulator, however I'm finding that I can't make my velocity rotate so that if my craft is going forward that it would equal vector3df(0,0,1) for example.
What I seem to be getting out is the raw direction value when it's used on the mini simulator I made. However when I rotate but don't change my velocity (so i'm still moving in the same direction) the motion simulator is rotating too. This leads me to believe that it is rotating the vector just not by what I would like.
I've tried this a few different ways but haven't found a winner, any thoughts?
Code: Select all
void Player_suit::MotionSim()
{
static char Outbytes[] = {0,0,0};
static float F=0,S=0,U=0; //Forward,Side,Up
vector3df dif = velocity.direction;
vector3df rot = rotation;
matrix4 m;
m.setRotationDegrees(rot.invert()); //Rotate the velocity so its relitive to the node rotation
//This should make the direction of acceleration face (0,0,1) if it was forward of the node.
m.rotateVect(dif);
if(dif.getLength()>5)
{
dif.setLength(5);
}
F = dif.Z;
U = dif.Y;
S = dif.X;
core::stringw tmp = L"Balance board";
tmp += " ( ";
tmp += F;
tmp += ", ";
tmp += S;
tmp += ", ";
tmp += U;
tmp += " )";
device->setWindowCaption(tmp.c_str());
if(motionSimEn && arduino->IsConnected())
{
Outbytes[0] = (char)((F)+100);
Outbytes[1] = (char)((S)+100);
Outbytes[2] = (char)((U)+100);
core::stringw tmp = L"Balance board";
tmp += " ( ";
tmp += Outbytes[0]-100;
tmp += ", ";
tmp += Outbytes[1]-100;
tmp += ", ";
tmp += Outbytes[2]-100;
tmp += " )";
device->setWindowCaption(tmp.c_str());
arduino->WriteData(Outbytes,3);
}
else if(!motionSimEn && arduino->IsConnected())
{
Outbytes[0] = (char)((0)+100);
Outbytes[1] = (char)((0)+100);
Outbytes[2] = (char)((0)+100);
arduino->WriteData(Outbytes,3);
}
}