
what i want to do is: stick camera behind a node, a little bit above and behind it . like vector3df(0,20,-50).
the node is 'space ship' freely flying in space.
i've managed to make camera follow my node(behind it), but it transfroms upside down when node rotates every 90 degrees vertically.
i don't know how to translate matrix relatively to node

i've tried to follow CuteAlien's advices on IRC but i failed miserably doing this using matrices.
also i tried parenting, bindTargetAndRotation, but i couldn't achieve desired effect...
here's code for rotating the 'ship'(lame way):
(in short - the further cursor is from center of screen, the faster 'ship' rotates in that direction)
Code: Select all
void Ship::updateRot() {
vector3df rotation(0,0,0);
vector3df shrotation(0,0,0);
f32 xrot=0;
f32 yrot=0;
if (my > halfy)
xrot=(((my-halfy)*1.00/halfy)*2);
else if (my < halfy)
xrot=-(((halfy-my)*1.00/halfy)*2);
else if (my == halfy) xrot=0;
if (mx > halfx)
yrot=(((mx-halfx)*1.00/halfx)*2);
else if (mx < halfx)
yrot=-(((halfx-mx)*1.00/halfx)*2);
else if (mx == halfx) xrot=0;
rotation.X=xrot;
rotation.Y=yrot;
shrotation=shipnode->getRotation();
std::cout << shrotation.X << " " << shrotation.Y << " " << shrotation.Z << std::endl;
shipnode->setRotation(shrotation+rotation);
}

and main loop(cut and edited with only related functions left):
Code: Select all
while (device->run()) {
if (device->isWindowActive()) {
driver->beginScene(1,1,SColor(255,155,5,5));
playership.updateRot();
playership.updatePos(); //move ship constant value forward
srot=playership.shipnode->getRotation().rotationToDirection().normalize();
cam->setPosition(playership.shipnode->getPosition()-20*srot);
cam->setRotation(playership.shipnode->getRotation());
smgr->drawAll();
driver->endScene();
}
