void Camera::rotateView(float x, float y) { float thetaX = -y*right.x + x*up.x; float thetaY = -y*right.y + x*up.y; float thetaZ = -y*right.z + x*up.z; if(cameraMode == FREEROAM_CAMERA) { vec3 newDir = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY) * vec4(dir, 1)); changeDir(newDir); } else if(cameraMode == MODELVIEWER_CAMERA) { pos = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY) * vec4(pos - viewCenter, 1)) + viewCenter; //Rotate position around center float pos_length = length(pos-viewCenter); vec3 _dir = normalize(pos-viewCenter); /*if (abs(_dir.y) > maxY) { if (_dir.y < 0) _dir.y = -maxY; else _dir.y = maxY; float s = sqrt((1 - maxY*maxY) / (_dir.x*_dir.x + _dir.z*_dir.z)); _dir.x *= s; _dir.z *= s; _dir = normalize(_dir); pos = viewCenter+_dir*pos_length; }*/ if ((_dir.y > maxY) || (_dir.y < minY)) { float s = 1.f; if (_dir.y > maxY) { _dir.y = maxY; s = sqrt((1 - maxY*maxY) / (_dir.x*_dir.x + _dir.z*_dir.z)); } else if (_dir.y < minY) { _dir.y = minY; s = sqrt((1 - minY*minY) / (_dir.x*_dir.x + _dir.z*_dir.z)); } dir.x *= s; _dir.z *= s; _dir = normalize(_dir); pos = viewCenter + _dir*pos_length; } changeDir(normalize(viewCenter-pos)); } }
void COLLADA_Viewer::SixAxis(float flX, float flY, float flZ, float flG) { (void) flG; if (_CrtRender.UsingPhysics()) { static float dampedX = 0.0f; static float dampedY = 0.0f; static float dampedZ = 0.0f; dampedX=(flX + 10.f*dampedX)/11.f; dampedY=(flY + 10.f*dampedY)/11.f; dampedZ=(flZ + 10.f*dampedZ)/11.f; btTransform floorTrans; floorTrans.setIdentity(); btVector3 xAxis(1,0,0); btVector3 zAxis(0,0,1); btQuaternion rotX(zAxis,dampedX*10.f); btQuaternion rotZ(xAxis,-dampedZ*10.f); btQuaternion combinedRot = rotZ*rotX; btMatrix3x3 orn; orn.setRotation(combinedRot); btVector3 up = orn.getColumn(1); CrtVec3f newG = CrtVec3f(up.getX(),up.getY(),up.getZ()); _CrtRender.SetGravity(newG); // printf("new gravity (%f, %f, %f)\n", newG.getX(), newG.getY(), newG.getZ()); } }
void Camera::setXRotation(const float angle) { float sourceRot[16], rotXMat[16]; memcpy_s(sourceRot,sizeof(float) * 16,m_rotMatrix,sizeof(float) * 16); rotX( rad2deg(m_yMov),rotXMat); multMat(rotXMat, sourceRot, m_rotMatrix); }
void Camera::rotateViewAround(float x, float y) { float thetaX = -y*right.x + x*up.x; float thetaY = -y*right.y + x*up.y; float thetaZ = -y*right.z + x*up.z; pos = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY)* vec4(pos - viewCenter, 1) )+ viewCenter; //Rotate position around center changeDir(viewCenter-pos); }
static void anon_str(logmeta_t *meta, logpipe_field_t field) { str_t *str = logmeta_field(meta, field); if( ! str->ptr || str->len < 1 ) { return; } size_t i; for( i = 0; i < str->len; i++ ) { str->ptr[i] = (unsigned char)rotX((char)str->ptr[i]); } }
void OpekeTool::setupActions() { connect (b_rotateX, SIGNAL(clicked()), this, SIGNAL(rotX())); connect (b_rotateY, SIGNAL(clicked()), this, SIGNAL(rotY())); connect (b_rotateZ, SIGNAL(clicked()), this, SIGNAL(rotZ())); connect ( color, SIGNAL ( highlighted ( QColor ) ), this, SIGNAL ( colorChanged( QColor ) ) ); connect ( color, SIGNAL ( activated ( QColor ) ), this, SIGNAL ( colorViewed ( QColor ) ) ); connect ( planeZ, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( planeChanged ( int ) ) ); connect ( sizeX, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( sizeXChanged ( int ) ) ); connect ( sizeY, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( sizeYChanged ( int ) ) ); connect ( sizeZ, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( sizeZChanged ( int ) ) ); }
int main(){ auto r = rotX(0); for(auto i : r * r) std::cout << i << " "; Matrix2x2a d2({2, 0, 0, 2}); std::cout << std::endl; for(auto i : d2 * inverse(d2)) std::cout << i << " "; std::cout << std::endl; for(auto i : inverse(d2) * d2) std::cout << i << " "; std::cout << std::endl; Matrix3x3a o = { 0, 1, 2 , 3, 4, 5 , 6, 7, 8 }; for(auto i : transpose(o)) std::cout << i << " "; }
void SphereObject::transform() { //Create transformation matrices Matrix scale(SCALE, xScale, yScale, zScale); Matrix rotX(ROT_X, xAngle * MATH_PI / 180.0f); Matrix rotY(ROT_Y, yAngle * MATH_PI / 180.0f); Matrix rotZ(ROT_Z, zAngle * MATH_PI / 180.0f); Matrix axisRot(IDENTITY); axisRot.set(ROT_AXIS_ANGLE, this -> rotAxis, this -> axisRotAngle * MATH_PI / 180.0f); Matrix orbitRot(IDENTITY); orbitRot.set(ROT_AXIS_ANGLE, this -> orbitAxis, this -> orbitAngle * MATH_PI / 180.0f); Matrix trans( TRANS, this -> startPos[x] + this -> xTrans, this -> startPos[y] + this -> yTrans, this -> startPos[z] + this -> zTrans ); Matrix orbitTrans(TRANS, this -> xOrbitTrans, this -> yOrbitTrans, this -> zOrbitTrans ); //Create the normal matrix this -> normal = rotX * rotY * rotZ * axisRot * (orbitTrans * orbitRot); //Create the local to world matrix (ie Model) this -> world = scale * rotX * rotY * rotZ * axisRot * (orbitTrans * orbitRot) * trans; // Create the ModelView ( LocalToWorld * View) // Some pipelines have the project concatenated, others don't // Best to keep the separated, you can always join them with a quick multiply CameraManager* cm = CameraManager::getInstance(); this -> modelView = this -> world * cm -> getCam1() -> getViewMatrix(); //Since we are using the supplied flat shader we need to send it the //combined modelView and Projection Matrices this -> modelViewProj = this -> modelView * cm -> getCam1() -> getProjMatrix(); //Transform the lighting position this -> transformedLightPos = this -> lightPos;// * cm -> getCam1() -> getViewMatrix(); Looks like I do not need this for now }
bool Skeleton::setBoneRotationsAngles(const unsigned int& idx, const vec3& angles) { if(idx >= mBones.size()) { return false; } // rotation around x anax rotX(angles.x(), vec3::UnitX()); // pitch anax rotY(angles.y(), vec3::UnitY()); // yaw anax rotZ(angles.z(), vec3::UnitZ()); // roll quat q = rotX * rotY * rotZ; mBones[idx].R = q.matrix(); std::vector<REAL> len; getBoneLengths(len); fitToBoneLengths(len); return true; }
bool ASMs1D::generateTwistedFEModel (const RealFunc& twist, const Vec3& Zaxis) { if (!this->generateOrientedFEModel(Zaxis)) return false; // Update the local element axes for 3D beam elements Tensor rotX(3); for (size_t i = 0; i < myCS.size(); i++) if (MLGE[i] > 0) { Vec3 X1 = this->getCoord(1+MNPC[i].front()); Vec3 X2 = this->getCoord(1+MNPC[i][curv->order()-1]); double alpha = twist(0.5*(X1+X2)); // twist angle in the element mid-point myCS[i] *= Tensor(alpha*M_PI/180.0,1); // rotate about local X-axis #ifdef SP_DEBUG std::cout <<"Twisted axes for beam element "<< MLGE[i] <<", from "<< X1 <<" to "<< X2 <<":\n"<< myCS[i]; #endif } return true; }
mat3<float> rotationMat3(float a, vec3<float> axis) { a *= DEGTORAD; double cosAx = cos(a * axis.x); double sinAx = sin(a * axis.x); double cosAy = cos(a * axis.y); double sinAy = sin(a * axis.y); double cosAz = cos(a * axis.z); double sinAz = sin(a * axis.z); mat3<float> rotX(1, 0, 0, 0, cosAx,-sinAx, 0, sinAx, cosAx); mat3<float> rotY(cosAy, 0, sinAy, 0, 1, 0, -sinAy, 0, cosAy); mat3<float> rotZ(cosAz,-sinAz, 0, sinAz, cosAz, 0, 0, 0, 1); return rotX * rotY * rotZ; }
void CTwisterDialog::UpdateRotation(CString & strResult) { bool error = FALSE; double x, y, z; x=y=z=0; x = atof(m_strX); y = atof(m_strY); z = atof(m_strZ); if(!m_bRadians) { x *= V_DEGTORAD; y *= V_DEGTORAD; z *= V_DEGTORAD; } CAxisRotation rotX(1, 0, 0, x); CAxisRotation rotY(0, 1, 0, y); CAxisRotation rotZ(0, 0, 1, z); CQuaternion quatX(rotX); CQuaternion quatY(rotY); CQuaternion quatZ(rotZ); CQuaternion quatResult = quatZ * quatY * quatX; CAxisRotation rotResult(quatResult); strResult = rotResult.ToString(2); return; }
void OpekeTool::rotateX() { emit rotX(); }
void Opeke::setupActions() { KStandardAction::openNew ( this, SLOT ( fileNew() ), actionCollection() ); KStandardAction::quit ( qApp, SLOT ( quit() ), actionCollection() ); KStandardAction::save ( this, SLOT ( saveFile() ), actionCollection() ); KStandardAction::open ( this, SLOT ( openFile() ), actionCollection() ); KStandardAction::saveAs ( this, SLOT ( saveFileAs() ), actionCollection() ); KStandardAction::preferences ( this, SLOT ( optionsPreferences() ), actionCollection() ); undoAct = KStandardAction::undo (m_view, SLOT(undo()), actionCollection() ); redoAct = KStandardAction::redo (m_view, SLOT(redo()), actionCollection() ); removeAct = KStandardAction::cut (m_view, SLOT(delBrick()), actionCollection()); removeAct->setShortcut(QKeySequence(Qt::Key_Delete)); removeAct->setText( i18n ("Delete")); removeAct->setEnabled(false); // The action to start building Bricks in OGRE KAction *build = new KAction ( KIcon ( "build" ), i18n ( "Build" ), this ); build->setShortcut(QKeySequence(Qt::Key_B)); actionCollection()->addAction ( QLatin1String ( "build_action" ), build ); connect ( build, SIGNAL ( triggered ( bool ) ), m_view, SLOT ( setBuildMode() ) ); // Start select mode KAction *select = new KAction ( KIcon ( "select" ), i18n ( "S&elect" ), this ); select->setShortcut(QKeySequence(Qt::Key_E)); actionCollection()->addAction ( QLatin1String ( "select_action" ), select ); connect ( select, SIGNAL ( triggered ( bool ) ), m_view, SLOT ( setSelectMode() ) ); // Enable or disable grid KAction *grid = new KAction (KIcon ( "grid" ), i18n ("Toggle &Grid"), this); grid->setShortcut(QKeySequence(Qt::Key_G)); actionCollection()->addAction(QLatin1String("grid_action"), grid); connect (grid, SIGNAL (triggered (bool)), m_view, SLOT (flipGridEnabled() )); // Actions to choose what kind of Brick to build KAction *block = new KAction (KIcon ( "block" ), i18n ("Build B&lock"), this); block->setShortcut(QKeySequence(Qt::Key_L)); actionCollection()->addAction(QLatin1String("block_action"), block); connect (block, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeBlock() )); connect (block, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *roof = new KAction (KIcon ( "roof" ), i18n ("Build &Roof"), this); roof->setShortcut(QKeySequence(Qt::Key_R)); actionCollection()->addAction(QLatin1String("roof_action"), roof); connect (roof, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeRoof())); connect (roof, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *cylinder = new KAction (KIcon ( "cylinder" ), i18n ("Build &Cylinder"), this); cylinder->setShortcut(QKeySequence(Qt::Key_C)); actionCollection()->addAction(QLatin1String("cylinder_action"), cylinder); connect (cylinder, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeCylinder() )); connect (cylinder, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *invCyl = new KAction (KIcon ("invCyl"), i18n ("Build &Inverted Cylinder"), this); invCyl->setShortcut(QKeySequence(Qt::Key_I)); actionCollection()->addAction(QLatin1String("invCyl_action"), invCyl); connect (invCyl, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeInvCyl() )); connect (invCyl, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *sphere = new KAction (KIcon ("sphere"), i18n ("Build &Sphere"), this); sphere->setShortcut(QKeySequence(Qt::Key_S)); actionCollection()->addAction(QLatin1String("sphere_action"), sphere); connect (sphere, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeSphere() )); connect (sphere, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *cone = new KAction (KIcon ( "cone" ), i18n ("Build Co&ne"), this); cone->setShortcut(QKeySequence(Qt::Key_N)); actionCollection()->addAction(QLatin1String("cone_action"), cone); connect (cone, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeCone() )); connect (cone, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *corner = new KAction (KIcon ( "corner" ), i18n ("Build Roof C&orner"), this); corner->setShortcut(QKeySequence(Qt::Key_O)); actionCollection()->addAction(QLatin1String("corner_action"), corner); connect (corner, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeCorner() )); connect (corner, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *invrcor = new KAction (KIcon ( "invrcor" ), i18n ("Build In&verted Roof Corner"), this); invrcor->setShortcut(QKeySequence(Qt::Key_V)); actionCollection()->addAction(QLatin1String("invrcor_action"), invrcor); connect (invrcor, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeInvCorner() )); connect (invrcor, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *pyramid = new KAction (KIcon ( "pyramid" ), i18n ("Build &Pyramid"), this); pyramid->setShortcut(QKeySequence(Qt::Key_P)); actionCollection()->addAction(QLatin1String("pyramid_action"), pyramid); connect (pyramid, SIGNAL (triggered (bool)), m_view, SLOT (changeTypePyramid() )); connect (pyramid, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() )); KAction *snapshot = new KAction (KIcon ("ksnapshot"), i18n ("&Take Screenshot"), this); snapshot->setShortcut(QKeySequence("Ctrl+T")); actionCollection()->addAction(QLatin1String("snapshot_action"), snapshot); connect (snapshot, SIGNAL(triggered(bool)), this, SLOT (saveScreen())); // Reload the field after loading a new file connect ( this, SIGNAL ( reload() ), m_view, SLOT ( update() ) ); connect ( this, SIGNAL ( clear() ), m_view, SLOT ( newScene() ) ); connect ( m_tool, SIGNAL ( colorViewed ( QColor ) ), m_view, SLOT ( viewColor ( QColor ) ) ); connect ( m_tool, SIGNAL ( colorChanged ( QColor ) ), m_view, SLOT ( setColor ( QColor ) ) ); connect ( m_tool, SIGNAL ( planeChanged ( int ) ), m_view, SLOT ( setPlaneZ ( int ) ) ); connect ( m_tool, SIGNAL ( sizeXChanged ( int ) ), m_view, SLOT ( setSizeX ( int ) ) ); connect ( m_tool, SIGNAL ( sizeYChanged ( int ) ), m_view, SLOT ( setSizeY ( int ) ) ); connect ( m_tool, SIGNAL ( sizeZChanged ( int ) ), m_view, SLOT ( setSizeZ ( int ) ) ); connect ( m_view, SIGNAL(planeChanged(int)), m_tool, SLOT(changePlaneZ(int))); connect ( m_view, SIGNAL(undoEmpty(bool)), this, SLOT(undoEnable(bool))); connect ( m_view, SIGNAL(redoEmpty(bool)), this, SLOT(redoEnable(bool))); connect ( m_view, SIGNAL(delEnable(bool)), this, SLOT(removeEnable(bool))); connect ( m_view, SIGNAL(modified()), this, SLOT(fileModified())); connect (m_tool, SIGNAL(rotX()), m_view, SLOT(rotateX())); connect (m_tool, SIGNAL(rotY()), m_view, SLOT(rotateY())); connect (m_tool, SIGNAL(rotZ()), m_view, SLOT(rotateZ())); }