int main() { int i, j; char s[M], t[M]; int find; while (scanf ("%s", input) != EOF) { find = 0; for (i=0; i<6; i++) s[i] = input[i]; s[i] = '\0'; for (i=6,j=0; i<12; i++, j++) t[j] = input[i]; t[j] = '\0'; rota (t, map[0]); strcpy (t, rotated); for (i=0; i<=5; i++) { rota (s, map[i]); if (!strcmp (rotated, t)) { printf ("TRUE\n"); find=1; break; } for (j=0; j<3; j++) { rightR(rotated); if (!strcmp (rotated, t)) { printf ("TRUE\n"); i=6; find=1; break; } } } if (!find) printf ("FALSE\n"); } return 0; }
/* lexcographic order between '\0'-ending-strings */ int lex_comp(const void * pt1, const void * pt2) { int p = * (int *) pt1, q = * (int *) pt2; char diff; int i; for (i = 0; rota(p, i) != '\0' && rota(q, i) != '\0'; i++) { diff = rota(p, i) - rota(q, i); if ( diff != 0 ) return diff; } return 0; }
void InvPlaneMover::setPosition(SbVec3f &point) { // make sure that the normal points in direction to the camera SbVec3f camPos = renderer->viewer->getCamera()->position.getValue(); SbVec3f no; if (camPos.dot(planeNormal_) < 0) { no = planeNormal_; } else { no = -planeNormal_; } fprintf(stderr, "inorm=(%f %f %f), no=(%f %f %f)\n", iNorm_[0], iNorm_[1], iNorm_[2], no[0], no[1], no[2]); SbRotation rota(iNorm_, no); distOffset_ = point; nnn_ = no; // the handle lays in front of the plane by this distance float offset_of_handle = 0.001 * scale_->scaleFactor.getValue()[0]; // if (!show) { transl_->translation = point - offset_of_handle * no; fullRot_->rotation = rota; // } SbVec3f t(0, 0, 0); jDrag_->translation.setValue(t); jDrag_->rotation.setValue(SbRotation::identity()); }
int main(int argc, char * argv[]) { int *order; int i, j, org; char * transformed; /* preparing an array for the argument's size */ printf("Input: \"%s\"\n", argv[1]); TEXT = argv[1]; /* copying the pointer, not contents of the string */ LENGTH = strlen(TEXT); transformed = (char *) malloc(sizeof(char) * (LENGTH+1)); order = (int *) malloc(sizeof(int) * LENGTH); for (i = 0; i < LENGTH; i++) order[i] = i; for (i = 0; i < LENGTH; i++) { for (j = 0; j < LENGTH; j++) { printf("%c", rota(i,j)); } printf("\n"); } printf("\n --- Result ---\n\n"); qsort(order, LENGTH, sizeof(int), &lex_comp); for (i = 0; i < LENGTH; i++) { for (j = 0; j < LENGTH; j++) { printf("%c", rota(order[i],j)); } printf("\n"); if (order[i] == 0) org = i; } for (i = 0; i < LENGTH; i++) transformed[i] = rota(order[i],LENGTH-1); transformed[LENGTH] = '\0'; /* don't forget placing the terminal */ printf("\nTransformed into \n\"%s\"\nand the original text is at row %d.\n",transformed, org+1); return 0; /* no error */ }
/** * Rotates the camera around a point and an axis. * * @param amount the amount (in radians) to rotate the camera by * @param which the axis to rotate the camera around * @param around the point to rotate the camera around */ void Camera::rotate(double amount, axis which, Vector around) { Matrix<double> rota(4, 4); Vector vecs[3]; switch(which) { case x_axis: vecs[2] = v; break; case y_axis: vecs[2] = u; break; case z_axis: return; break; } vecs[0] = vecs[2].getPerpendicular(); vecs[1] = cross(vecs[0], vecs[2]).normalize(); auto R = ray::eye<double>(4); for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) R[i][j] = vecs[i][j]; /* create z */ auto z = ray::eye<double>(4); z[0][0] = std::cos(amount); z[0][1] = std::sin(amount); z[1][0] = -std::sin(amount); z[1][1] = std::cos(amount); /* create rotation matrix */ rota = R.t() * z * R; /* move the actual camera elements */ fp = fp - around; fp = rota * fp; fp = fp + around; n = rota * n; u = rota * u; v = rota * v; vrp = fp + (n * fl); }
//-------------------------------------------------------------------- // setWorldRotation() //-------------------------------------------------------------------- void LLJoint::setWorldRotation( const LLQuaternion& rot ) { if (mParent == NULL) { this->setRotation( rot ); return; } LLMatrix4a parentWorldMatrix = mParent->getWorldMatrix(); LLQuaternion2 rota(rot); LLMatrix4a temp_mat(rota); LLMatrix4a invParentWorldMatrix = mParent->getWorldMatrix(); invParentWorldMatrix.setTranslate_affine(LLVector3(0.f)); invParentWorldMatrix.invert(); invParentWorldMatrix.mul(temp_mat); setRotation(LLQuaternion(LLMatrix4(invParentWorldMatrix.getF32ptr()))); }
// Surface bool CLwoWriter::WriteSurfaces() { // surface tag names CLwoFile::CLayer::SurfaceMap& surfaces = m_curLayer.GetSurfaceMap(); CLwoFile::CLayer::SurfaceMap::iterator surfaceIt, surfaceEnd; surfaceEnd = surfaces.end(); for(surfaceIt = surfaces.begin(); surfaceIt != surfaceEnd; ++surfaceIt) // For each surface { std::string surfaceName(surfaceIt->first); CLwoFile::CLayer::CSurface& surface = surfaceIt->second; MSG_DEBUG("SURF: '" << surfaceName << "'"); // "SURF" + size WriteTag(CLwoFile::CHUNK_SURF); WriteLong(surface.m_size); // hack for surface, in fact, it should be like this for everything // surface name OBJ_ASSERT(surfaceName == surface.GetSurfaceName()); WriteString(surfaceName); // parent/source name std::string parentLayerName(""); WriteString(parentLayerName); // SURF | COLR { MSG_DEBUG("SURF | COLR"); WriteTag(CLwoFile::CHUNK_COLR); ushort colr_size = (ushort)(m_chunkLengthMap[CLwoFile::CHUNK_COLR]); WriteShort(colr_size); // Color Vector3D color(3); color[0] = 0.78431f; color[1] = 0.78431f; color[2] = 0.78431f; WriteVector3D(color); // Envl ushort envl = 0; WriteShort(envl); } // SURF | DIFF { MSG_DEBUG("SURF | DIFF"); WriteTag(CLwoFile::CHUNK_DIFF); ushort diff_size = (ushort)(m_chunkLengthMap[CLwoFile::CHUNK_DIFF]); WriteShort(diff_size); float diffuse = 1.0f; WriteFloat(diffuse); ushort lumi = 0; WriteShort(lumi); } // SURF | BLOK if(surface.m_imageIndex != -1) // there is an image index { MSG_DEBUG("SURF | BLOK"); // BLOK WriteTag(CLwoFile::CHUNK_BLOK); WriteShort((ushort)m_chunkLengthMap[CLwoFile::CHUNK_BLOK]); // SURF | BLOK | IMAP { MSG_DEBUG("SURF | BLOK | IMAP"); // IMAP WriteTag(CLwoFile::CHUNK_IMAP); m_chunkLengthMap[CLwoFile::CHUNK_IMAP] = 50; WriteShort((ushort)m_chunkLengthMap[CLwoFile::CHUNK_IMAP]); // IMAP size { ushort ordStrCmp = 0x8000; WriteShort(ordStrCmp); // Ordinal string compare function // CHAN WriteTag(CLwoFile::CHUNK_CHAN); WriteShort(4); // CHAN size WriteTag(CLwoFile::CHUNK_COLR); // OPAC WriteTag(CLwoFile::CHUNK_OPAC); WriteShort(8); // OPAC size WriteShort(0); WriteFloat(1.0f); WriteShort(0); // ENAB WriteTag(CLwoFile::CHUNK_ENAB); WriteShort(2); // ENAB size WriteShort(1); // NEGA WriteTag(CLwoFile::CHUNK_NEGA); WriteShort(2); // NEGA size WriteShort(0); // AXIS WriteTag(CLwoFile::CHUNK_AXIS); WriteShort(2); // AXIS size WriteShort(1); } } // SURF | BLOK | TMAP { MSG_DEBUG("SURF | BLOK | TMAP"); // TMAP WriteTag(CLwoFile::CHUNK_TMAP); ushort imap_size = 104; WriteShort(imap_size); { // CNTR WriteTag(CLwoFile::CHUNK_CNTR); WriteShort(14); // CHAN size Vector3D center(3); WriteVector3D(center); WriteShort(0); // SIZE WriteTag(CLwoFile::CHUNK_SIZE); WriteShort(14); // SIZE size Vector3D size(3); size[0] = 1.0f; size[1] = 1.0f; size[2] = 1.0f; WriteVector3D(size); WriteShort(0); // ROTA WriteTag(CLwoFile::CHUNK_ROTA); WriteShort(14); // ROTA size Vector3D rota(3); WriteVector3D(rota); WriteShort(0); // FALL WriteTag(CLwoFile::CHUNK_FALL); WriteShort(16); // FALL size WriteShort(0); Vector3D fall(3); WriteVector3D(fall); WriteShort(0); // OREF WriteTag(CLwoFile::CHUNK_OREF); WriteShort(8); // OREF size WriteString(std::string("(none)")); // CSYS WriteTag(CLwoFile::CHUNK_CSYS); WriteShort(2); // CSYS size WriteShort(0); } } // PROJ : projection WriteTag(CLwoFile::CHUNK_PROJ); WriteShort(2); // PROJ size WriteShort(5); // UV projection mapping // AXIS WriteTag(CLwoFile::CHUNK_AXIS); WriteShort(2); // AXIS size WriteShort(2); // IMAG WriteTag(CLwoFile::CHUNK_IMAG); WriteShort(2); // IMAG size WriteShort(surface.m_imageIndex); // Write the image index corresponding to imageVector // WRAP WriteTag(CLwoFile::CHUNK_WRAP); WriteShort(4); // WRAP size WriteShort(1); WriteShort(1); // WRPW WriteTag(CLwoFile::CHUNK_WRPW); WriteShort(6); // WRPW size WriteFloat(1.0f); WriteShort(0); // WRPH WriteTag(CLwoFile::CHUNK_WRPH); WriteShort(6); // WRPH size WriteFloat(1.0f); WriteShort(0); // VMAP WriteTag(CLwoFile::CHUNK_VMAP); WriteShort(8); // VMAP size WriteString("txuv00"); // TODO : increment for multiple meshes? // AAST WriteTag(CLwoFile::CHUNK_AAST); WriteShort(6); // AAST size WriteShort(1); WriteFloat(1.0f); // PIXB WriteTag(CLwoFile::CHUNK_PIXB); WriteShort(2); // PIXB size WriteShort(1); } } return true; }
void CoreEngine::run() { isRunning = true; bool render; int frames = 0; long long frameCounter = 0; double accFrames = 0; double unaccounted = 0; app->init(); //TEMP________________________________________________________________________________________________________________________________________ graphics::Shader shader("res/shaders/basic.vert", "res/shaders/basic.frag"); shader.enable(); GLfloat vertices[] = { -4, -2.31f, 0, 0, 4.62f, 0, 4, -2.31f, 0 }; GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); maths::mat4 ortho = maths::mat4::orthographic(0.0f, 16.0f, 0.0f, 16.0f, -8.0f, 8.0f); maths::mat4 persp = maths::mat4::perspective(1.22173f, (float)window->getWidth() / (float)window->getHeight(), 0.1f, 1000); shader.setUniformMat4("pr_matrix", ortho); shader.setUniformMat4("vw_matrix", maths::mat4::translation(maths::vec3(8, 8, 0))); maths::quaternion rotation(maths::vec3(0, 0, 1), 0); maths::quaternion rota(maths::vec3(0, 0, 1), 1); maths::quaternion rotb(maths::vec3(1, 1, 0), 2); maths::vec4 colour; float test = 0; //____________________________________________________________________________________________________________________________________________ long long lastTime = util::Time::getNanoTime(); long long startTime; long long passedTime; long long unprocessedTime = 0; profiling::ProfileTimer totalTimer; profiling::ProfileTimer inputTimer; profiling::ProfileTimer updateTimer; profiling::ProfileTimer renderTimer; profiling::ProfileTimer windowTimer; profiling::ProfileTimer sleepTimer; while (isRunning) { totalTimer.startInvocation(); render = false; startTime = util::Time::getNanoTime(); passedTime = startTime - lastTime; lastTime = startTime; unprocessedTime += passedTime; frameCounter += passedTime; while (unprocessedTime > frameTimeNano) { render = true; unprocessedTime -= frameTimeNano; inputTimer.startInvocation(); app->input((float)frameTime); if (window->isKeyPressed(GLFW_KEY_L)) stop(); inputTimer.stopInvocation(); updateTimer.startInvocation(); app->update((float)frameTime); updateTimer.stopInvocation(); if (frameCounter >= 1000000000) { accFrames = ((double)frames) / (double) (frameCounter / 1000000000.0); printf("%.2f Fps--", accFrames); unaccounted = totalTimer.displayAndReset(" Total:", accFrames); unaccounted -= inputTimer.displayAndReset(" Input:", accFrames); unaccounted -= updateTimer.displayAndReset(" Update:", accFrames); unaccounted -= renderTimer.displayAndReset(" Render:", accFrames); unaccounted -= windowTimer.displayAndReset(" Window:", accFrames); unaccounted -= sleepTimer.displayAndReset(" Sleep:", accFrames); printf(" Unaccounted: %.2f\n", unaccounted); frames = 0; frameCounter = 0; unaccounted = 0; } } if (window->closed()) { stop(); } if (render) { renderTimer.startInvocation(); renderingEngine->render(app->render()); //TEMP___________________________________________________________________________________________________________________________________________ rotation *= (rotb * rota); test += 0.01f; shader.setUniform2f("light_pos", maths::vec2(3 * cos(-test * 4), 3 * sin(-test * 4))); colour.set(pow(cos(test), 2), pow(sin(test + test / 2), 2), pow(sin(test + 2), 2), 1); shader.setUniform4f("col", colour); shader.setUniformMat4("ml_matrix", rotation.toRotationMatrix()); glDrawArrays(GL_TRIANGLES, 0, 3); //_______________________________________________________________________________________________________________________________________________ renderTimer.stopInvocation(); windowTimer.startInvocation(); window->update(); windowTimer.stopInvocation(); frames++; } else { sleepTimer.startInvocation(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); sleepTimer.stopInvocation(); } totalTimer.stopInvocation(); } std::cout << "[Core Engine Terminated]" << std::endl; }