// Rotate a vector *v by the euler angles defined by the 3-vector *delta. void rotateV(struct fp_vector *v, fp_angles_t *delta) { struct fp_vector v_tmp = *v; float matrix[3][3]; buildRotationMatrix(delta, matrix); v->X = v_tmp.X * matrix[0][X] + v_tmp.Y * matrix[1][X] + v_tmp.Z * matrix[2][X]; v->Y = v_tmp.X * matrix[0][Y] + v_tmp.Y * matrix[1][Y] + v_tmp.Z * matrix[2][Y]; v->Z = v_tmp.X * matrix[0][Z] + v_tmp.Y * matrix[1][Z] + v_tmp.Z * matrix[2][Z]; }
void initBoardAlignment(const boardAlignment_t *boardAlignment) { if (isBoardAlignmentStandard(boardAlignment)) { return; } standardBoardAlignment = false; fp_angles_t rotationAngles; rotationAngles.angles.roll = degreesToRadians(boardAlignment->rollDegrees ); rotationAngles.angles.pitch = degreesToRadians(boardAlignment->pitchDegrees); rotationAngles.angles.yaw = degreesToRadians(boardAlignment->yawDegrees ); buildRotationMatrix(&rotationAngles, boardRotation); }
void RotationTranslator::move(TouchInfo &ti, const ci::Vec3f &previous_global_pt) { if (!(ti.mPickedSprite && ti.mPickedSprite->isRotateTouches())) return; ci::Matrix44f m(ci::Matrix44f::identity()); auto f = mMatrix.find(ti.mFingerId); if (f != mMatrix.end()) { m = f->second; } else { m = buildRotationMatrix(ti.mPickedSprite); mMatrix[ti.mFingerId] = m; } ci::Vec3f pt(ti.mCurrentGlobalPoint - ti.mStartPoint); pt = ti.mStartPoint + m.transformPoint(pt); ti.mCurrentGlobalPoint = pt; ti.mDeltaPoint = ti.mCurrentGlobalPoint - previous_global_pt; }
void RotationTranslator::down(TouchInfo &ti) { if (!(ti.mPickedSprite && ti.mPickedSprite->isRotateTouches())) return; mMatrix[ti.mFingerId] = buildRotationMatrix(ti.mPickedSprite); }
void drawContext::drawView() { OrthofFromGModel(); glMatrixMode(GL_MODELVIEW); // fill the background glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(CTX::instance()->bgGradient){ glPushMatrix(); glLoadIdentity(); const GLfloat squareVertices[] = { (GLfloat)_top, (GLfloat)_left, 2*_far, (GLfloat)_top, (GLfloat)_right, 2*_far, (GLfloat)_bottom, (GLfloat)_left, 2*_far, (GLfloat)_bottom, (GLfloat)_right, 2*_far, }; const GLubyte squareColors[] = { 255, 255, 255, 255, 255, 255, 255, 255, 190, 200, 255, 255, 190, 200, 255, 255, }; glVertexPointer(3, GL_FLOAT, 0, squareVertices); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors); glEnableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); } checkGlError("Draw background"); glLoadIdentity(); glScalef(_scale[0], _scale[1], _scale[2]); glTranslatef(_translate[0], _translate[1], _translate[2]); if(CTX::instance()->rotationCenterCg) glTranslatef(CTX::instance()->cg[0], CTX::instance()->cg[1], CTX::instance()->cg[2]); else glTranslatef(CTX::instance()->rotationCenter[0], CTX::instance()->rotationCenter[1], CTX::instance()->rotationCenter[2]); buildRotationMatrix(); glMultMatrixf(_rotatef); if(CTX::instance()->rotationCenterCg) glTranslatef(-CTX::instance()->cg[0], -CTX::instance()->cg[1], -CTX::instance()->cg[2]); else glTranslatef(-CTX::instance()->rotationCenter[0], -CTX::instance()->rotationCenter[1], -CTX::instance()->rotationCenter[2]); checkGlError("Initialize position"); glEnable(GL_DEPTH_TEST); drawMesh(); checkGlError("Draw mesh"); drawGeom(); checkGlError("Draw geometry"); drawPost(); checkGlError("Draw post-pro"); glDisable(GL_DEPTH_TEST); drawScale(); checkGlError("Draw scales"); drawAxes(); checkGlError("Draw axes"); }