衝突検出のために画像を回転させるjs関数を作成しましたが、回転がπ* 1.5(Pi)を超えると関数が正しく機能しません。画像がトリミングされます。
function rotateImage(image , rotation)
{
// Creates a canvas
var rotatedImage = document.createElement( "canvas" ) . getContext( "2d" ),
// Setting a bounding box size
boundingWidth = Math . abs( image . height * Math . cos( rotation ) + image . width * Math . sin( rotation ) ),
boundingHeight = Math . abs( image . height * Math . sin( rotation ) + image . width * Math . cos( rotation ) );
// Changing canvas size
rotatedImage . canvas.width = boundingWidth;
rotatedImage . canvas.height = boundingHeight;
// Translating canvas
rotatedImage . translate( boundingWidth/2 , boundingHeight/2 );
// Rotate canvas
rotatedImage . rotate( rotation );
// Un-translating canvas
rotatedImage . translate( -boundingWidth/2 , -boundingHeight/2 );
// Draws image
rotatedImage . drawImage( image , 0 , 0 );
// Returns canvas
return rotatedImage . canvas;
}
ありがとう :)