void MeshLoaderSPM::readChunkAnimationSkeletal() { /* Read skeletal animation basics */ const io::stringc AnimName(File_->readStringData()); /* Add new skeletal animation */ SkeletalAnimation* Anim = gSharedObjects.SceneMngr->createAnimation<SkeletalAnimation>("SPM Animation"); AnimationSkeleton* Skeleton = Anim->createSkeleton(); /* Read animation joints */ const u32 JointCount = File_->readValue<u32>(); Joints_.resize(JointCount); for (u32 i = 0; i < JointCount; ++i) readChunkAnimationJoint(Joints_[i]); /* Build joint construction */ foreach (SJointSPM &Joint, Joints_) { /* Create joint object */ Joint.JointObject = Skeleton->createJoint( Transformation(Joint.Position, Joint.Rotation, Joint.Scale), Joint.Name ); /* Setup vertex weights */ std::vector<SVertexGroup> VertexGroups; VertexGroups.resize(Joint.VertexWeights.size()); u32 i = 0; foreach (const SVertexWeightSPM &Vertex, Joint.VertexWeights) { VertexGroups[i++] = SVertexGroup( CurMesh_, Vertex.Surface, Vertex.Index, Vertex.Weight ); } Joint.JointObject->setVertexGroups(VertexGroups); /* Setup keyframes */ foreach (const SKeyframeSPM &Keyframe, Joint.Keyframes) { Anim->addKeyframe( Joint.JointObject, Keyframe.Frame, Transformation(Keyframe.Position, Keyframe.Rotation, Keyframe.Scale) ); } }
Transformation LinearPrediction::Interpolate( Unit *un, double deltatime ) const { static bool no_interp = XMLSupport::parse_bool( vs_config->getVariable( "network", "no_interpolation", "false" ) ); if (no_interp) return Transformation( OB, B ); if (deltatime > this->deltatime || this->deltatime == 0) { double delay = deltatime-this->deltatime; //cerr << "Using new Pos "<<un->GetSerial()<<": A2=("<<A2.i<<",,"<<A2.k<<"), VB=("<<VB.i<<",,"<<VB.k<<"), delay="<<delay<<endl; return Transformation( OB, A2+VB*delay ); } else { const Transformation old_pos( OA, A0 ); //un->curr_physical_state); const Transformation new_pos( OB, A2 ); //cerr << "Using OLD Pos "<<un->GetSerial()<<": A2=("<<A2.i<<",,"<<A2.k<<"), delay="<<(deltatime/this->deltatime)<<", A0=("<<A0.i<<",,"<<A0.k<<")"<<endl; return linear_interpolate_uncapped( old_pos, new_pos, deltatime/this->deltatime ); } }
//********************************************************************************** //test of polyhedron intersection callable from python shell bool do_Polyhedras_Intersect(const shared_ptr<Shape>& cm1,const shared_ptr<Shape>& cm2,const State& state1,const State& state2){ const Se3r& se31=state1.se3; const Se3r& se32=state2.se3; Polyhedra* A = static_cast<Polyhedra*>(cm1.get()); Polyhedra* B = static_cast<Polyhedra*>(cm2.get()); //move and rotate 1st the CGAL structure Polyhedron Matrix3r rot_mat = (se31.orientation).toRotationMatrix(); Vector3r trans_vec = se31.position; Transformation t_rot_trans(rot_mat(0,0),rot_mat(0,1),rot_mat(0,2), trans_vec[0],rot_mat(1,0),rot_mat(1,1),rot_mat(1,2),trans_vec[1],rot_mat(2,0),rot_mat(2,1),rot_mat(2,2),trans_vec[2],1.); Polyhedron PA = A->GetPolyhedron(); std::transform( PA.points_begin(), PA.points_end(), PA.points_begin(), t_rot_trans); //move and rotate 2st the CGAL structure Polyhedron rot_mat = (se32.orientation).toRotationMatrix(); trans_vec = se32.position; t_rot_trans = Transformation(rot_mat(0,0),rot_mat(0,1),rot_mat(0,2), trans_vec[0],rot_mat(1,0),rot_mat(1,1),rot_mat(1,2),trans_vec[1],rot_mat(2,0),rot_mat(2,1),rot_mat(2,2),trans_vec[2],1.); Polyhedron PB = B->GetPolyhedron(); std::transform( PB.points_begin(), PB.points_end(), PB.points_begin(), t_rot_trans); //calculate plane equations std::transform( PA.facets_begin(), PA.facets_end(), PA.planes_begin(),Plane_equation()); std::transform( PB.facets_begin(), PB.facets_end(), PB.planes_begin(),Plane_equation()); //call test return do_intersect(PA,PB); }
void PostScriptView::MinGS (ostream& out) { Brush(out); FgColor(out); BgColor(out); Pattern(out); Transformation(out); }
/// transforms face coordinates to regular system, face normal will be z' /// will try to align y' with z, but if that fails will align y' with y /// face origin will be minimum point in x', y' and z'=0 /// will return identity transformation if cannot compute plane for vertices Transformation Transformation::alignFace(const std::vector<Point3d>& vertices) { OptionalVector3d zPrime = getOutwardNormal(vertices); if (!zPrime){ LOG(Error, "Cannot compute outward normal for vertices"); return Transformation(); } // align z' with outward normal Transformation align = alignZPrime(*zPrime); Point3dVector alignedVertices = align.inverse()*vertices; // compute translation to minimum in aligned system double minX = alignedVertices[0].x(); double minY = alignedVertices[0].y(); double minZ = alignedVertices[0].z(); for (const Point3d& vertex : alignedVertices){ minX = min(minX, vertex.x()); minY = min(minY, vertex.y()); minZ = min(minZ, vertex.z()); } Transformation translate = translation(Vector3d(minX, minY, minZ)); return align*translate; }
/// rotation about origin defined by axis and angle (radians) Transformation Transformation::rotation(const Vector3d& axis, double radians) { Matrix storage = identity_matrix<double>(4); Vector3d temp = axis; if (!temp.normalize()){ LOG(Error, "Could not normalize axis"); } Vector normalVector = temp.vector(); // Rodrigues' rotation formula / Rotation matrix from Euler axis/angle // I*cos(radians) + I*(1-cos(radians))*axis*axis^T + Q*sin(radians) // Q = [0, -axis[2], axis[1]; axis[2], 0, -axis[0]; -axis[1], axis[0], 0] Matrix P = outer_prod(normalVector, normalVector); Matrix I = identity_matrix<double>(3); Matrix Q(3, 3, 0.0); Q(0,1) = -normalVector(2); Q(0,2) = normalVector(1); Q(1,0) = normalVector(2); Q(1,2) = -normalVector(0); Q(2,0) = -normalVector(1); Q(2,1) = normalVector(0); // rotation matrix Matrix R = I*cos(radians) + (1-cos(radians))*P + Q*sin(radians); for (unsigned i = 0; i < 3; ++i){ for (unsigned j = 0; j < 3; ++j){ storage(i,j) = R(i,j); } } return Transformation(storage); }
Transformation Transformation::newTranslation(double dx, double dy, double dz){ return Transformation ({{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {dx, dy, dz, 1}}}); }
FPPlayerEntity::FPPlayerEntity(RenderSystem* pRenderSystem) { m_PointingEulerDir = Vector3( 0.0f, 0.0f, 0.0f ); m_TimeSinceLastShot = 0.0f; m_ShotEntityId = 0; m_bMouseDragged = false; SetRenderSystem( pRenderSystem ); // Set up flashlight m_pSpotlight = new SpotLight(); m_pSpotlight->SetRadius( 100.0f ); m_pSpotlight->SetIntensity( 20.0f ); m_pSpotlight->SetColor( Vector3(1.0f,1.0f,0.8f) ); m_pSpotlight->SetCone( Vector2( XM_PI/3.0f, XM_PI/3.0f ) ); m_pSpotlight->SetCookie( m_pRenderSystem->LoadTexture2D( L"Media/spotlight.bmp" ) ); m_pSpotlight->Transformation()->SetPosition( 0.0f, 0.0f, 0.0f ); m_pSpotlight->PointTo( Vector3( 0.0f, 0.0f, 25.0f ), 0.0f ); m_pSpotlight->SetRSMEnabled( false ); //m_pSpotlight->disable(); UINT width, height; RenderSystemConfig config = pRenderSystem->GetConfig(); width = config.Width; height = config.Height; // Set up first person camera m_pCamera = new Camera3D(); m_pCamera->SetPosition( Transformation()->GetPosition() ); m_pCamera->SetLookAt( Vector3( 0.0f, 1.0f, 0.0f ) ); m_pCamera->SetUpVector( Vector3( 0.0f, 0.0f, 1.0f ) ); m_pCamera->SetProjection( XM_PI*0.35f, width / (float)height, 0.1f, 2000.0f ); m_pCamera->Update( 0.0f ); }
void MarkerDetector::estimatePosition(std::vector<Marker>& detectedMarkers) { for (size_t i=0; i<detectedMarkers.size(); i++) { Marker& m = detectedMarkers[i]; cv::Mat Rvec; cv::Mat_<float> Tvec; cv::Mat raux,taux; cv::solvePnP(m_markerCorners3d, m.points, camMatrix, distCoeff,raux,taux); raux.convertTo(Rvec,CV_32F); taux.convertTo(Tvec ,CV_32F); cv::Mat_<float> rotMat(3,3); cv::Rodrigues(Rvec, rotMat); // Copy to transformation matrix m.transformation = Transformation(); for (int col=0; col<3; col++) { for (int row=0; row<3; row++) { m.transformation.r().mat[row][col] = rotMat(row,col); // Copy rotation component } m.transformation.t().data[col] = Tvec(col); // Copy translation component } // Since solvePnP finds camera location, w.r.t to marker pose, to get marker pose w.r.t to the camera we invert it. m.transformation = m.transformation.getInverted(); } }
void PhysicsBaseObject::setRotation(const dim::matrix4f &Rotation) { const dim::vector3df Position(getPosition()); dim::matrix4f Transformation(Rotation); Transformation.setPosition(Position); setTransformation(Transformation); }
// We can use the precise location of marker corners to estimate a transformation between our camera and a marker in 3D. // This operation is known as pose estimation from 2D-3D correspondences. // This process finds an Euclidean transformation (rotation + translation) between the camera and the object. // We define the 3D coordinates of marker corners putting our marker on the XY plane (Z=0), // with the marker center in the origin (0,0,0). // Then we find the camera location using the 2D-3D correspondences as input for cv::solvePnP. void MarkerDetector::estimatePosition(std::vector<Marker>& detectedMarkers) { for (size_t i = 0; i < detectedMarkers.size(); i++) { Marker& m = detectedMarkers[i]; cv::Mat Rvec; cv::Mat_<float> Tvec; cv::Mat raux; cv::Mat taux; // See: http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#solvepnp cv::solvePnP(markerCorners3D, m.points, camMatrix, distCoeff, raux, taux); // See; http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-convertto raux.convertTo(Rvec, CV_32F); taux.convertTo(Tvec, CV_32F); cv::Mat_<float> rotMat(3, 3); // See: http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#rodrigues cv::Rodrigues(Rvec, rotMat); // Copy to transformation matrix. m.transformation = Transformation(); for (int col = 0; col < 3; col++) { for (int row = 0; row < 3; row++) { // Copy rotation component. m.transformation.r().mat[row][col] = rotMat(row, col); } // Copy translation component. m.transformation.t().data[col] = Tvec(col); } // Since solvePnP finds camera location, with regard to the marker pose, // to get marker pose with regard to the camera we invert it. m.transformation = m.transformation.getInverted(); } }
void Matrix4x4::EulerRotation(const Vertex &rot) { float radiansX = rot._x * (float(PI)/float(180)); float radiansY = rot._y * (float(PI)/float(180)); float radiansZ = rot._z * (float(PI)/float(180)); Matrix4x4 matRotateX; matRotateX.SetMatrix(1.0f, 0.0f, 0.0f, 0.0f, cos(radiansX), sin(radiansX), 0.0f, -sin(radiansX),cos(radiansX)); Matrix4x4 matRotateY; matRotateY.SetMatrix(cos(radiansY), 0.0f, -sin(radiansY), 0.0f, 1.0f, 0.0f, sin(radiansY), 0, cos(radiansY)); Matrix4x4 matRotateZ; matRotateZ.SetMatrix(cos(radiansZ), sin(radiansZ), 0.0f, -sin(radiansZ), cos(radiansZ), 0.0f, 0.0f, 0.0f, 1.0f); matRotateZ.Transformation(matRotateX); matRotateZ.Transformation(matRotateY); Transformation(matRotateZ); }
void Matrix4x4::ArbAxisRotation(Vertex &rotVert, int degrees) { float radians = degrees * (float(PI)/180); rotVert.Normalize(); float xy = rotVert._x * rotVert._y; float xz = rotVert._x * rotVert._z; float yz = rotVert._y * rotVert._z; float xSq = rotVert._x * rotVert._x; float ySq = rotVert._y * rotVert._y; float zSq = rotVert._z * rotVert._z; float oneMincos = (1-cos(radians)); Matrix4x4 matRotate; matRotate.Identity(); matRotate._11 = xSq * oneMincos + cos(radians); matRotate._12 = xy * oneMincos + rotVert._z * sin(radians); matRotate._13 = xz * oneMincos - rotVert._y * sin(radians); matRotate._21 = xy * oneMincos - rotVert._z * sin(radians); matRotate._22 = ySq * oneMincos + cos(radians); matRotate._23 = yz * oneMincos + rotVert._x * sin(radians); matRotate._31 = xz * oneMincos + rotVert._y * sin(radians); matRotate._32 = yz * oneMincos - rotVert._x * sin(radians); matRotate._33 = zSq * oneMincos + cos(radians); Transformation(matRotate); }
Transformation Transformation::newRz(double theta){ return Transformation ({{ {cos(theta), sin(theta), 0, 0}, {-sin(theta), cos(theta) , 0, 0}, {0 , 0 , 1, 0}, {0 , 0 , 0, 1}}}); }
Transformation Transformation::newScaling(double sx, double sy, double sz){ return Transformation ({{ {sx, 0 , 0 , 0}, {0 , sy, 0 , 0}, {0 , 0 , sz, 0}, {0 , 0 , 0 , 1}}}); }
Transformation Transformation::newTranslation(double dx, double dy) { Matrix m = {{ {1, 0, 0}, {0, 1, 0}, {dx, dy, 1} } }; return Transformation(m); }
Transformation Transformation::newScaling(double sx, double sy) { Matrix m = {{ {sx, 0, 0}, {0, sy, 0}, {0, 0, 1} } }; return Transformation(m); }
void Matrix4x4::Scale(float kx, float ky, float kz) { Matrix4x4 scaleMat(kx, 0.0f, 0.0f, 0.0f, ky, 0.0f, 0.0f, 0.0f, kz); Transformation(scaleMat); }
Transformation Transformation::transpose(){ TransformationMatrix mat; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) mat[i][j] = _m[j][i]; return Transformation(std::move(mat)); }
void Window::updateMatrix() { _wo2wiMatrix = Transformation(); _wo2wiMatrix *= Transformation::newTranslation(-_center.x + _d, -_center.y + _d, -_center.z + _d); _wo2wiMatrix *= Transformation::newRx(_thetaX); _wo2wiMatrix *= Transformation::newRy(_thetaY); _wo2wiMatrix *= Transformation::newRz(_thetaZ); _wo2wiMatrix *= Transformation::newScaling(1.0/_width, 1.0/_height, 2.0/(_width + _height)); }
Transformation Transformation::newRotation(double graus){ // Por algum motivo desconhecido, a rotação esta invertida double rad = -toRadians(graus); Matrix m = {{ {cos(rad), -sin(rad), 0}, {sin(rad), cos(rad), 0}, { 0, 0, 1} }}; return Transformation(m); }
Transformation Transformation::newRotation(double graus) { double rad = toRadians(graus); Matrix m = {{ { cos(rad), sin(rad), 0}, {-sin(rad), cos(rad), 0}, { 0, 0, 1} } }; return Transformation(m); }
void Matrix4x4::XAxisRotation(float degrees) { float radians = degrees * (float(PI)/180); Matrix4x4 matRotate(1.0f, 0.0f, 0.0f, 0.0f, cos(radians), sin(radians), 0.0f, -sin(radians),cos(radians)); Transformation(matRotate); }
/// returns a transformation which is the inverse of this Transformation Transformation::inverse() const { Matrix matrix(4,4); bool test = invert(m_storage, matrix); if (!test){ // this should never happen LOG_AND_THROW("Matrix inversion failed"); } return Transformation(matrix); }
/// translation along vector Transformation Transformation::translation(const Vector3d& translation) { Matrix storage = identity_matrix<double>(4); storage(0,3) = translation.x(); storage(1,3) = translation.y(); storage(2,3) = translation.z(); return Transformation(storage); }
Player::Player(float x, float y, Vec3D scale){ Player(); m_Active = true; m_Transformation = Transformation(Vec3D(x,y,0),scale); m_CollisionEnabled = true; m_Speed = 0.2; m_MaxVel = 3.6; m_Velocity = 0; m_LaserCooldown = 30; m_LaserStatus = 0; m_Lives = 3; }
void Matrix4x4::YAxisRotation(float degrees) { float radians = degrees * (float(PI)/180); Matrix4x4 matRotate; matRotate.Identity(); matRotate.SetMatrix(cos(radians), 0.0f, -sin(radians), 0.0f, 1.0f, 0.0f, sin(radians), 0, cos(radians)); Transformation(matRotate); }
void TerrainPage::update_bounding_box() { BoundingBox bounding_box; glm::vec3 min, max; get_mesh()->get_bounding_box(Transformation(), bounding_box); min = bounding_box.get_min(); max = bounding_box.get_max(); min.z = get_min_z(); max.z = get_max_z(); bounding_box.set_min_max(min, max); set_bounding_box(bounding_box.transform( get_world_transformation())); }
/// transforms system with z' to regular system /// will try to align y' with z, but if that fails will align y' with y Transformation Transformation::alignZPrime(const Vector3d& zPrime) { Vector3d xp; Vector3d yp; Vector3d zp = zPrime; if (!zp.normalize()){ LOG(Error, "Could not normalize zPrime"); } Vector3d xAxis(1,0,0); Vector3d yAxis(0,1,0); Vector3d zAxis(0,0,1); Vector3d negXAxis(-1,0,0); // check if face normal is up or down if (fabs(zp.dot(zAxis)) < 0.99){ // not facing up or down, set yPrime along zAxis yp = zAxis - (zp.dot(zAxis)*zp); if (!yp.normalize()){ LOG(Error, "Could not normalize axis"); } xp = yp.cross(zp); }else{ // facing up or down, set xPrime along -xAxis xp = negXAxis - (zp.dot(negXAxis)*zp); if (!xp.normalize()){ LOG(Error, "Could not normalize axis"); } yp = zp.cross(xp); } Matrix storage = identity_matrix<double>(4); storage(0,0) = xp.x(); storage(1,0) = xp.y(); storage(2,0) = xp.z(); storage(0,1) = yp.x(); storage(1,1) = yp.y(); storage(2,1) = yp.z(); storage(0,2) = zp.x(); storage(1,2) = zp.y(); storage(2,2) = zp.z(); return Transformation(storage); }
boolean PSStencil::Definition (ostream& out) { StencilComp* comp = (StencilComp*) GetSubject(); Bitmap* image, *mask; comp->GetStencil()->GetOriginal(image, mask); const char* tag = (image == mask) ? "SSten" : "FSten"; Coord w = image->Width(); Coord h = image->Height(); out << "Begin " << MARK << " " << tag << "\n"; FgColor(out); BgColor(out); Transformation(out); out << MARK << "\n"; out << w << " " << h << " " << tag << " "; out << "{ currentfile "<< (w + 7) / 8 << " string readhexstring pop }\n"; out << "imagemask"; unidraw->GetCatalog()->WriteBitmapData(image, out); out << "\nEnd\n\n"; return out.good(); }