通さん、IWさん、Suraレスありがとうございます
環境は
BCC Developer Ver1.2.21
DXライブラリ Ver2.25です。
通さんが言われているC89、C9Xなどは確認の仕方がわかりません。borlandのbcc55の事でしたら最近インストールしました。
またVisual C++ 2005で同じものを実行してみたところエラーダイアログはでてきませんでした。
BCC Developerでもこのエラーを出さない方法があれば教えてください。
acosを使わない方法もやってみるつもりです。
以下ソースです。
//四角と丸の当たり判定 丸の中心が四角に入っていたら自機の下に「HIT」と表示する
#include<math.h>
#include"DxLib.h"
#define PI 3.1415936
#define RAD 57.29578
float timer;
int cr;
int i ;
float plx=320,ply=240,plsize=30;
float angle = 0;//四角の角度
float si_x=150,si_y=300;//四角の座標
int ss_x,ss_y;//四角のサイズ
float px[5],py[5];//四角の四点の座標 初期状態の[0]左上 [1]右上 [2]右下 [3]左下
//A=初期状態の左上 B=右上 C=左下 D=左下
//Z=自機
double AZx,AZy,AZz,BAx,BAy,BZx,//AZxはA点からZ点までの横の距離
BZy,BZz,BAz,CZx,CZy,CZz,//AZyは縦の距離
CDx,CDy,CDz,DZx,DZy,DZz,//AZzは三平方の定理で長さを求める
ADx,ADy,ADz,CBx,CBy,CBz;//
double baz,dcz,adz,cbz;//それぞれの角度
int number_2(){
AZx = fabs( plx - px[0]);
AZy = fabs( ply - py[0]);
AZz = sqrt( AZx*AZx + AZy*AZy);
BAx = fabs( px[0] - px[1]);
BAy = fabs( py[0] - py[1]);
BAz = sqrt( BAx*BAx + BAy*BAy);
BZx = fabs( plx - px[1]);
BZy = fabs( ply - py[1]);
BZz = sqrt( BZx*BZx + BZy*BZy);
CZx = fabs( plx - px[2]);
CZy = fabs( ply - py[2]);
CZz = sqrt( CZx*CZx + CZy*CZy);
CDx = fabs( px[2] - px[3]);
CDy = fabs( py[2] - py[3]);
CDz = sqrt( CDx*CDx + CDy*CDy);
DZx = fabs( plx - px[3]);
DZy = fabs( ply - py[3]);
DZz = sqrt( DZx*DZx + DZy*DZy);
ADx = fabs( px[0] - px[3]);
ADy = fabs( py[0] - py[3]);
ADz = sqrt( ADx*ADx + ADy*ADy);
CBx = fabs( px[1] - px[2]);
CBy = fabs( py[1] - py[2]);
CBz = sqrt( CBx*CBx + CBy*CBy);
baz = acos( (AZz*AZz + BAz*BAz - BZz*BZz)/(2*AZz*BAz) ) * RAD;//三角形abcがありそれぞれの長さがわかれば
dcz = acos( (CZz*CZz + CDz*CDz - DZz*DZz)/(2*CZz*CDz) ) * RAD;//角度が出すことが出来る公式
adz = acos( (ADz*ADz + DZz*DZz - AZz*AZz)/(2*ADz*DZz) ) * RAD;//(b^2+c^2-a^2)/(2bc)
cbz = acos( (CBz*CBz + BZz*BZz - CZz*CZz)/(2*CBz*BZz) ) * RAD;//これによりaに対する角度?がでる
if(baz <= 90 && dcz <= 90 && adz <= 90 && cbz <= 90)//円の中心が四角の中に入っている
return 1;
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow ){
SetGraphMode( 640 , 480 , 16 );
ChangeWindowMode( TRUE );
if( DxLib_Init() == -1 ) return -1;
SetDrawScreen( DX_SCREEN_BACK );
char Buf[ 256 ] ;
int sikakuimg = LoadGraph( "sikaku.bmp" ) ;
//この画像は横140縦209の長方形です
GetGraphSize( sikakuimg , &ss_x , &ss_y ) ;
while(1){
ClearDrawScreen();
timer = GetNowCount();
GetHitKeyStateAll( Buf ) ;
cr = GetColor( 255 , 255 , 255 ) ;
if(angle>=360)angle-=360;
DrawRotaGraph( si_x , si_y , 1.0f , angle/RAD , sikakuimg , TRUE ) ;
DrawCircle( plx,ply,plsize , cr ) ;
cr = GetColor( 255 , 255 , 255 ) ;
DrawFormatString( 320, 0 , cr, "angle = %lf°", angle );
float x,y,z;
x = ss_x/2;
y = ss_y/2;
z = sqrt(x*x+y*y);
float O = atan(y / x)*RAD;
DrawFormatString( 320, 20 , cr, "O = %lf°", O );
cr = GetColor( 255 , 255 , 255 ) ;
px[0] = (si_x ) - z*cos(O/RAD + angle/RAD) ;
py[0] = (si_y ) - z*sin(O/RAD + angle/RAD) ;
px[1] = (si_x ) + z*cos(O/RAD - angle/RAD) ;
py[1] = (si_y ) - z*sin(O/RAD - angle/RAD) ;
px[2] = (si_x ) + z*cos(O/RAD + angle/RAD) ;
py[2] = (si_y ) + z*sin(O/RAD + angle/RAD) ;
px[3] = (si_x ) - z*cos(O/RAD - angle/RAD) ;
py[3] = (si_y ) + z*sin(O/RAD - angle/RAD) ;
cr = GetColor( 255 , 0 , 0 ) ;
DrawLine(plx,ply, px[0],py[0],cr);
DrawLine(px[1],py[1],px[0],py[0],cr);
DrawLine(plx,ply,px[2],py[2],cr);
DrawLine(px[3],py[3],px[2],py[2],cr);
cr = GetColor( 0 , 255 , 0 ) ;
DrawLine(plx,ply, px[1],py[1],cr);
DrawLine(px[2],py[2],px[1],py[1],cr);
DrawLine(plx,ply,px[3],py[3],cr);
DrawLine(px[3],py[3],px[0],py[0],cr);
DrawFormatString( 320, 50 , cr, "baz = %lf", baz );
DrawFormatString( 320, 70 , cr, "dcz = %lf", dcz );
DrawFormatString( 320, 90 , cr, "adz = %lf", adz );
DrawFormatString( 320, 110 , cr, "cbz = %lf", cbz );
DrawFormatString( 320, 210 , cr, "dx = %3.lf", px[3] );
DrawFormatString( 320, 230 , cr, "dy = %3.lf", py[3] );
DrawFormatString( 320, 250 , cr, "cx = %3.lf", px[2] );
DrawFormatString( 320, 270 , cr, "cy = %3.lf", py[2] );
DrawFormatString( 320, 290 , cr, "zx = %3.lf", plx );
DrawFormatString( 320, 310 , cr, "zy = %3.lf", ply );
DrawFormatString( 200, 350 , cr, "acos((CZz*CZz + CDz*CDz - DZz*DZz)/(2*CZz*CDz))" );
DrawFormatString( 200, 370 , cr, "acos((%7.lf + %7.lf - %7.lf)/(%9.lf))",CZz*CZz,CDz*CDz,DZz*DZz,2*CZz*CDz );
DrawFormatString( 200, 390 , cr, "acos((%27.lf)/(%9.lf))",CZz*CZz+CDz*CDz-DZz*DZz,2*CZz*CDz );
DrawFormatString( 200, 410 , cr, "acos(%lf)",(CZz*CZz+CDz*CDz-DZz*DZz)/(2*CZz*CDz) );
//私がエラーを確認したのはangle = 180°で自機がCD線上にいるときにエラーがでます。
//なのでこの式はdczの中身を書いています。
//dcz = acos( (CZz*CZz + CDz*CDz - DZz*DZz)/(2*CZz*CDz) ) * RAD;
if(number_2() == 1){
DrawString( plx , ply + plsize , "HIT中!!" , cr );
}
if( Buf[ KEY_INPUT_Z ] == 1 )
angle-=1;
if( Buf[ KEY_INPUT_X ] == 1 )
angle+=1;
if( Buf[ KEY_INPUT_RIGHT ] == 1 )
plx += 4;
if( Buf[ KEY_INPUT_LEFT ] == 1 )
plx -= 4;
if( Buf[ KEY_INPUT_UP ] == 1 )
ply -= 4;
if( Buf[ KEY_INPUT_DOWN ] == 1 )
ply += 4;
ScreenFlip();
while( GetNowCount() - timer < 17 ){}
if( ProcessMessage() == -1 ) break;
if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 ) break;
}
DxLib_End();
return 0;
}