/* * Adds the transformation attribute to the given XMLAttributes object. * * @param transformation the transformation to add as attribute. * * @param att XMLAttributes where the attribute needs to be added to */ void Transformation2D::addTransformation2DAttributes(const Transformation2D& transformation,XMLAttributes& att) { if(transformation.isSetMatrix() && memcmp(transformation.mMatrix,getIdentityMatrix(),12*sizeof(double))!=0) { att.add("transform",transformation.get2DTransformationString()); } }
/* * Subclasses should override this method to write their XML attributes * to the XMLOutputStream. Be sure to call your parents implementation * of this method as well. For example: * * SBase::writeAttributes(stream); * stream.writeAttribute( "id" , mId ); * stream.writeAttribute( "name", mName ); * ... */ void Transformation2D::writeAttributes (XMLOutputStream& stream) const { SBase::writeAttributes(stream); if(this->isSetMatrix() && memcmp(this->mMatrix,getIdentityMatrix(),12*sizeof(double))!=0) { stream.writeAttribute("transform", getPrefix(), this->get2DTransformationString()); } }
Matrix HaloRenderingThread::getOrientationMatrix(CrystalDescriptor::OrientationType orientation) { Matrix m; switch (orientation) { case CrystalDescriptor::OT_RANDOM: { /* First rotate the crystal around the Z axis:*/ Matrix zRot = createRotationMatrix(Vector3(0, 0, 1), randFloat(-3.14159265, 3.14159265)); /* Then rotate the Z axis into an uniformly distributed position*/ const Vector3 newAxis = getRandomVector(); Vector3 rotAxis = Vector3(0, 0, 1) % newAxis; Matrix axisRot = getIdentityMatrix(); if (rotAxis * rotAxis != 0) { rotAxis /= ~rotAxis; double rotAngle = acos(Vector3(0, 0, 1) * newAxis); axisRot = createRotationMatrix(rotAxis, rotAngle); } return zRot % axisRot; } break; case CrystalDescriptor::OT_PARRY: { /* For hexagonal prisms, one side face is horizontal. */ m = createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); } break; case CrystalDescriptor::OT_COLUMN: { /* Main axis horizontal. */ Matrix n = createRotationMatrix(Vector3(0, 0, 1), randFloat(0, 3.1415926536)); Matrix o = createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); m = n % o; } break; case CrystalDescriptor::OT_PLATE: { /* Main axis vertical. */ m = createRotationMatrix(Vector3(1, 0, 0), 3.14159265636 * 0.5) % createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); } break; case CrystalDescriptor::OT_LOWITZ: { /* Rotation around a diagonal axis. The axis is horizontal.*/ m = createRotationMatrix(Vector3(1, 0, 0), 3.14159265636 * randFloat(-3.1415 * 0.5, 3.1415 * 0.5)) % createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); } break; default: { sendNotifyString(wxT("Invalid orientation type."), 1); } } return m; }
void LOElectricBall::render(SunnyMatrix *MV) { if (status != LO_Active) return; SunnyMatrix m = position **MV; m = getRotationZMatrix(sRandomf()*2*M_PI) * m; glUniformMatrix4fv(globalModelview[LOS_TexturedTSA], 1, GL_FALSE, &(m.front.x)); glDrawArrays(GL_TRIANGLE_STRIP, (LOObject_VAO+44+sRandomi()%6)*4, 4); const float scale = 1.0/((116.-50.)/640*mapSize.y); SunnyMatrix mat = getIdentityMatrix(); for (short i = 0 ;i<attackCount;i++) { SunnyVector2D v = attack[i]->position; mat.pos.x = v.x; mat.pos.y = v.y; mat.up.x = (position.pos.x - mat.pos.x)*scale; mat.up.y = (position.pos.y - mat.pos.y)*scale; mat.front = mat.up ^ mat.right; m = mat **MV; glUniformMatrix4fv(globalModelview[LOS_TexturedTSA], 1, GL_FALSE, &(m.front.x)); glDrawArrays(GL_TRIANGLE_STRIP, (LOObject_VAO+50+sRandomi()%3)*4, 4); } }
void getInverseDestroy(matrix *m, matrix *dest) { getIdentityMatrix(dest, m->R); int i; int j; int si; nType temp; for(i = 0; i < m->R; i++) { j = getMaxInRow(m, i); if(isZero(m->ptr[i][j])) { dest->R = 0; dest->C = 0; return; } temp = m->ptr[i][j]; if(temp != 1) { #ifdef DEBUG fprintf(stderr, "dividing row %d by %lf\n", i + 1, temp); #endif eop1(m, i, ((nType) 1.) / temp); eop1(dest, i, ((nType) 1.) / temp); #ifdef DEBUG printMatrices(m, dest); #endif } for(si = 0; si < m->R; si++) { if(si != i) { temp = m->ptr[si][j]; if(temp != 0) { #ifdef DEBUG fprintf(stderr, "subtracting row %d multiplied by %lf from row %d\n", i + 1, temp, si + 1); #endif eop2(m, i, temp, si); eop2(dest, i, temp, si); #ifdef DEBUG printMatrices(m, dest); #endif } } } } int k; for(k = 0; k < m->R; k++) for(i = 0; i < m->R; i++) { //0...1...0 //....j.... j = getMaxInRow(m, i); if(i != j) { #ifdef DEBUG fprintf(stderr, "swapping rows %d and %d\n", i + 1, j + 1); #endif eop3(m, i, j); eop3(dest, i, j); #ifdef DEBUG printMatrices(m, dest); #endif } } }