Angle Client::calcPlayerObjAngle(Angle preAngle, StateCmds stateCmds) { bool left = stateCmds.getCurrentState(Cmds::ROTATE_LEFT); bool right = stateCmds.getCurrentState(Cmds::ROTATE_RIGHT); float rotateAmount(PlayerObj::getRotateSpeed()); Angle deltaAngle((left ? rotateAmount : 0.0f) + (right ? -rotateAmount : 0.0f)); return preAngle + deltaAngle; }
int MRISangleErrors(MRI_SURFACE *mris) { int fno, max_f = -1, ano ; FACE *face ; FILE *fp ; float ferror, max_ferror, total_error, total_sq_error, error, mean_error, std_error, pct_error, n ; fp = fopen("angle.err", "w") ; MRISupdateEllipsoidSurface(mris) ; total_error = total_sq_error = max_ferror = 0.0f ; for (fno = 0 ; fno < mris->nfaces ; fno++) { face = &mris->faces[fno] ; ferror = 0.0f ; for (ano = 0 ; ano < ANGLES_PER_TRIANGLE ; ano++) { error = deltaAngle(face->angle[ano], face->orig_angle[ano]); pct_error = error / face->orig_angle[ano] * 100.0f ; fprintf(fp, "%d %2.3f %2.3f %2.3f %2.1f\n", fno, (float)DEGREES(face->orig_angle[ano]), (float)DEGREES(face->angle[ano]), (float)DEGREES(error), (float)pct_error) ; total_sq_error += (error * error) ; ferror += fabs(error) ; total_error += error ; } if (ferror >= max_ferror) { max_ferror = ferror ; max_f = fno ; } } n = (float)(2*mris->nfaces) ; mean_error = total_error / n ; std_error = sqrt(total_sq_error / (float)n - mean_error*mean_error) ; fprintf(stderr, "max angle error occurs at %d, error = %2.3f\n", max_f, (float)DEGREES(max_ferror)); fprintf(stderr, "mean angle error = %2.3f, std = %2.3f\n", (float)DEGREES(mean_error), (float)DEGREES(std_error)); fclose(fp) ; return(NO_ERROR) ; }
/** * user intersects: follow * by moving the guide first */ bool Guide::whenIntersect(WObject *pcur, WObject *pold) { static bool first = true; if (perpetual) return true; if (pcur->type != USER_TYPE) { pold->copyPositionAndBB(pcur); return true; } // user only inside = true; if (restored) { restored = false; first = true; } if (first) { // save initial position of the user uinitial[0] = pold->pos.x; uinitial[1] = pold->pos.y; uinitial[2] = pold->pos.z; uinitial[3] = pold->pos.az; localuser->pos.x = pos.x; localuser->pos.y = pos.y; localuser->pos.z += (pos.z + pos.bbsize.v[2]); // jump on the skate localuser->pos.az = pos.az; if (path[pt][4]) { // pause signal(SIGALRM, sigguide); alarm((uint32_t) path[pt][4]); pause = true; } first = false; } if (path[pt][3]) { /* user follows the guide */ float dx, dy, dz; motion(&dx, &dy, &dz); localuser->updatePositionAndGrid(localuser->pos); localuser->pos.x += dx; localuser->pos.y += dy; localuser->pos.z += dz + .05; // + 1cm //error("follow: %.2f %.2f %.2f, %.3f %.3f %.3f", localuser->pos.x,localuser->pos.y,localuser->pos.z,dx,dy,dz); if (localuser->pos.x == pold->pos.x && localuser->pos.y == pold->pos.y) pold->copyPositionAndBB(localuser); else localuser->pos.z += DELTAZ; updatePositionAndGrid(pold->pos); //HACK! I don't know why! localuser->updatePositionAndGrid(localuser->pos); if ((floor(pos.x) == path[pt+1][0]) && (floor(pos.y) == path[pt+1][1])) { // new segment pt++; // next point if (path[pt][3] == 0) goto endtour; // null speed if (path[pt][4]) { // pause signal(SIGALRM, sigguide); alarm((uint32_t) path[pt][4]); // set delay pause = true; float azn = atan((path[pt+1][1] - path[pt][1]) / (path[pt+1][0] - path[pt][0])); if ((path[pt+1][0] - path[pt][0]) < 0) azn += M_PI; float azo = atan((path[pt][1] - path[pt-1][1]) / (path[pt][0] - path[pt-1][0])); if ((path[pt][0] - path[pt-1][0]) < 0) azo += M_PI; float da = deltaAngle(azn, 0); move.aspeed.v[0] = da / path[pt][4]; } else { signal(SIGALRM, SIG_IGN); motion(&dx, &dy, &dz); localuser->updatePositionAndGrid(localuser->pos); localuser->pos.x += dx; localuser->pos.y += dy; localuser->pos.z += dz; localuser->updatePosition(); } // new orientation float az = atan((path[pt+1][1] - path[pt][1]) / (path[pt+1][0] - path[pt][0])); if ((path[pt+1][0] - path[pt][0]) < 0) az += M_PI; pos.az = az; localuser->pos.az = pos.az; // user takes same orientation than guide } // update user localuser->updatePositionAndGrid(localuser->pos); } else { endtour: first = true; restore((User *)localuser); } return true; }
void rePlayer::messageProcess( reMessageDispatcher* sender, reMessage* message ) { reVec3 deltaAngle(0,0,0); float rs = .5f; switch (message->id) { case reM_TIMER: if (model()) { reVec3 dirZ = reVec3(model()->worldTransform().matrix * reVec4(0,0,-1, 0)); reVec3 dirX = reVec3(model()->worldTransform().matrix * reVec4(1,0,0, 0)); if (reRadial::shared()->input()->keyStates['W']) { body->btBody->applyCentralForce(toBullet(dirZ * 50.0f)); } if (reRadial::shared()->input()->keyStates['S']) { body->btBody->applyCentralForce(toBullet(dirZ * -50.0f)); } if (reRadial::shared()->input()->keyStates[' ']) { body->btBody->applyCentralForce(toBullet(dirX * 1.0f)); //reVec4 f = worldTransform().matrix * reVec4(0,-200,0,0); //btVector3 bf(f.x, f.y, f.z); //body->btBody->applyCentralForce(bf); } if (reRadial::shared()->input()->keyStates['A']) { reVec3 v = reVec3(glm::rotate(reMat4(), rs, reVec3(0,1,0)) * reVec4(fromBullet(body->btBody->getLinearVelocity()), 0)); body->btBody->setLinearVelocity(toBullet(v)); model()->transform(glm::rotate(reMat4(), rs, reVec3(0,1,0)) * model()->transform().matrix); //body->btBody->applyCentralForce(toBullet(f)); } if (reRadial::shared()->input()->keyStates['D']) { reVec3 v = reVec3(glm::rotate(reMat4(), -rs, reVec3(0,1,0)) * reVec4(fromBullet(body->btBody->getLinearVelocity()), 0)); body->btBody->setLinearVelocity(toBullet(v)); model()->transform(glm::rotate(reMat4(), -rs, reVec3(0,1,0)) * model()->transform().matrix); //deltaAngle += reVec3(0,-1,0); //model()->transform(glm::rotate(reMat4(), -1.0f, reVec3(0,1,0)) * model()->transform().matrix); } reVec3 pos = worldTransform().position(); camera->lookAt(pos); light->lookAt(pos); if (pos.y < calculateVertex(reVec4(pos,1)).y) { //__debugbreak(); } break; } } if (glm::length(fromBullet(body->btBody->getLinearVelocity()))) { reVec3 dir = glm::normalize(fromBullet(body->btBody->getLinearVelocity())); if (!dir.z) { return; } float yaw = dir.z < 0 ? glm::atan(dir.x / dir.z) : M_PI - glm::atan(dir.x / -dir.z); float pitch = glm::atan(dir.y / abs(dir.z)); reMat4 y(glm::rotate(reMat4(), glm::degrees(yaw), reVec3(0,1,0))); reMat4 p(glm::rotate(reMat4(), glm::degrees(pitch), reVec3(1,0,0))); model()->children->at(0)->transform(p); reVec3 da = reVec3(0, glm::degrees(yaw), 0) - camera->lookAngles(); camera->lookAngles(camera->lookAngles() + da / 5.0f ); } }