Code: Select all
void HandleUserInput() {
if (device->isWindowActive()) {
if (KeybInput.isKeyPressed(KEY_KEY_W)) {
ppos += dis*pmovspeed*dt;
ppos.normalize();
ppos*=R;
axis=dis.crossProduct(ppos);
dis=ArbitraryRotate(dis, -0.5*pmovspeed*dt, axis);
playernode->setPosition(ppos);
cpos = (ppos - dis*10)*2;
cam->setPosition(cpos);
cam->setTarget(ppos);
cam->setUpVector(cpos);
ReturnPolarCoordinates();
printf("chi=%f phi=%f thi=%f Dis.Z=%f\n",chi, phi, thi, dis.Z);
cis=bis;
cis.rotateYZBy(thi, cen);
cis.rotateXZBy(phi, cen);
dot=cis.dotProduct(dis)/0.7615634f;
if (dot>0.9999) dot=1;
if (dot<-0.9999) dot=-1;
ang=acos(dot) / con;
ang*=sign;
chi=ang;
pnode->setRotation(core::vector3df(0,180+ang,0));
T1=pnode->getRelativeTransformation();
prot=T1.getRotationDegrees();
printf("W:T1: protX=%f, protY=%f, protZ=%f chi=%f\n",prot.X, prot.Y, prot.Z, chi);
pnode->setRotation(core::vector3df(thi,-phi,0));
T2=pnode->getRelativeTransformation();
prot=T2.getRotationDegrees();
printf("W:T2: protX=%f, protY=%f, protZ=%f chi=%f\n\n",prot.X, prot.Y, prot.Z, chi);
T3.setbyproduct(T2,T1);
prot=T3.getRotationDegrees();
playernode->setRotation(prot);
}
Code: Select all
if (KeybInput.isKeyPressed(KEY_KEY_D)) {
chi += protspeed * dt;
dis=ArbitraryRotate(dis, protspeed * dt, ppos);
cpos = (ppos - dis*10)*2;
cam->setPosition(cpos);
cam->setTarget(ppos);
cam->setUpVector(cpos);
ReturnPolarCoordinates();
printf("chi=%f phi=%f thi=%f Dis.Z=%f\n",chi, phi, thi, dis.Z);
if ( (fmod(chi,360) <= 0) && ( (fmod(chi,360)) >= -180) ) sign=-1;
if ( (fmod(chi,360) <= -180) && ( (fmod(chi,360)) >= -360) ) sign=1;
if ( (fmod(chi,360) >= 0) && ( (fmod(chi,360)) <= 180) ) sign=1;
if ( (fmod(chi,360) >= 180) && ( (fmod(chi,360)) <= 360) ) sign=-1;
pnode->setRotation(core::vector3df(0,180+chi,0));
T1=pnode->getRelativeTransformation();
prot=T1.getRotationDegrees();
printf("D:T1: protX=%f, protY=%f, protZ=%f chi=%f\n",prot.X, prot.Y, prot.Z, chi);
pnode->setRotation(core::vector3df(thi,-phi,0));
T2=pnode->getRelativeTransformation();
prot=T2.getRotationDegrees();
printf("D:T2: protX=%f, protY=%f, protZ=%f chi=%f\n\n",prot.X, prot.Y, prot.Z, chi);
T3.setbyproduct(T2,T1);
prot=T3.getRotationDegrees();
playernode->setRotation(prot);
}
so the issue is : because the keys can be used simultaneously, a variable changing in the the "D" key loop, can be used in the "W" key loop without everything having finished in the "D" loop.