0

이미지의 일부분을 회전 된 다른 것으로 대체하려고합니다. 이미지 소스는 origin_source가 image * this의 orign_dest에서 끝나는 방식으로 나타나야합니다. 픽셀을 교체하기 전에 원본을 origin_source 주위로 회전해야합니다.회전 된 이미지를 캔버스에 그립니다.

아래 코드는 R이 미러 매트릭스 일 때 작동하지만 실제로 회전 매트릭스를 만들면 결과 이미지가 전단됩니다. 뭐가 잘못 되었 니? 정규화 벡터를 또한

inline Matrix22<double> transformRotationCreate(const Vector2d<double>& direction) 
{ 
return (Matrix22<double>){direction.x, -direction.y, direction.y, direction.x}; 
} 

Vector2d<T>& operator*=(const Matrix22<T>& M) 
    { 
    x=x*M.xx + y*M.xy; 
    y=x*M.yx + y*M.yy; 
    return *this; 
    } 
이다

template<class T> 
struct Matrix22 
{ 
T xx; 
T xy; 
T yx; 
T yy; 
}; 

방향 이중

T = 여기

void Image::imageApply(const Image& source,const Point& origin_dest,const Point& origin_source,const Point& direction) 
{ 
Matrix22<double> R=transformRotationCreate(direction); 
Point source_new_size=sqrt(2)*((Point){source.widthGet(),source.heightGet()}); 
Point blit_start=origin_dest; 
for(unsigned int k=0;k<source_new_size.y;k++) 
    { 
    for(unsigned int l=0;l<source_new_size.x;l++) 
     { 
     Point point_source=(Point){l,k}; 
     Point point_dest=point_source-origin_source; 
     point_dest*=R; 
     point_dest+=blit_start; 

     if(point_source.rectangleInIs((Point){0,0},(Point){source.widthGet(),source.heightGet()}) 
      &&point_dest.rectangleInIs((Point){0,0},(Point){widthGet(),heightGet()})) 
      { 
      (*this)(point_dest)=source(point_source); 
      } 
     } 
    } 
} 

사용할 다른 함수들이다
+0

'transformRotationCreate()'의 코드를 게시 할 수 있습니까? – user1118321

답변

0

내가 모든

먼저 그것을 해결, 행렬 - 벡터 곱셈 연산자는 잘못 :

Vector2d<T>& operator*=(const Matrix22<T>& M) 
    { 
    T x_old=x; //Need to save old x value (Stupid error but anyone does so sometimes) 
    x=x*M.xx + y*M.xy; 
    y=x_old*M.yx + y*M.yy; 
    return *this; 
    } 

마지막과 같은 일상적인 모습 "을 붙여 회전 - 및 -"

void Image::imageApply(const Image& source,const Point& origin_dest,const Point& origin_source,const Point& direction) 
{ 
Matrix22<double> R=transformRotationCreate(direction); 
Point blit_start=origin_dest-(Point){source.sizeMaxGet(),source.sizeMaxGet()}; 
Point blit_end=origin_dest+(Point){source.sizeMaxGet(),source.sizeMaxGet()}; 

for(unsigned int k=blit_start.y;k<blit_end.y;k++) 
    { 
    for(unsigned int l=blit_start.x;l<blit_end.x;l++) 
     { 
     Point point_dest=(Point){l,k}; 
     Point point_source=R*(point_dest - origin_dest) + origin_source; 
     if(point_source.rectangleInIs((Point){0,0},(Point){source.widthGet(),source.heightGet()})) 
      { 
      float alpha_source=source(point_source).alpha; 
      (*this)(point_dest)=(1.0f-alpha_source)*(*this)(point_dest) 
           + alpha_source*source(point_source); 
      } 
     } 
    } 
} 

마지막으로, 회전 방향이 틀렸지 만 이는 변환에서 xy 요소를 교환 한 것입니다.

관련 문제